Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
scheduling-system
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
External wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
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
SMASCH
scheduling-system
Commits
cf945719
Commit
cf945719
authored
6 years ago
by
Carlos Vega
Browse files
Options
Downloads
Patches
Plain Diff
added support for class-based views
parent
7aa15f11
No related branches found
No related tags found
1 merge request
!192
Feature/add way to change password and PERMISSIONS
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
smash/web/decorators.py
+9
-3
9 additions, 3 deletions
smash/web/decorators.py
with
9 additions
and
3 deletions
smash/web/decorators.py
+
9
−
3
View file @
cf945719
...
@@ -8,6 +8,7 @@ from django.http import HttpResponseForbidden
...
@@ -8,6 +8,7 @@ from django.http import HttpResponseForbidden
from
django.contrib.auth.models
import
Permission
from
django.contrib.auth.models
import
Permission
import
functools
import
functools
from
collections
import
defaultdict
from
collections
import
defaultdict
from
django.views.generic.base
import
ContextMixin
logger
=
logging
.
getLogger
(
__name__
)
logger
=
logging
.
getLogger
(
__name__
)
...
@@ -84,19 +85,24 @@ class PermissionDecorator:
...
@@ -84,19 +85,24 @@ class PermissionDecorator:
'''
'''
This method is also called when the function is decorated
This method is also called when the function is decorated
'''
'''
def
func_wrapper
(
request
,
**
kwargs
):
def
func_wrapper
(
thing
,
*
args
,
**
kwargs
):
'''
'''
This method is called when the decorated function is called
This method is called when the decorated function is called
'''
'''
if
isinstance
(
thing
,
ContextMixin
):
request
=
thing
.
request
else
:
request
=
thing
if
request
.
user
.
is_superuser
:
if
request
.
user
.
is_superuser
:
return
func
(
request
,
**
kwargs
)
return
func
(
thing
,
*
args
,
**
kwargs
)
else
:
else
:
worker
=
Worker
.
get_by_user
(
request
.
user
)
worker
=
Worker
.
get_by_user
(
request
.
user
)
roles
=
WorkerStudyRole
.
objects
.
filter
(
worker
=
worker
,
study_id
=
GLOBAL_STUDY_ID
)
roles
=
WorkerStudyRole
.
objects
.
filter
(
worker
=
worker
,
study_id
=
GLOBAL_STUDY_ID
)
if
roles
.
count
()
>
0
:
if
roles
.
count
()
>
0
:
permissions
=
roles
[
0
].
permissions
.
filter
(
codename
=
self
.
perm_codename
)
permissions
=
roles
[
0
].
permissions
.
filter
(
codename
=
self
.
perm_codename
)
if
len
(
permissions
)
>
0
:
if
len
(
permissions
)
>
0
:
return
func
(
request
,
**
kwargs
)
return
func
(
thing
,
*
args
,
**
kwargs
)
messages
.
error
(
request
,
'
You are not authorized to view this page. Request permissions to the system administrator.
'
)
messages
.
error
(
request
,
'
You are not authorized to view this page. Request permissions to the system administrator.
'
)
#avoid loops if the HTTP_REFERER header is set to the visited URL
#avoid loops if the HTTP_REFERER header is set to the visited URL
http_referer
=
request
.
META
.
get
(
'
HTTP_REFERER
'
,
'
web.views.index
'
)
http_referer
=
request
.
META
.
get
(
'
HTTP_REFERER
'
,
'
web.views.index
'
)
...
...
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