Skip to content

Commit

Permalink
Add an endpoint to show a user their permissions (#326)
Browse files Browse the repository at this point in the history
  • Loading branch information
cemathey authored Nov 8, 2023
1 parent c22c810 commit 110ca94
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
20 changes: 20 additions & 0 deletions rconweb/api/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from typing import Any

from django.contrib.auth import authenticate, login, logout
from django.contrib.auth.models import Permission
from django.contrib.auth.decorators import permission_required
from django.contrib.auth.hashers import make_password
from django.contrib.auth.models import User
Expand Down Expand Up @@ -235,3 +236,22 @@ def get_ingame_mods(request):
result=ingame_mods(),
failed=False,
)

@csrf_exempt
@login_required()
def get_own_user_permissions(request):
command_name = "get_own_user_permissions"

permissions = Permission.objects.filter(user=request.user)
trimmed_permissions = [
{
"permission": p['codename'],
"description": p['name'],
}
for p in permissions.values()
]

return api_response(command=command_name, result={
"permissions": trimmed_permissions,
"is_superuser": request.user.is_superuser,
}, failed=False)
1 change: 1 addition & 0 deletions rconweb/api/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ def get_api_documentation(request):
("is_logged_in", auth.is_logged_in),
("get_online_mods", auth.get_online_mods),
("get_ingame_mods", auth.get_ingame_mods),
("get_own_user_permissions", auth.get_own_user_permissions),
("get_services", services.get_services),
("do_service", services.do_service),
("server_list", multi_servers.get_server_list),
Expand Down

0 comments on commit 110ca94

Please sign in to comment.