Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
converse.js
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
converse.js
Commits
92b1f15f
Commit
92b1f15f
authored
Feb 19, 2013
by
Michal Čihař
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add decorator to test for multiple permissions
parent
17a61f75
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
41 additions
and
7 deletions
+41
-7
weblate/trans/decorators.py
weblate/trans/decorators.py
+36
-0
weblate/trans/views/js.py
weblate/trans/views/js.py
+5
-7
No files found.
weblate/trans/decorators.py
0 → 100644
View file @
92b1f15f
# -*- coding: utf-8 -*-
#
# Copyright © 2012 - 2013 Michal Čihař <michal@cihar.com>
#
# This file is part of Weblate <http://weblate.org/>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
from
django.contrib.auth.decorators
import
user_passes_test
def
any_permission_required
(
*
args
):
'''
A decorator which checks user has any of the given permissions.
permission required can not be used in its place as that takes only a
single permission.
'''
def
test_func
(
user
):
for
perm
in
args
:
if
user
.
has_perm
(
perm
):
return
True
return
False
return
user_passes_test
(
test_func
)
weblate/trans/views/js.py
View file @
92b1f15f
...
@@ -23,9 +23,7 @@ from django.views.decorators.cache import cache_page
...
@@ -23,9 +23,7 @@ from django.views.decorators.cache import cache_page
from
weblate.trans
import
appsettings
from
weblate.trans
import
appsettings
from
django.template
import
RequestContext
from
django.template
import
RequestContext
from
django.http
import
HttpResponse
from
django.http
import
HttpResponse
from
django.contrib.auth.decorators
import
(
from
django.contrib.auth.decorators
import
permission_required
login_required
,
permission_required
,
user_passes_test
)
from
django.db.models
import
Q
from
django.db.models
import
Q
from
weblate.trans.models
import
(
from
weblate.trans.models
import
(
...
@@ -33,6 +31,7 @@ from weblate.trans.models import (
...
@@ -33,6 +31,7 @@ from weblate.trans.models import (
Dictionary
Dictionary
)
)
from
weblate.trans.views.edit
import
parse_search_url
from
weblate.trans.views.edit
import
parse_search_url
from
weblate.trans.decorators
import
any_permission_required
from
whoosh.analysis
import
StandardAnalyzer
,
StemmingAnalyzer
from
whoosh.analysis
import
StandardAnalyzer
,
StemmingAnalyzer
import
logging
import
logging
...
@@ -140,7 +139,6 @@ def get_dictionary(request, unit_id):
...
@@ -140,7 +139,6 @@ def get_dictionary(request, unit_id):
}))
}))
@
login_required
@
permission_required
(
'trans.ignore_check'
)
@
permission_required
(
'trans.ignore_check'
)
def
ignore_check
(
request
,
check_id
):
def
ignore_check
(
request
,
check_id
):
obj
=
get_object_or_404
(
Check
,
pk
=
int
(
check_id
))
obj
=
get_object_or_404
(
Check
,
pk
=
int
(
check_id
))
...
@@ -155,7 +153,7 @@ def ignore_check(request, check_id):
...
@@ -155,7 +153,7 @@ def ignore_check(request, check_id):
return
HttpResponse
(
'ok'
)
return
HttpResponse
(
'ok'
)
@
user_passes_test
(
lambda
u
:
u
.
has_perm
(
'trans.commit_translation'
)
or
u
.
has_perm
(
'trans.update_translation'
)
)
@
any_permission_required
(
'trans.commit_translation'
,
'trans.update_translation'
)
def
git_status_project
(
request
,
project
):
def
git_status_project
(
request
,
project
):
obj
=
get_object_or_404
(
Project
,
slug
=
project
)
obj
=
get_object_or_404
(
Project
,
slug
=
project
)
obj
.
check_acl
(
request
)
obj
.
check_acl
(
request
)
...
@@ -165,7 +163,7 @@ def git_status_project(request, project):
...
@@ -165,7 +163,7 @@ def git_status_project(request, project):
}))
}))
@
user_passes_test
(
lambda
u
:
u
.
has_perm
(
'trans.commit_translation'
)
or
u
.
has_perm
(
'trans.update_translation'
)
)
@
any_permission_required
(
'trans.commit_translation'
,
'trans.update_translation'
)
def
git_status_subproject
(
request
,
project
,
subproject
):
def
git_status_subproject
(
request
,
project
,
subproject
):
obj
=
get_object_or_404
(
SubProject
,
slug
=
subproject
,
project__slug
=
project
)
obj
=
get_object_or_404
(
SubProject
,
slug
=
subproject
,
project__slug
=
project
)
obj
.
check_acl
(
request
)
obj
.
check_acl
(
request
)
...
@@ -175,7 +173,7 @@ def git_status_subproject(request, project, subproject):
...
@@ -175,7 +173,7 @@ def git_status_subproject(request, project, subproject):
}))
}))
@
user_passes_test
(
lambda
u
:
u
.
has_perm
(
'trans.commit_translation'
)
or
u
.
has_perm
(
'trans.update_translation'
)
)
@
any_permission_required
(
'trans.commit_translation'
,
'trans.update_translation'
)
def
git_status_translation
(
request
,
project
,
subproject
,
lang
):
def
git_status_translation
(
request
,
project
,
subproject
,
lang
):
obj
=
get_object_or_404
(
obj
=
get_object_or_404
(
Translation
,
Translation
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment