Better handling of permissions

This commit is contained in:
cdricms
2025-01-31 13:07:25 +01:00
parent acfd2c7b14
commit f7dd0c60d6
12 changed files with 45 additions and 57 deletions

View File

@@ -9,21 +9,14 @@ import (
)
func HandlePermission(w http.ResponseWriter, r *http.Request) {
id := r.PathValue("permission_id")
var permission models.Permission
count, err := core.DB.NewSelect().
Model(&permission).
Where("id = ?", id).
resource := r.PathValue("resource")
action := r.PathValue("action")
var permissions models.Permission
err := core.DB.NewSelect().
Model(&permissions).
Where("resource = ? AND action = ?", resource, action).
Limit(1).
ScanAndCount(context.Background())
if count == 0 {
core.JSONSuccess{
Status: core.Success,
Message: "Permission not found.",
}.Respond(w, http.StatusNotFound)
return
}
Scan(context.Background())
if err != nil {
core.JSONError{
@@ -35,7 +28,7 @@ func HandlePermission(w http.ResponseWriter, r *http.Request) {
core.JSONSuccess{
Status: core.Success,
Message: "Permission found.",
Data: permission,
Message: "Permissions found.",
Data: permissions,
}.Respond(w, http.StatusOK)
}