Better handling of permissions
This commit is contained in:
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user