Skip to content

Commit

Permalink
fix: subject template group
Browse files Browse the repository at this point in the history
  • Loading branch information
zhu327 committed Nov 9, 2023
1 parent aa3eb6f commit f2cf9db
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 16 deletions.
4 changes: 2 additions & 2 deletions pkg/database/dao/mock/subject_template_group.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 8 additions & 8 deletions pkg/database/dao/subject_template_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ type SubjectTemplateGroupManager interface {
) (members []SubjectTemplateGroup, err error)
ListRelationBySubjectPKGroupPKs(subjectPK int64, groupPKs []int64) ([]SubjectTemplateGroup, error)
ListGroupDistinctSubjectPK(groupPK int64) (subjectPKs []int64, err error)
ListMaxExpiredAtRelation(groupPK int64) ([]SubjectTemplateGroup, error)
ListMaxExpiredAtRelation(groupPK int64) ([]ThinSubjectRelation, error)

BulkCreateWithTx(tx *sqlx.Tx, relations []SubjectTemplateGroup) error
BulkUpdateExpiredAtWithTx(tx *sqlx.Tx, relations []SubjectTemplateGroup) error
Expand Down Expand Up @@ -203,15 +203,11 @@ func (m *subjectTemplateGroupManager) ListGroupDistinctSubjectPK(groupPK int64)
return
}

func (m *subjectTemplateGroupManager) ListMaxExpiredAtRelation(groupPK int64) ([]SubjectTemplateGroup, error) {
relations := []SubjectTemplateGroup{}
func (m *subjectTemplateGroupManager) ListMaxExpiredAtRelation(groupPK int64) ([]ThinSubjectRelation, error) {
relations := []ThinSubjectRelation{}
query := `SELECT
pk,
subject_pk,
template_id,
group_pk,
MAX(expired_at) AS expired_at,
created_at
MAX(expired_at) AS policy_expired_at
FROM subject_template_group
WHERE group_pk = ?
GROUP BY subject_pk`
Expand All @@ -221,5 +217,9 @@ func (m *subjectTemplateGroupManager) ListMaxExpiredAtRelation(groupPK int64) ([
return relations, nil
}

for i := range relations {
relations[i].GroupPK = groupPK
}

return relations, err
}
7 changes: 3 additions & 4 deletions pkg/database/dao/subject_template_group_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,13 +194,12 @@ func Test_subjectTemplateGroupManager_BulkUpdateExpiredAtWithTx(t *testing.T) {
func Test_subjectTemplateGroupManager_ListMaxExpiredAtRelation(t *testing.T) {
database.RunWithMock(t, func(db *sqlx.DB, mock sqlmock.Sqlmock, t *testing.T) {
mockQuery := `^SELECT
pk, subject_pk, template_id, group_pk,
(.*), created_at
subject_pk, (.*)
FROM subject_template_group
WHERE group_pk = (.*) GROUP BY subject_pk`
mockRows := sqlmock.NewRows(
[]string{"pk", "subject_pk", "template_id", "group_pk", "expired_at"},
).AddRow(int64(1), int64(2), int64(3), int64(4), int64(0))
[]string{"subject_pk", "policy_expired_at"},
).AddRow(int64(1), int64(2))
mock.ExpectQuery(mockQuery).WithArgs(int64(1)).WillReturnRows(mockRows)

manager := &subjectTemplateGroupManager{DB: db}
Expand Down
2 changes: 0 additions & 2 deletions pkg/service/group_system_auth_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,11 +120,9 @@ func (s *groupService) AlterGroupAuthType(
}

memberMap[r.SubjectPK] = dao.SubjectRelation{
PK: r.PK,
SubjectPK: r.SubjectPK,
GroupPK: r.GroupPK,
ExpiredAt: r.ExpiredAt,
CreatedAt: r.CreatedAt,
}
}

Expand Down

0 comments on commit f2cf9db

Please sign in to comment.