diff --git a/user/db.go b/user/db.go index 1411051..d240d11 100644 --- a/user/db.go +++ b/user/db.go @@ -79,6 +79,33 @@ func roleFindByID(ctx context.Context, id primitive.ObjectID) (model.DBRole, err return doc, err } +func roleFindByCondition(ctx context.Context, cond interface{}, opts ...*options.FindOptions) (docs []model.DBRole) { + var ( + col = database.GetRoleCol() + ) + docs = make([]model.DBRole, 0) + + cursor, err := col.Find(ctx, cond, opts...) + if err != nil { + logger.Error("usermngmt - Role - Find", logger.LogData{ + "cond": cond, + "opts": opts, + "err": err.Error(), + }) + return + } + defer cursor.Close(ctx) + if err = cursor.All(ctx, &docs); err != nil { + logger.Error("usermngmt - Role - Decode", logger.LogData{ + "cond": cond, + "opts": opts, + "err": err.Error(), + }) + return + } + return +} + func permissionFindByCondition(ctx context.Context, cond interface{}, opts ...*options.FindOptions) (docs []model.DBPermission) { var ( col = database.GetPermissionCol() diff --git a/user/handle.go b/user/handle.go index 558bba7..f538855 100644 --- a/user/handle.go +++ b/user/handle.go @@ -225,6 +225,13 @@ func GetUsersByPermission(queryParams model.UserByPermissionQuery) (r model.User for _, value := range permissions { roles = append(roles, value.RoleID) } + + // Get admin role + adminRoles := roleFindByCondition(ctx, bson.M{"isAdmin": true}) + for _, value := range adminRoles { + roles = append(roles, value.ID) + } + if len(roles) < 0 { return }