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
158e978a
Commit
158e978a
authored
Aug 15, 2012
by
Mike Chen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added naive caching. not sure how to expire.
parent
2454c06b
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
11 additions
and
2 deletions
+11
-2
lms/djangoapps/django_comment_client/permissions.py
+11
-2
No files found.
lms/djangoapps/django_comment_client/permissions.py
View file @
158e978a
...
@@ -5,6 +5,7 @@ from django.dispatch import receiver
...
@@ -5,6 +5,7 @@ from django.dispatch import receiver
from
student.models
import
CourseEnrollment
from
student.models
import
CourseEnrollment
import
logging
import
logging
from
util.cache
import
cache
@receiver
(
post_save
,
sender
=
CourseEnrollment
)
@receiver
(
post_save
,
sender
=
CourseEnrollment
)
...
@@ -17,9 +18,17 @@ def assign_default_role(sender, instance, **kwargs):
...
@@ -17,9 +18,17 @@ def assign_default_role(sender, instance, **kwargs):
logging
.
info
(
"assign_default_role: adding
%
s as
%
s"
%
(
instance
.
user
,
role
))
logging
.
info
(
"assign_default_role: adding
%
s as
%
s"
%
(
instance
.
user
,
role
))
instance
.
user
.
roles
.
add
(
role
)
instance
.
user
.
roles
.
add
(
role
)
def
has_permission
(
user
,
permission
,
course_id
=
None
):
def
cached_
has_permission
(
user
,
permission
,
course_id
=
None
):
# if user.permissions.filter(name=permission).exists():
# if user.permissions.filter(name=permission).exists():
# return True
# return True
key
=
"permission_
%
d_
%
s_
%
s"
%
(
user
.
id
,
str
(
course_id
),
permission
)
val
=
cache
.
get
(
key
,
None
)
if
val
not
in
[
True
,
False
]:
val
=
has_permission
(
user
,
permission
,
course_id
=
course_id
)
cache
.
set
(
key
,
val
,
3600
)
return
val
def
has_permission
(
user
,
permission
,
course_id
=
None
):
for
role
in
user
.
roles
.
filter
(
course_id
=
course_id
):
for
role
in
user
.
roles
.
filter
(
course_id
=
course_id
):
if
role
.
has_permission
(
permission
):
if
role
.
has_permission
(
permission
):
return
True
return
True
...
@@ -60,7 +69,7 @@ def check_conditions_permissions(user, permissions, course_id, **kwargs):
...
@@ -60,7 +69,7 @@ def check_conditions_permissions(user, permissions, course_id, **kwargs):
if
isinstance
(
per
,
basestring
):
if
isinstance
(
per
,
basestring
):
if
per
in
CONDITIONS
:
if
per
in
CONDITIONS
:
return
check_condition
(
user
,
per
,
course_id
,
kwargs
)
return
check_condition
(
user
,
per
,
course_id
,
kwargs
)
return
has_permission
(
user
,
per
,
course_id
=
course_id
)
return
cached_
has_permission
(
user
,
per
,
course_id
=
course_id
)
elif
isinstance
(
per
,
list
)
and
operator
in
[
"and"
,
"or"
]:
elif
isinstance
(
per
,
list
)
and
operator
in
[
"and"
,
"or"
]:
results
=
[
test
(
user
,
x
,
operator
=
"and"
)
for
x
in
per
]
results
=
[
test
(
user
,
x
,
operator
=
"and"
)
for
x
in
per
]
if
operator
==
"or"
:
if
operator
==
"or"
:
...
...
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