-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add notification on update of lending instance
- Loading branch information
1 parent
ab09ba5
commit 0c729d5
Showing
5 changed files
with
136 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
from lego.apps.permissions.constants import CREATE, DELETE, EDIT, LIST, VIEW | ||
from lego.apps.permissions.permissions import PermissionHandler | ||
from django.db.models import Q | ||
|
||
|
||
class LendingInstancePermissionHandler(PermissionHandler): | ||
force_object_permission_check = True | ||
authentication_map = {LIST: False, VIEW: False} | ||
default_require_auth = True | ||
|
||
def has_perm( | ||
self, | ||
user, | ||
perm, | ||
obj=None, | ||
queryset=None, | ||
check_keyword_permissions=True, | ||
**kwargs | ||
): | ||
if perm == LIST: | ||
return True | ||
if not user.is_authenticated: | ||
return False | ||
|
||
# Check object permissions before keywork perms | ||
if obj is not None: | ||
if self.has_object_permissions(user, perm, obj): | ||
return True | ||
|
||
if perm == EDIT and self.created_by(user, obj): | ||
return True | ||
|
||
if perm == CREATE: | ||
return True | ||
|
||
has_perm = super().has_perm( | ||
user, perm, obj, queryset, check_keyword_permissions, **kwargs | ||
) | ||
|
||
if has_perm: | ||
return True | ||
|
||
return False | ||
|
||
def has_object_permissions(self, user, perm, obj): | ||
if perm == DELETE: | ||
return False | ||
if perm == EDIT and obj.created_by == user: | ||
return True | ||
if perm == CREATE: | ||
return True | ||
return not (perm == DELETE or perm == EDIT) | ||
|
||
def filter_queryset(self, user, queryset, **kwargs): | ||
if user.is_authenticated: | ||
return queryset.filter( | ||
Q(created_by=user) | | ||
Q(lendable_object__responsible_groups__in=user.abakus_groups) | ||
).distinct() | ||
return queryset.none() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters