Skip to content
Snippets Groups Projects
Commit c48d8134 authored by Hangzhi Yu's avatar Hangzhi Yu
Browse files

Replace decorators for dashboard and search with django-rules decorators,...

Replace decorators for dashboard and search with django-rules decorators, adding view_dashboard and search rules and additional global permission search
parent 79912be6
No related branches found
No related tags found
1 merge request!207Resolve "Roles and permissions"
......@@ -582,4 +582,5 @@ class GlobalPermissions(ExtensibleModel):
("link_persons_accounts", _("Can link persons to accounts")),
("manage_data", _("Can manage data")),
("impersonate", _("Can impersonate")),
("search", _("Can use search")),
)
......@@ -12,6 +12,13 @@ from aleksis.core.util.predicates import (
add_perm("core", always_allow)
# View dashboard
add_perm("core.view_dashboard", has_person_predicate)
# Use search
search_predicate = has_person_predicate & has_global_perm("core.search")
add_perm("core.search", search_predicate)
# View persons
view_persons_predicate = has_person_predicate & (
has_global_perm("core.view_person") | has_any_object("core.view_person", Person)
......
......@@ -26,7 +26,7 @@ from .tables import GroupsTable, PersonsTable
from .util import messages
@person_required
@permission_required("core.view_dashboard")
def index(request: HttpRequest) -> HttpResponse:
context = {}
......@@ -347,7 +347,7 @@ def delete_announcement(request: HttpRequest, pk: int) -> HttpResponse:
return redirect("announcements")
@login_required
@permission_required("core.search")
def searchbar_snippets(request: HttpRequest) -> HttpResponse:
query = request.GET.get('q', '')
limit = int(request.GET.get('limit', '5'))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment