Fix missing soft_delete handling

This commit is contained in:
Abin Simon
2022-03-18 12:06:50 +05:30
parent 357f53ff29
commit 7189ae0fbe
3 changed files with 21 additions and 1 deletions

View File

@@ -15,17 +15,20 @@ func GetUsers(ctx context.Context, db bun.IDB, id uuid.UUID) ([]models.KratosIde
err := db.NewSelect().Model(&entities).
Join(`JOIN authsrv_groupaccount ON identities.id=authsrv_groupaccount.account_id`).
Where(`authsrv_groupaccount.group_id = ?`, id).
Where("authsrv_groupaccount.trash = ?", false).
Scan(ctx)
return entities, err
}
func GetGroupRoles(ctx context.Context, db bun.IDB, id uuid.UUID) ([]*userv3.ProjectNamespaceRole, error) {
// Could possibily union them later for some speedup
// Could possibly union them later for some speedup
var r = []*userv3.ProjectNamespaceRole{}
err := db.NewSelect().Table("authsrv_grouprole").
ColumnExpr("authsrv_resourcerole.name as role").
Join(`JOIN authsrv_resourcerole ON authsrv_resourcerole.id=authsrv_grouprole.role_id`).
Where("authsrv_grouprole.group_id = ?", id).
Where("authsrv_resourcerole.trash = ?", false).
Where("authsrv_grouprole.trash = ?", false).
Scan(ctx, &r)
if err != nil {
return nil, err
@@ -37,6 +40,9 @@ func GetGroupRoles(ctx context.Context, db bun.IDB, id uuid.UUID) ([]*userv3.Pro
Join(`JOIN authsrv_resourcerole ON authsrv_resourcerole.id=authsrv_projectgrouprole.role_id`).
Join(`JOIN authsrv_project ON authsrv_project.id=authsrv_projectgrouprole.project_id`).
Where("authsrv_projectgrouprole.group_id = ?", id).
Where("authsrv_project.trash = ?", false).
Where("authsrv_projectgrouprole.trash = ?", false).
Where("authsrv_resourcerole.trash = ?", false).
Scan(ctx, &pr)
if err != nil {
return nil, err
@@ -48,6 +54,9 @@ func GetGroupRoles(ctx context.Context, db bun.IDB, id uuid.UUID) ([]*userv3.Pro
Join(`JOIN authsrv_resourcerole ON authsrv_resourcerole.id=authsrv_projectgroupnamespacerole.role_id`).
Join(`JOIN authsrv_project ON authsrv_project.id=authsrv_projectgroupnamespacerole.project_id`). // also need a namespace join
Where("authsrv_projectgroupnamespacerole.group_id = ?", id).
Where("authsrv_project.trash = ?", false).
Where("authsrv_projectgroupnamespacerole.trash = ?", false).
Where("authsrv_resourcerole.trash = ?", false).
Scan(ctx, &pnr)
if err != nil {
return nil, err

View File

@@ -15,6 +15,8 @@ func GetRolePermissions(ctx context.Context, db bun.IDB, id uuid.UUID) ([]models
ColumnExpr("authsrv_resourcepermission.name as name").
Join(`JOIN authsrv_resourcerolepermission ON authsrv_resourcerolepermission.resource_permission_id=authsrv_resourcepermission.id`).
Where("authsrv_resourcerolepermission.resource_role_id = ?", id).
Where("authsrv_resourcepermission.trash = ?", false).
Where("authsrv_resourcerolepermission.trash = ?", false).
Scan(ctx, &r)
if err != nil {
return nil, err

View File

@@ -14,6 +14,7 @@ func GetGroups(ctx context.Context, db bun.IDB, id uuid.UUID) ([]models.Group, e
err := db.NewSelect().Model(&entities).
Join(`JOIN authsrv_groupaccount ON authsrv_groupaccount.group_id="group".id`).
Where("authsrv_groupaccount.account_id = ?", id).
Where("authsrv_groupaccount.trash = ?", false).
Scan(ctx)
return entities, err
}
@@ -25,6 +26,8 @@ func GetUserRoles(ctx context.Context, db bun.IDB, id uuid.UUID) ([]*userv3.Proj
ColumnExpr("authsrv_resourcerole.name as role").
Join(`JOIN authsrv_resourcerole ON authsrv_resourcerole.id=authsrv_accountresourcerole.role_id`).
Where("authsrv_accountresourcerole.account_id = ?", id).
Where("authsrv_resourcerole.trash = ?", false).
Where("authsrv_accountresourcerole.trash = ?", false).
Scan(ctx, &r)
if err != nil {
return nil, err
@@ -36,6 +39,9 @@ func GetUserRoles(ctx context.Context, db bun.IDB, id uuid.UUID) ([]*userv3.Proj
Join(`JOIN authsrv_resourcerole ON authsrv_resourcerole.id=authsrv_projectaccountresourcerole.role_id`).
Join(`JOIN authsrv_project ON authsrv_project.id=authsrv_projectaccountresourcerole.project_id`).
Where("authsrv_projectaccountresourcerole.account_id = ?", id).
Where("authsrv_project.trash = ?", false).
Where("authsrv_resourcerole.trash = ?", false).
Where("authsrv_projectaccountresourcerole.trash = ?", false).
Scan(ctx, &pr)
if err != nil {
return nil, err
@@ -47,6 +53,9 @@ func GetUserRoles(ctx context.Context, db bun.IDB, id uuid.UUID) ([]*userv3.Proj
Join(`JOIN authsrv_resourcerole ON authsrv_resourcerole.id=authsrv_projectaccountnamespacerole.role_id`).
Join(`JOIN authsrv_project ON authsrv_project.id=authsrv_projectaccountnamespacerole.project_id`). // also need a namespace join
Where("authsrv_projectaccountnamespacerole.account_id = ?", id).
Where("authsrv_project.trash = ?", false).
Where("authsrv_resourcerole.trash = ?", false).
Where("authsrv_projectaccountresourcerole.trash = ?", false).
Scan(ctx, &pnr)
if err != nil {
return nil, err