Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-platform
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
edx-platform
Commits
a3703fbf
Commit
a3703fbf
authored
Jul 24, 2014
by
Greg Price
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor a small amount of forum permission code
parent
c23a27ba
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
9 additions
and
9 deletions
+9
-9
lms/djangoapps/django_comment_client/permissions.py
+9
-9
No files found.
lms/djangoapps/django_comment_client/permissions.py
View file @
a3703fbf
...
...
@@ -37,16 +37,16 @@ def has_permission(user, permission, course_id=None):
CONDITIONS
=
[
'is_open'
,
'is_author'
]
def
_check_condition
(
user
,
condition
,
co
urse_id
,
data
):
def
check_open
(
user
,
con
dition
,
course_id
,
data
):
def
_check_condition
(
user
,
condition
,
co
ntent
):
def
check_open
(
user
,
con
tent
):
try
:
return
data
and
not
data
[
'content'
]
[
'closed'
]
return
content
and
not
content
[
'closed'
]
except
KeyError
:
return
False
def
check_author
(
user
,
con
dition
,
course_id
,
data
):
def
check_author
(
user
,
con
tent
):
try
:
return
data
and
data
[
'content'
]
[
'user_id'
]
==
str
(
user
.
id
)
return
content
and
content
[
'user_id'
]
==
str
(
user
.
id
)
except
KeyError
:
return
False
...
...
@@ -55,10 +55,10 @@ def _check_condition(user, condition, course_id, data):
'is_author'
:
check_author
,
}
return
handlers
[
condition
](
user
,
con
dition
,
course_id
,
data
)
return
handlers
[
condition
](
user
,
con
tent
)
def
_check_conditions_permissions
(
user
,
permissions
,
course_id
,
**
kwargs
):
def
_check_conditions_permissions
(
user
,
permissions
,
course_id
,
content
):
"""
Accepts a list of permissions and proceed if any of the permission is valid.
Note that ["can_view", "can_edit"] will proceed if the user has either
...
...
@@ -69,7 +69,7 @@ def _check_conditions_permissions(user, permissions, course_id, **kwargs):
def
test
(
user
,
per
,
operator
=
"or"
):
if
isinstance
(
per
,
basestring
):
if
per
in
CONDITIONS
:
return
_check_condition
(
user
,
per
,
co
urse_id
,
kwargs
)
return
_check_condition
(
user
,
per
,
co
ntent
)
return
cached_has_permission
(
user
,
per
,
course_id
=
course_id
)
elif
isinstance
(
per
,
list
)
and
operator
in
[
"and"
,
"or"
]:
results
=
[
test
(
user
,
x
,
operator
=
"and"
)
for
x
in
per
]
...
...
@@ -115,4 +115,4 @@ def check_permissions_by_view(user, course_id, content, name):
p
=
VIEW_PERMISSIONS
[
name
]
except
KeyError
:
logging
.
warning
(
"Permission for view named
%
s does not exist in permissions.py"
%
name
)
return
_check_conditions_permissions
(
user
,
p
,
course_id
,
content
=
content
)
return
_check_conditions_permissions
(
user
,
p
,
course_id
,
content
)
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