Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
djangoldp-notification
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
decentral1se
djangoldp-notification
Commits
7f87f83b
Verified
Commit
7f87f83b
authored
5 years ago
by
Jean-Baptiste Pasquier
Browse files
Options
Downloads
Patches
Plain Diff
update: custom permissions for nested_field
parent
6b9e8162
No related branches found
Branches containing commit
Tags
v0.0.38
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
djangoldp_notification/models.py
+2
-0
2 additions, 0 deletions
djangoldp_notification/models.py
djangoldp_notification/permissions.py
+38
-0
38 additions, 0 deletions
djangoldp_notification/permissions.py
with
40 additions
and
0 deletions
djangoldp_notification/models.py
+
2
−
0
View file @
7f87f83b
...
...
@@ -16,6 +16,7 @@ from djangoldp.fields import LDPUrlField
from
djangoldp.models
import
Model
from
django.template
import
loader
from
.permissions
import
InboxPermissions
class
Notification
(
Model
):
...
...
@@ -30,6 +31,7 @@ class Notification(Model):
class
Meta
(
Model
.
Meta
):
owner_field
=
'
user
'
ordering
=
[
'
-date
'
]
permission_classes
=
[
InboxPermissions
]
anonymous_perms
=
[
'
add
'
]
authenticated_perms
=
[
'
inherit
'
]
owner_perms
=
[
'
view
'
,
'
change
'
,
'
control
'
]
...
...
This diff is collapsed.
Click to expand it.
djangoldp_notification/permissions.py
0 → 100644
+
38
−
0
View file @
7f87f83b
from
djangoldp.permissions
import
LDPPermissions
class
InboxPermissions
(
LDPPermissions
):
def
has_permission
(
self
,
request
,
view
):
from
djangoldp.models
import
Model
if
self
.
is_a_container
(
request
.
_request
.
path
):
try
:
"""
If on nested field we use users permissions
"""
obj
=
Model
.
resolve_parent
(
request
.
path
)
model
=
view
.
parent_model
"""
If still on nested field and request is post (/users/X/inbox/) we use notification permissions
"""
if
view
.
parent_model
!=
view
.
model
and
request
.
method
==
'
POST
'
:
obj
=
None
model
=
view
.
model
except
:
"""
Not on nested field we use notification permissions
"""
obj
=
None
model
=
view
.
model
else
:
obj
=
Model
.
resolve_id
(
request
.
_request
.
path
)
model
=
view
.
model
perms
=
self
.
get_permissions
(
request
.
method
,
model
)
for
perm
in
perms
:
if
not
perm
.
split
(
'
.
'
)[
1
].
split
(
'
_
'
)[
0
]
in
self
.
user_permissions
(
request
.
user
,
model
,
obj
):
return
False
return
True
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment