Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
concrexit
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor 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
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
thalia
concrexit
Commits
bccb5528
Verified
Commit
bccb5528
authored
5 years ago
by
Sébastiaan Versteeg
Browse files
Options
Downloads
Patches
Plain Diff
Fix permission in admin views of pizzas
parent
b37c42a4
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!1345
Fix permission in admin views of pizzas
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
docs/pizzas.rst
+8
-0
8 additions, 0 deletions
docs/pizzas.rst
website/pizzas/admin_views.py
+1
-1
1 addition, 1 deletion
website/pizzas/admin_views.py
website/pizzas/decorators.py
+36
-0
36 additions, 0 deletions
website/pizzas/decorators.py
with
45 additions
and
1 deletion
docs/pizzas.rst
+
8
−
0
View file @
bccb5528
...
...
@@ -40,6 +40,14 @@ pizzas.apps module
:undoc-members:
:show-inheritance:
pizzas.decorators module
------------------------
.. automodule:: pizzas.decorators
:members:
:undoc-members:
:show-inheritance:
pizzas.models module
--------------------
...
...
This diff is collapsed.
Click to expand it.
website/pizzas/admin_views.py
+
1
−
1
View file @
bccb5528
...
...
@@ -5,7 +5,7 @@ from django.utils.text import capfirst
from
django.utils.translation
import
ugettext_lazy
as
_
from
django.views.generic
import
TemplateView
from
event
s.decorators
import
organiser_only
from
pizza
s.decorators
import
organiser_only
from
payments.models
import
Payment
from
pizzas.models
import
PizzaEvent
,
Order
...
...
This diff is collapsed.
Click to expand it.
website/pizzas/decorators.py
0 → 100644
+
36
−
0
View file @
bccb5528
"""
The decorators defined by the pizzas package
"""
from
django.core.exceptions
import
PermissionDenied
from
events
import
services
from
pizzas.models
import
PizzaEvent
def
organiser_only
(
view_function
):
"""
See OrganiserOnly
"""
return
OrganiserOnly
(
view_function
)
class
OrganiserOnly
(
object
):
"""
Decorator that denies access to the page if:
1. There is no `pk` in the request
2. The specified pizza event does not exist
3. The user is no organiser of the specified pizza event
"""
def
__init__
(
self
,
view_function
):
self
.
view_function
=
view_function
def
__call__
(
self
,
request
,
*
args
,
**
kwargs
):
pizza_event
=
None
if
'
pk
'
in
kwargs
:
try
:
pizza_event
=
PizzaEvent
.
objects
.
get
(
pk
=
kwargs
.
get
(
'
pk
'
))
except
PizzaEvent
.
DoesNotExist
:
pass
if
pizza_event
and
services
.
is_organiser
(
request
.
member
,
pizza_event
.
event
):
return
self
.
view_function
(
request
,
*
args
,
**
kwargs
)
raise
PermissionDenied
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