fix the wrong status code when appRoleAssignments is forbidden #6037 #6035

This commit is contained in:
Roman Perekhod
2023-05-10 17:29:49 +02:00
parent b2140bb744
commit 082e450677
2 changed files with 16 additions and 0 deletions

View File

@@ -0,0 +1,7 @@
Bugfix: Fix the wrong status code when appRoleAssignments is forbidden
Fix the wrong status code when appRoleAssignments is forbidden in the CreateAppRoleAssignment and
DeleteAppRoleAssignment methods.
https://github.com/owncloud/ocis/issues/6037
https://github.com/owncloud/ocis/pull/6276

View File

@@ -10,6 +10,7 @@ import (
settingsmsg "github.com/owncloud/ocis/v2/protogen/gen/ocis/messages/settings/v0"
settingssvc "github.com/owncloud/ocis/v2/protogen/gen/ocis/services/settings/v0"
"github.com/owncloud/ocis/v2/services/graph/pkg/service/v0/errorcode"
merrors "go-micro.dev/v4/errors"
)
const principalTypeUser = "User"
@@ -67,6 +68,10 @@ func (g Graph) CreateAppRoleAssignment(w http.ResponseWriter, r *http.Request) {
RoleId: appRoleAssignment.AppRoleId,
})
if err != nil {
if merr, ok := merrors.As(err); ok && merr.Code == http.StatusForbidden {
errorcode.NotAllowed.Render(w, r, http.StatusForbidden, err.Error())
return
}
errorcode.GeneralException.Render(w, r, http.StatusInternalServerError, err.Error())
return
}
@@ -108,6 +113,10 @@ func (g Graph) DeleteAppRoleAssignment(w http.ResponseWriter, r *http.Request) {
Id: appRoleAssignmentID,
})
if err != nil {
if merr, ok := merrors.As(err); ok && merr.Code == http.StatusForbidden {
errorcode.NotAllowed.Render(w, r, http.StatusForbidden, err.Error())
return
}
errorcode.GeneralException.Render(w, r, http.StatusInternalServerError, err.Error())
return
}