Roles and permissions view completed
This commit is contained in:
@@ -11,10 +11,22 @@ import (
|
||||
func HandleRemovePermission(w http.ResponseWriter, r *http.Request) {
|
||||
ctx := context.Background()
|
||||
role_id := r.PathValue("role_uuid")
|
||||
permission_id := r.PathValue("permission_id")
|
||||
resource := r.PathValue("resource")
|
||||
action := r.PathValue("action")
|
||||
var permission models.Permission
|
||||
count, err := core.DB.NewSelect().Model(&permission).
|
||||
Where("resource = ? AND action = ?", resource, action).
|
||||
Limit(1).ScanAndCount(ctx)
|
||||
if count == 0 {
|
||||
core.JSONError{
|
||||
Status: core.Error,
|
||||
Message: "Permission doesn't exist.",
|
||||
}.Respond(w, http.StatusNotFound)
|
||||
return
|
||||
}
|
||||
|
||||
_, err := core.DB.NewDelete().Model((*models.PermissionToRole)(nil)).
|
||||
Where("permission_id = ? AND role_id = ?", permission_id, role_id).
|
||||
_, err = core.DB.NewDelete().Model((*models.PermissionToRole)(nil)).
|
||||
Where("permission_id = ? AND role_id = ?", permission.ID, role_id).
|
||||
Exec(ctx)
|
||||
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user