ch users <-> branches
This commit is contained in:
1 parent
d3e188affe
commit
0971158e98
9 files changed
+43
-18
No files matched your search
@@ -74,7 +74,11 @@ const userPermissionsJSON = `COALESCE((
|
||||
), '[]'::json)`
|
||||
|
||||
func (r *repository) List(ctx context.Context, filter user.ListFilter) (user.ListUserDTO, error) {
|
||||
fromClause, whereClause, args := buildFilteredListQuery(filter, listVisibleRoles...)
|
||||
roles := listVisibleRoles
|
||||
if filter.AllRoles {
|
||||
roles = nil
|
||||
}
|
||||
fromClause, whereClause, args := buildFilteredListQuery(filter, roles...)
|
||||
return r.paginateUsers(ctx, filter, fromClause, whereClause, args)
|
||||
}
|
||||
|
||||
|
||||
@@ -70,6 +70,9 @@ type ListFilter struct {
|
||||
BranchIds []int64
|
||||
Page int
|
||||
Limit int
|
||||
// AllRoles, when true, skips the role=user filter so admin/superadmin
|
||||
// callers see every user regardless of role.
|
||||
AllRoles bool
|
||||
}
|
||||
|
||||
type ListUserDTO struct {
|
||||
|
||||
@@ -62,7 +62,7 @@ func (h *handler) RegisterPublic(engine *gin.Engine) {
|
||||
|
||||
// list godoc
|
||||
// @Summary List users
|
||||
// @Description Returns paginated users with role user, including roleId
|
||||
// @Description Returns paginated users, including roleId. Admin-guard callers (admin, superadmin, and other admin-guard roles) see users of every role; branch-scoped operators see role=user only, scoped to their branches.
|
||||
// @Tags user
|
||||
// @Produce json
|
||||
// @Security BearerAuth
|
||||
@@ -80,6 +80,7 @@ func (h *handler) list(c *gin.Context) {
|
||||
c.JSON(http.StatusBadRequest, appresult.ErrMissingParam)
|
||||
return
|
||||
}
|
||||
filter.AllRoles = rbac.IsAdminGuard(c)
|
||||
rbac.BindBranchIDs(c, &filter.BranchIds)
|
||||
|
||||
result, err := h.repository.List(c.Request.Context(), filter)
|
||||
|
||||
Reference in new issue
Block a user