Skip to content

Commit

Permalink
remaining depth added to check api response
Browse files Browse the repository at this point in the history
  • Loading branch information
tolgaOzen committed Jul 16, 2022
1 parent 75e72e1 commit 3e8cfe1
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 7 deletions.
5 changes: 4 additions & 1 deletion docs/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,10 @@ var doc = `{
"can": {
"type": "boolean"
},
"decisions": {}
"decisions": {},
"remaining_depth": {
"type": "integer"
}
}
},
"responses.HTTPErrorResponse": {
Expand Down
5 changes: 4 additions & 1 deletion docs/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,10 @@
"can": {
"type": "boolean"
},
"decisions": {}
"decisions": {},
"remaining_depth": {
"type": "integer"
}
}
},
"responses.HTTPErrorResponse": {
Expand Down
2 changes: 2 additions & 0 deletions docs/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ definitions:
can:
type: boolean
decisions: {}
remaining_depth:
type: integer
type: object
responses.HTTPErrorResponse:
properties:
Expand Down
5 changes: 3 additions & 2 deletions internal/controllers/http/responses/check.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package responses

type Check struct {
Can bool `json:"can"`
Decisions interface{} `json:"decisions"`
Can bool `json:"can"`
RemainingDepth int `json:"remaining_depth"`
Decisions interface{} `json:"decisions"`
}
8 changes: 5 additions & 3 deletions internal/controllers/http/v1/permission.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ func (r *permissionRoutes) check(c echo.Context) (err error) {

var can bool
var vi *services.VisitMap
can, vi, err = r.service.Check(context.Background(), request.Body.User, request.Body.Action, request.Body.Object, request.Body.Depth)
var rm int
can, vi, rm, err = r.service.Check(context.Background(), request.Body.User, request.Body.Action, request.Body.Object, request.Body.Depth)
if err != nil {
if errors.Is(err, services.DepthError) {
return c.JSON(http.StatusUnprocessableEntity, map[string]interface{}{"depth": "depth is not enough to check"})
Expand All @@ -68,7 +69,8 @@ func (r *permissionRoutes) check(c echo.Context) (err error) {
}

return c.JSON(http.StatusOK, responses.Check{
Can: can,
Decisions: vi,
Can: can,
Decisions: vi,
RemainingDepth: rm,
})
}

0 comments on commit 3e8cfe1

Please sign in to comment.