Skip to content

Commit

Permalink
updated role endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
BK1031 committed Aug 30, 2024
1 parent e7edc5f commit 87ac113
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions controller/role_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,23 @@ import (
)

func GetAllRolesForUser(c *gin.Context) {
RequireAny(c, RequestTokenHasScope(c, "sentinel:all"), RequestTokenHasScope(c, "user:read"))
RequireAny(c, RequestUserHasID(c, c.Param("userID")), RequestUserHasRole(c, "d_admin"))
Require(c, Any(
RequestTokenHasScope(c, "sentinel:all"),
All(
RequestTokenHasScope(c, "user:read"),
Any(RequestUserHasID(c, c.Param("userID")), RequestUserHasRole(c, "d_admin")),
),
))

roles := service.GetRolesForUser(c.Param("userID"))
c.JSON(200, roles)
}

func SetRolesForUser(c *gin.Context) {
RequireAny(c, RequestTokenHasScope(c, "sentinel:all"))
RequireAny(c, RequestUserHasID(c, c.Param("userID")), RequestUserHasRole(c, "d_admin"))
Require(c, All(
RequestTokenHasScope(c, "sentinel:all"),
RequestUserHasRole(c, "d_admin"),
))

var roles []string
if err := c.ShouldBindJSON(&roles); err != nil {
Expand Down

0 comments on commit 87ac113

Please sign in to comment.