From 952efb864fef1b00635ba94df90b30ad05e04ee9 Mon Sep 17 00:00:00 2001 From: zhu327 Date: Wed, 25 Oct 2023 09:54:54 +0800 Subject: [PATCH] feat: add subject template group api --- pkg/abac/pap/group.go | 91 ++++++++++---------------- pkg/abac/pap/group_test.go | 18 ++--- pkg/database/dao/mock/subject_group.go | 14 ---- pkg/database/dao/subject_group.go | 17 ----- pkg/database/dao/subject_group_test.go | 26 -------- pkg/service/group.go | 39 ++++++----- pkg/service/group_test.go | 12 ++-- pkg/service/mock/group.go | 6 +- pkg/service/types/subject.go | 14 ---- 9 files changed, 73 insertions(+), 164 deletions(-) diff --git a/pkg/abac/pap/group.go b/pkg/abac/pap/group.go index a24c6dfe..fa2b0b30 100644 --- a/pkg/abac/pap/group.go +++ b/pkg/abac/pap/group.go @@ -483,7 +483,9 @@ func (c *groupController) BulkCreateSubjectTemplateGroup(subjectTemplateGroups [ subjectGroupHelper := newSubjectGroupHelper(c.service) - for i, relation := range relations { + for i := range relations { + relation := &relations[i] + authorized, subjectGroup, err := subjectGroupHelper.getSubjectGroup(relation.SubjectPK, relation.GroupPK) if err != nil { return errorWrapf( @@ -501,12 +503,12 @@ func (c *groupController) BulkCreateSubjectTemplateGroup(subjectTemplateGroups [ // 2. 如果已授权并且过期时间大于当前时间, 不需要更新 if subjectGroup != nil && subjectGroup.ExpiredAt > relation.ExpiredAt { - relations[i].ExpiredAt = subjectGroup.ExpiredAt + relation.ExpiredAt = subjectGroup.ExpiredAt continue } // 3. 其余场景需要更新 - relations[i].NeedUpdate = true + relation.NeedUpdate = true } tx, err := database.GenerateDefaultDBTx() @@ -581,14 +583,16 @@ func (c *groupController) BulkDeleteSubjectTemplateGroup(subjectTemplateGroups [ } // 查询是否有其它的关系 - for i, relation := range relations { - exist, err := c.service.HasRelationExceptTemplate(relation) + for i := range relations { + relation := &relations[i] + + exist, err := c.service.HasRelationExceptTemplate(*relation) if err != nil { return errorWrapf(err, "service.HasRelationExceptTemplate relation=`%+v` fail", relation) } if !exist { - relations[i].NeedUpdate = true + relation.NeedUpdate = true } } @@ -693,73 +697,58 @@ func (c *groupController) alterGroupMembers( } // 获取实际需要添加的member - createMembers := make([]types.SubjectRelationForCreate, 0, len(members)) + createMembers := make([]types.SubjectTemplateGroup, 0, len(members)) // 需要更新过期时间的member - updateMembers := make([]types.SubjectRelationForUpdate, 0, len(members)) - - // 用于清理缓存 - subjectPKs := make([]int64, 0, len(members)) + updateMembers := make([]types.SubjectTemplateGroup, 0, len(members)) typeCount = map[string]int64{ types.UserType: 0, types.DepartmentType: 0, } - subjectGroupHelper := newSubjectGroupHelper(c.service) subjectTemplateGroups, err := c.convertGroupMembersToSubjectTemplateGroups(groupPK, members) if err != nil { return nil, err } - for i, m := range members { - subjectPK := subjectTemplateGroups[i].SubjectPK - authorized, subjectGroup, err := subjectGroupHelper.getSubjectGroup(subjectPK, groupPK) + subjectGroupHelper := newSubjectGroupHelper(c.service) + for i := range subjectTemplateGroups { + relation := &subjectTemplateGroups[i] + + // 查询 subject group 已有的关系 + authorized, subjectGroup, err := subjectGroupHelper.getSubjectGroup(relation.SubjectPK, groupPK) if err != nil { return nil, errorWrapf( err, "getSubjectGroup subjectPK=`%d`, groupPK=`%d` fail", - subjectPK, + relation.SubjectPK, groupPK, ) } - if authorized && subjectGroup != nil && subjectGroup.ExpiredAt > m.ExpiredAt { - m.ExpiredAt = subjectGroup.ExpiredAt - subjectTemplateGroups[i].ExpiredAt = subjectGroup.ExpiredAt + if authorized && subjectGroup != nil && subjectGroup.ExpiredAt > relation.ExpiredAt { + relation.ExpiredAt = subjectGroup.ExpiredAt } // member已存在则不再添加 - if oldMember, ok := memberMap[subjectPK]; ok { + if oldMember, ok := memberMap[relation.SubjectPK]; ok { // 如果过期时间大于已有的时间, 则更新过期时间 - if m.ExpiredAt > oldMember.ExpiredAt { - updateMembers = append(updateMembers, types.SubjectRelationForUpdate{ - PK: oldMember.PK, - SubjectPK: subjectPK, - ExpiredAt: m.ExpiredAt, - }) - - subjectPKs = append(subjectPKs, subjectPK) - } + if relation.ExpiredAt > oldMember.ExpiredAt { + relation.NeedUpdate = true - if authorized && (subjectGroup == nil || subjectGroup.ExpiredAt < m.ExpiredAt) { - subjectTemplateGroups[i].NeedUpdate = true + updateMembers = append(updateMembers, *relation) } continue } if createIfNotExists { - createMembers = append(createMembers, types.SubjectRelationForCreate{ - SubjectPK: subjectPK, - GroupPK: groupPK, - ExpiredAt: m.ExpiredAt, - }) - typeCount[m.Type]++ - subjectPKs = append(subjectPKs, subjectPK) - - if authorized && (subjectGroup == nil || subjectGroup.ExpiredAt < m.ExpiredAt) { - subjectTemplateGroups[i].NeedUpdate = true + if authorized && (subjectGroup == nil || subjectGroup.ExpiredAt < relation.ExpiredAt) { + relation.NeedUpdate = true } + + createMembers = append(createMembers, *relation) + typeCount[members[i].Type]++ } } @@ -803,18 +792,8 @@ func (c *groupController) alterGroupMembers( return nil, errorWrapf(err, "tx commit error") } - needUpdateSubjectPKs := make([]int64, 0, len(subjectPKs)) - for _, group := range subjectTemplateGroups { - if group.NeedUpdate { - needUpdateSubjectPKs = append(needUpdateSubjectPKs, group.SubjectPK) - } - } - - // 创建group_alter_event - c.createGroupAlterEvent(groupPK, needUpdateSubjectPKs) - // 清理subject system group 缓存 - cacheimpls.BatchDeleteSubjectAuthSystemGroupCache(needUpdateSubjectPKs, groupPK) + c.deleteSubjectTemplateGroupCache(subjectTemplateGroups) return typeCount, nil } @@ -824,14 +803,10 @@ func (c *groupController) updateSubjectGroupExpiredAtWithTx( subjectTemplateGroups []types.SubjectTemplateGroup, updateGroupRelation bool, ) error { - needUpdateRelations := make([]types.SubjectRelationForCreate, 0, len(subjectTemplateGroups)) + needUpdateRelations := make([]types.SubjectTemplateGroup, 0, len(subjectTemplateGroups)) for _, relation := range subjectTemplateGroups { if relation.NeedUpdate { - needUpdateRelations = append(needUpdateRelations, types.SubjectRelationForCreate{ - SubjectPK: relation.SubjectPK, - GroupPK: relation.GroupPK, - ExpiredAt: relation.ExpiredAt, - }) + needUpdateRelations = append(needUpdateRelations, relation) } } diff --git a/pkg/abac/pap/group_test.go b/pkg/abac/pap/group_test.go index 12330bcc..76d25418 100644 --- a/pkg/abac/pap/group_test.go +++ b/pkg/abac/pap/group_test.go @@ -88,7 +88,7 @@ var _ = Describe("GroupController", func() { mockGroupService.EXPECT(). UpdateGroupMembersExpiredAtWithTx( gomock.Any(), int64(1), - []types.SubjectRelationForUpdate{{PK: 1, SubjectPK: 2, ExpiredAt: 3}}, + []types.SubjectTemplateGroup{{SubjectPK: 2, GroupPK: 1, ExpiredAt: 3, NeedUpdate: true}}, ). Return( errors.New("error"), @@ -126,13 +126,13 @@ var _ = Describe("GroupController", func() { []types.GroupMember{}, nil, ).AnyTimes() mockGroupService.EXPECT(). - UpdateGroupMembersExpiredAtWithTx(gomock.Any(), int64(1), []types.SubjectRelationForUpdate{{PK: 1, SubjectPK: 2, ExpiredAt: 3}}). + UpdateGroupMembersExpiredAtWithTx(gomock.Any(), int64(1), []types.SubjectTemplateGroup{{SubjectPK: 2, GroupPK: 1, ExpiredAt: 3}}). Return( nil, ). AnyTimes() mockGroupService.EXPECT(). - BulkCreateGroupMembersWithTx(gomock.Any(), int64(1), []types.SubjectRelationForCreate{{ + BulkCreateGroupMembersWithTx(gomock.Any(), int64(1), []types.SubjectTemplateGroup{{ SubjectPK: 2, GroupPK: 1, ExpiredAt: int64(3), @@ -175,16 +175,13 @@ var _ = Describe("GroupController", func() { mockGroupService.EXPECT(). UpdateGroupMembersExpiredAtWithTx( gomock.Any(), int64(1), - []types.SubjectRelationForUpdate{{PK: 1, SubjectPK: 2, ExpiredAt: 3}}, + []types.SubjectTemplateGroup{{SubjectPK: 2, GroupPK: 1, ExpiredAt: 3}}, ).Return( nil, ). AnyTimes() mockGroupService.EXPECT().ListGroupAuthSystemIDs(int64(1)).Return([]string{}, nil).AnyTimes() mockGroupAlterEventService := mock.NewMockGroupAlterEventService(ctl) - mockGroupAlterEventService.EXPECT(). - CreateByGroupSubject(gomock.Any(), gomock.Any()). - Return(errors.New("error")) mockGroupService.EXPECT().GetGroupOneAuthSystem(int64(1)).Return("", nil).AnyTimes() patches.ApplyFunc(service.NewGroupService, func() service.GroupService { @@ -223,14 +220,14 @@ var _ = Describe("GroupController", func() { mockGroupService.EXPECT(). UpdateGroupMembersExpiredAtWithTx( gomock.Any(), int64(1), - []types.SubjectRelationForUpdate{{PK: 1, SubjectPK: 2, ExpiredAt: 3}}, + []types.SubjectTemplateGroup{{SubjectPK: 2, GroupPK: 1, ExpiredAt: 3}}, ). Return( nil, ). AnyTimes() mockGroupService.EXPECT(). - BulkCreateGroupMembersWithTx(gomock.Any(), int64(1), []types.SubjectRelationForCreate{{ + BulkCreateGroupMembersWithTx(gomock.Any(), int64(1), []types.SubjectTemplateGroup{{ SubjectPK: 2, GroupPK: 1, ExpiredAt: int64(3), @@ -241,9 +238,6 @@ var _ = Describe("GroupController", func() { AnyTimes() mockGroupService.EXPECT().ListGroupAuthSystemIDs(int64(1)).Return([]string{}, nil).AnyTimes() mockGroupAlterEventService := mock.NewMockGroupAlterEventService(ctl) - mockGroupAlterEventService.EXPECT(). - CreateByGroupSubject(gomock.Any(), gomock.Any()). - Return(errors.New("error")) mockGroupService.EXPECT().GetGroupOneAuthSystem(int64(1)).Return("", nil).AnyTimes() patches.ApplyFunc(service.NewGroupService, func() service.GroupService { diff --git a/pkg/database/dao/mock/subject_group.go b/pkg/database/dao/mock/subject_group.go index 4d4dc8c5..c29ebbc0 100644 --- a/pkg/database/dao/mock/subject_group.go +++ b/pkg/database/dao/mock/subject_group.go @@ -405,17 +405,3 @@ func (mr *MockSubjectGroupManagerMockRecorder) ListThinRelationAfterExpiredAtByS mr.mock.ctrl.T.Helper() return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ListThinRelationAfterExpiredAtBySubjectPKs", reflect.TypeOf((*MockSubjectGroupManager)(nil).ListThinRelationAfterExpiredAtBySubjectPKs), subjectPKs, expiredAt) } - -// UpdateExpiredAtWithTx mocks base method. -func (m *MockSubjectGroupManager) UpdateExpiredAtWithTx(tx *sqlx.Tx, relations []dao.SubjectRelationForUpdateExpiredAt) error { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "UpdateExpiredAtWithTx", tx, relations) - ret0, _ := ret[0].(error) - return ret0 -} - -// UpdateExpiredAtWithTx indicates an expected call of UpdateExpiredAtWithTx. -func (mr *MockSubjectGroupManagerMockRecorder) UpdateExpiredAtWithTx(tx, relations interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UpdateExpiredAtWithTx", reflect.TypeOf((*MockSubjectGroupManager)(nil).UpdateExpiredAtWithTx), tx, relations) -} diff --git a/pkg/database/dao/subject_group.go b/pkg/database/dao/subject_group.go index 381f9abc..53ec5091 100644 --- a/pkg/database/dao/subject_group.go +++ b/pkg/database/dao/subject_group.go @@ -34,13 +34,6 @@ type SubjectRelation struct { CreatedAt time.Time `db:"created_at"` } -// SubjectRelationForUpdateExpiredAt keep the PrimaryKey and policy_expired_at -type SubjectRelationForUpdateExpiredAt struct { - PK int64 `db:"pk"` - // NOTE: map policy_expired_at to ExpiredAt in dao - ExpiredAt int64 `db:"policy_expired_at"` -} - // ThinSubjectRelation with the minimum fields of the relationship: subject-group-policy_expired_at type ThinSubjectRelation struct { SubjectPK int64 `db:"subject_pk"` @@ -75,7 +68,6 @@ type SubjectGroupManager interface { FilterGroupPKsHasMemberBeforeExpiredAt(groupPKs []int64, expiredAt int64) ([]int64, error) - UpdateExpiredAtWithTx(tx *sqlx.Tx, relations []SubjectRelationForUpdateExpiredAt) error BulkCreateWithTx(tx *sqlx.Tx, relations []SubjectRelation) error BulkDeleteBySubjectPKs(tx *sqlx.Tx, subjectPKs []int64) error BulkDeleteByGroupPKs(tx *sqlx.Tx, groupPKs []int64) error @@ -395,15 +387,6 @@ func (m *subjectGroupManager) BulkDeleteByGroupPKs(tx *sqlx.Tx, groupPKs []int64 return m.bulkDeleteByGroupPKs(tx, groupPKs) } -// UpdateExpiredAtWithTx ... -func (m *subjectGroupManager) UpdateExpiredAtWithTx( - tx *sqlx.Tx, - relations []SubjectRelationForUpdateExpiredAt, -) error { - sql := `UPDATE subject_relation SET policy_expired_at = :policy_expired_at WHERE pk = :pk` - return database.SqlxBulkUpdateWithTx(tx, sql, relations) -} - // GetGroupMemberCountBeforeExpiredAt ... func (m *subjectGroupManager) GetGroupMemberCountBeforeExpiredAt( groupPK int64, expiredAt int64, diff --git a/pkg/database/dao/subject_group_test.go b/pkg/database/dao/subject_group_test.go index 36fc602b..e4134062 100644 --- a/pkg/database/dao/subject_group_test.go +++ b/pkg/database/dao/subject_group_test.go @@ -160,32 +160,6 @@ func Test_subjectRelationManager_GetMemberCountBeforeExpiredAt(t *testing.T) { }) } -func Test_subjectRelationManager_UpdateExpiredAtWithTx(t *testing.T) { - database.RunWithMock(t, func(db *sqlx.DB, mock sqlmock.Sqlmock, t *testing.T) { - mock.ExpectBegin() - mock.ExpectPrepare(`^UPDATE subject_relation SET policy_expired_at = (.*) WHERE pk = (.*)`) - mock.ExpectExec(`^UPDATE subject_relation SET policy_expired_at =`).WithArgs( - int64(2), int64(1), - ).WillReturnResult(sqlmock.NewResult(1, 1)) - mock.ExpectCommit() - - subjects := []SubjectRelationForUpdateExpiredAt{{ - PK: 1, - ExpiredAt: 2, - }} - - tx, err := db.Beginx() - assert.NoError(t, err) - - manager := &subjectGroupManager{DB: db} - err = manager.UpdateExpiredAtWithTx(tx, subjects) - - tx.Commit() - - assert.NoError(t, err) - }) -} - func Test_subjectRelationManager_BulkCreateWithTx(t *testing.T) { database.RunWithMock(t, func(db *sqlx.DB, mock sqlmock.Sqlmock, t *testing.T) { mock.ExpectBegin() diff --git a/pkg/service/group.go b/pkg/service/group.go index 43563d30..b0633aeb 100644 --- a/pkg/service/group.go +++ b/pkg/service/group.go @@ -60,13 +60,13 @@ type GroupService interface { GetGroupSubjectCountBeforeExpiredAt(expiredAt int64) (count int64, err error) ListPagingGroupSubjectBeforeExpiredAt(expiredAt int64, limit, offset int64) ([]types.GroupSubject, error) - UpdateGroupMembersExpiredAtWithTx(tx *sqlx.Tx, groupPK int64, members []types.SubjectRelationForUpdate) error + UpdateGroupMembersExpiredAtWithTx(tx *sqlx.Tx, groupPK int64, members []types.SubjectTemplateGroup) error BulkDeleteGroupMembers(groupPK int64, userPKs, departmentPKs []int64) (map[string]int64, error) - BulkCreateGroupMembersWithTx(tx *sqlx.Tx, groupPK int64, relations []types.SubjectRelationForCreate) error + BulkCreateGroupMembersWithTx(tx *sqlx.Tx, groupPK int64, relations []types.SubjectTemplateGroup) error BulkCreateSubjectTemplateGroupWithTx(tx *sqlx.Tx, relations []types.SubjectTemplateGroup) error UpdateSubjectGroupExpiredAtWithTx( tx *sqlx.Tx, - relations []types.SubjectRelationForCreate, + relations []types.SubjectTemplateGroup, updateSubjectRelation bool, ) error BulkDeleteSubjectTemplateGroupWithTx(tx *sqlx.Tx, relations []types.SubjectTemplateGroup) error @@ -336,21 +336,22 @@ func (l *groupService) ListGroupMember(groupPK int64) ([]types.GroupMember, erro func (l *groupService) UpdateGroupMembersExpiredAtWithTx( tx *sqlx.Tx, groupPK int64, - members []types.SubjectRelationForUpdate, + members []types.SubjectTemplateGroup, ) error { errorWrapf := errorx.NewLayerFunctionErrorWrapf(GroupSVC, "UpdateGroupMembersExpiredAtWithTx") - relations := make([]dao.SubjectRelationForUpdateExpiredAt, 0, len(members)) + relations := make([]dao.SubjectRelation, 0, len(members)) for _, m := range members { - relations = append(relations, dao.SubjectRelationForUpdateExpiredAt{ - PK: m.PK, + relations = append(relations, dao.SubjectRelation{ + SubjectPK: m.SubjectPK, + GroupPK: groupPK, ExpiredAt: m.ExpiredAt, }) } - err := l.manager.UpdateExpiredAtWithTx(tx, relations) + err := l.manager.BulkUpdateExpiredAtWithTx(tx, relations) if err != nil { - err = errorWrapf(err, "manager.UpdateExpiredAtWithTx relations=`%+v` fail", relations) + err = errorWrapf(err, "manager.BulkUpdateExpiredAtWithTx relations=`%+v` fail", relations) return err } @@ -360,8 +361,12 @@ func (l *groupService) UpdateGroupMembersExpiredAtWithTx( return errorWrapf(err, "listGroupAuthSystem groupPK=`%d` fail", groupPK) } - for _, systemID := range systemIDs { - for _, m := range members { + for _, m := range members { + if !m.NeedUpdate { + continue + } + + for _, systemID := range systemIDs { err = l.addOrUpdateSubjectSystemGroup(tx, m.SubjectPK, systemID, groupPK, m.ExpiredAt) if err != nil { return errorWrapf( @@ -473,7 +478,7 @@ func (l *groupService) BulkDeleteGroupMembers( func (l *groupService) BulkCreateGroupMembersWithTx( tx *sqlx.Tx, groupPK int64, - relations []types.SubjectRelationForCreate, + relations []types.SubjectTemplateGroup, ) error { errorWrapf := errorx.NewLayerFunctionErrorWrapf(GroupSVC, "BulkCreateGroupMembersWithTx") // 组装需要创建的Subject关系 @@ -497,8 +502,12 @@ func (l *groupService) BulkCreateGroupMembersWithTx( return errorWrapf(err, "listGroupAuthSystem groupPK=`%d` fail", groupPK) } - for _, systemID := range systemIDs { - for _, r := range relations { + for _, r := range relations { + if !r.NeedUpdate { + continue + } + + for _, systemID := range systemIDs { err = l.addOrUpdateSubjectSystemGroup(tx, r.SubjectPK, systemID, groupPK, r.ExpiredAt) if err != nil { return errorWrapf( @@ -575,7 +584,7 @@ func (l *groupService) BulkCreateSubjectTemplateGroupWithTx( func (l *groupService) UpdateSubjectGroupExpiredAtWithTx( tx *sqlx.Tx, - relations []types.SubjectRelationForCreate, + relations []types.SubjectTemplateGroup, updateSubjectRelation bool, ) error { errorWrapf := errorx.NewLayerFunctionErrorWrapf(GroupSVC, "UpdateSubjectGroupExpiredAtWithTx") diff --git a/pkg/service/group_test.go b/pkg/service/group_test.go index c6a15b4b..5efb2e3f 100644 --- a/pkg/service/group_test.go +++ b/pkg/service/group_test.go @@ -147,9 +147,10 @@ var _ = Describe("GroupService", func() { It("manager.UpdateExpiredAtWithTx fail", func() { mockSubjectService := mock.NewMockSubjectGroupManager(ctl) - mockSubjectService.EXPECT().UpdateExpiredAtWithTx(gomock.Any(), []dao.SubjectRelationForUpdateExpiredAt{ + mockSubjectService.EXPECT().BulkUpdateExpiredAtWithTx(gomock.Any(), []dao.SubjectRelation{ { - PK: 1, + SubjectPK: 1, + GroupPK: 1, ExpiredAt: 2, }, }).Return( @@ -160,9 +161,10 @@ var _ = Describe("GroupService", func() { manager: mockSubjectService, } - err := manager.UpdateGroupMembersExpiredAtWithTx(nil, int64(1), []types.SubjectRelationForUpdate{ + err := manager.UpdateGroupMembersExpiredAtWithTx(nil, int64(1), []types.SubjectTemplateGroup{ { - PK: 1, + SubjectPK: 1, + GroupPK: 1, ExpiredAt: 2, }, }) @@ -196,7 +198,7 @@ var _ = Describe("GroupService", func() { manager: mockSubjectService, } - err := manager.BulkCreateGroupMembersWithTx(nil, int64(1), []types.SubjectRelationForCreate{ + err := manager.BulkCreateGroupMembersWithTx(nil, int64(1), []types.SubjectTemplateGroup{ { SubjectPK: 1, GroupPK: 2, diff --git a/pkg/service/mock/group.go b/pkg/service/mock/group.go index 82af3f6f..fae2ac24 100644 --- a/pkg/service/mock/group.go +++ b/pkg/service/mock/group.go @@ -51,7 +51,7 @@ func (mr *MockGroupServiceMockRecorder) AlterGroupAuthType(tx, systemID, groupPK } // BulkCreateGroupMembersWithTx mocks base method. -func (m *MockGroupService) BulkCreateGroupMembersWithTx(tx *sqlx.Tx, groupPK int64, relations []types.SubjectRelationForCreate) error { +func (m *MockGroupService) BulkCreateGroupMembersWithTx(tx *sqlx.Tx, groupPK int64, relations []types.SubjectTemplateGroup) error { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "BulkCreateGroupMembersWithTx", tx, groupPK, relations) ret0, _ := ret[0].(error) @@ -436,7 +436,7 @@ func (mr *MockGroupServiceMockRecorder) ListPagingSubjectSystemGroups(subjectPK, } // UpdateGroupMembersExpiredAtWithTx mocks base method. -func (m *MockGroupService) UpdateGroupMembersExpiredAtWithTx(tx *sqlx.Tx, groupPK int64, members []types.SubjectRelationForUpdate) error { +func (m *MockGroupService) UpdateGroupMembersExpiredAtWithTx(tx *sqlx.Tx, groupPK int64, members []types.SubjectTemplateGroup) error { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "UpdateGroupMembersExpiredAtWithTx", tx, groupPK, members) ret0, _ := ret[0].(error) @@ -450,7 +450,7 @@ func (mr *MockGroupServiceMockRecorder) UpdateGroupMembersExpiredAtWithTx(tx, gr } // UpdateSubjectGroupExpiredAtWithTx mocks base method. -func (m *MockGroupService) UpdateSubjectGroupExpiredAtWithTx(tx *sqlx.Tx, relations []types.SubjectRelationForCreate, updateSubjectRelation bool) error { +func (m *MockGroupService) UpdateSubjectGroupExpiredAtWithTx(tx *sqlx.Tx, relations []types.SubjectTemplateGroup, updateSubjectRelation bool) error { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "UpdateSubjectGroupExpiredAtWithTx", tx, relations, updateSubjectRelation) ret0, _ := ret[0].(error) diff --git a/pkg/service/types/subject.go b/pkg/service/types/subject.go index 127c1b3d..f362d235 100644 --- a/pkg/service/types/subject.go +++ b/pkg/service/types/subject.go @@ -62,20 +62,6 @@ type GroupAuthType struct { AuthType int64 `json:"auth_type"` } -// SubjectRelationForUpdate 用于更新 subject-relation -type SubjectRelationForUpdate struct { - PK int64 `json:"pk"` - SubjectPK int64 `json:"subject_pk"` - ExpiredAt int64 `json:"expired_at"` -} - -// SubjectRelationForCreate 用于创建 subject-relation -type SubjectRelationForCreate struct { - SubjectPK int64 `json:"subject_pk"` - GroupPK int64 `json:"group_pk"` - ExpiredAt int64 `json:"expired_at"` -} - type GroupAlterEvent struct { UUID string `json:"uuid"` GroupPK int64 `json:"group_pk"`