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
283847a4
Commit
283847a4
authored
Aug 14, 2012
by
Rocky Duan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added administrator role
parent
90d3dc37
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
53 additions
and
27 deletions
+53
-27
lms/djangoapps/django_comment_client/management/commands/seed_permissions_roles.py
+6
-0
lms/djangoapps/django_comment_client/management/commands/show_permissions.py
+1
-0
lms/djangoapps/django_comment_client/models.py
+2
-1
lms/djangoapps/django_comment_client/permissions.py
+29
-23
lms/templates/discussion/user_profile.html
+15
-3
No files found.
lms/djangoapps/django_comment_client/management/commands/seed_permissions_roles.py
View file @
283847a4
...
...
@@ -7,6 +7,7 @@ class Command(BaseCommand):
help
=
'Seed default permisssions and roles'
def
handle
(
self
,
*
args
,
**
options
):
administrator_role
=
Role
.
objects
.
get_or_create
(
name
=
"Administrator"
,
course_id
=
"MITx/6.002x/2012_Fall"
)[
0
]
moderator_role
=
Role
.
objects
.
get_or_create
(
name
=
"Moderator"
,
course_id
=
"MITx/6.002x/2012_Fall"
)[
0
]
student_role
=
Role
.
objects
.
get_or_create
(
name
=
"Student"
,
course_id
=
"MITx/6.002x/2012_Fall"
)[
0
]
...
...
@@ -19,4 +20,9 @@ class Command(BaseCommand):
"endorse_comment"
,
"delete_comment"
]:
moderator_role
.
add_permission
(
per
)
for
per
in
[
"manage_moderator"
]:
administrator_role
.
add_permission
(
per
)
moderator_role
.
inherit_permissions
(
student_role
)
administrator_role
.
inherit_permissions
(
moderator_role
)
lms/djangoapps/django_comment_client/management/commands/show_permissions.py
View file @
283847a4
...
...
@@ -8,6 +8,7 @@ class Command(BaseCommand):
help
=
"Show a user's roles and permissions"
def
handle
(
self
,
*
args
,
**
options
):
print
args
if
len
(
args
)
!=
1
:
raise
CommandError
(
"The number of arguments does not match. "
)
try
:
...
...
lms/djangoapps/django_comment_client/models.py
View file @
283847a4
...
...
@@ -11,7 +11,8 @@ class Role(models.Model):
def
__unicode__
(
self
):
return
self
.
name
+
" for "
+
(
self
.
course_id
if
self
.
course_id
else
"all courses"
)
def
inherit_permissions
(
self
,
role
):
def
inherit_permissions
(
self
,
role
):
# TODO the name of this method is a little bit confusing,
# since it's one-off and doesn't handle inheritance later
if
role
.
course_id
and
role
.
course_id
!=
self
.
course_id
:
logging
.
warning
(
"
%
s cannot inheret permissions from
%
s due to course_id inconsistency"
%
(
self
,
role
))
...
...
lms/djangoapps/django_comment_client/permissions.py
View file @
283847a4
...
...
@@ -17,7 +17,6 @@ def assign_default_role(sender, instance, **kwargs):
logging
.
info
(
"assign_default_role: adding
%
s as
%
s"
%
(
instance
.
user
,
role
))
instance
.
user
.
roles
.
add
(
role
)
def
has_permission
(
user
,
permission
,
course_id
=
None
):
# if user.permissions.filter(name=permission).exists():
# return True
...
...
@@ -30,10 +29,16 @@ def has_permission(user, permission, course_id=None):
CONDITIONS
=
[
'is_open'
,
'is_author'
]
def
check_condition
(
user
,
condition
,
course_id
,
data
):
def
check_open
(
user
,
condition
,
course_id
,
data
):
return
not
data
[
'content'
][
'closed'
]
try
:
return
data
and
not
data
[
'content'
][
'closed'
]
except
KeyError
:
return
False
def
check_author
(
user
,
condition
,
course_id
,
data
):
return
data
[
'content'
][
'user_id'
]
==
str
(
user
.
id
)
try
:
return
data
and
data
[
'content'
][
'user_id'
]
==
str
(
user
.
id
)
except
KeyError
:
return
False
handlers
=
{
'is_open'
:
check_open
,
...
...
@@ -67,26 +72,27 @@ def check_conditions_permissions(user, permissions, course_id, **kwargs):
VIEW_PERMISSIONS
=
{
'update_thread'
:
[
'edit_content'
,
[
'update_thread'
,
'is_open'
,
'author'
]],
# 'create_comment' : [["create_comment", "is_open"]],
'create_comment'
:
[
"create_comment"
],
'delete_thread'
:
[
'delete_thread'
],
'update_comment'
:
[
'edit_content'
,
[
'update_comment'
,
'is_open'
,
'author'
]],
'endorse_comment'
:
[
'endorse_comment'
],
'openclose_thread'
:
[
'openclose_thread'
],
'create_sub_comment'
:
[[
'create_sub_comment'
,
'is_open'
]],
'delete_comment'
:
[
'delete_comment'
],
'vote_for_comment'
:
[[
'vote'
,
'is_open'
]],
'undo_vote_for_comment'
:
[[
'unvote'
,
'is_open'
]],
'vote_for_thread'
:
[[
'vote'
,
'is_open'
]],
'undo_vote_for_thread'
:
[[
'unvote'
,
'is_open'
]],
'follow_thread'
:
[
'follow_thread'
],
'follow_commentable'
:
[
'follow_commentable'
],
'follow_user'
:
[
'follow_user'
],
'unfollow_thread'
:
[
'unfollow_thread'
],
'unfollow_commentable'
:
[
'unfollow_commentable'
],
'unfollow_user'
:
[
'unfollow_user'
],
'create_thread'
:
[
'create_thread'
],
'update_thread'
:
[
'edit_content'
,
[
'update_thread'
,
'is_open'
,
'author'
]],
# 'create_comment' : [["create_comment", "is_open"]],
'create_comment'
:
[
"create_comment"
],
'delete_thread'
:
[
'delete_thread'
],
'update_comment'
:
[
'edit_content'
,
[
'update_comment'
,
'is_open'
,
'author'
]],
'endorse_comment'
:
[
'endorse_comment'
],
'openclose_thread'
:
[
'openclose_thread'
],
'create_sub_comment'
:
[[
'create_sub_comment'
,
'is_open'
]],
'delete_comment'
:
[
'delete_comment'
],
'vote_for_comment'
:
[[
'vote'
,
'is_open'
]],
'undo_vote_for_comment'
:
[[
'unvote'
,
'is_open'
]],
'vote_for_thread'
:
[[
'vote'
,
'is_open'
]],
'undo_vote_for_thread'
:
[[
'unvote'
,
'is_open'
]],
'follow_thread'
:
[
'follow_thread'
],
'follow_commentable'
:
[
'follow_commentable'
],
'follow_user'
:
[
'follow_user'
],
'unfollow_thread'
:
[
'unfollow_thread'
],
'unfollow_commentable'
:
[
'unfollow_commentable'
],
'unfollow_user'
:
[
'unfollow_user'
],
'create_thread'
:
[
'create_thread'
],
'update_moderator_status'
:
[
'manage_moderator'
],
}
...
...
lms/templates/discussion/user_profile.html
View file @
283847a4
<
%!
from
django_comment_client
.
utils
import
pluralize
%
>
<
%!
from
django_comment_client
.
permissions
import
has_permission
,
check_permissions_by_view
%
>
<
%
inherit
file=
"../main.html"
/>
<
%
namespace
name=
'static'
file=
'../static_content.html'
/>
...
...
@@ -19,13 +20,24 @@
<div
class=
"course-wrapper"
>
<section
aria-label=
"User Profile"
class=
"user-profile"
>
<nav>
<
%
role_names =
sorted(map(lambda
x:
x
.
name
,
django_user
.
roles
.
all
()))
%
>
<article
class=
"sidebar-module discussion-sidebar"
>
<div
class=
"sidebar-username"
>
${user.username}
</div>
<div
class=
"sidebar-username"
>
${django_user.username}
</div>
<div
class=
"sidebar-user-roles"
>
${", ".join(role_names)}
</div>
<div
class=
"sidebar-threads-count"
>
${discussion_user['threads_count']} ${pluralize('discussion', discussion_user['threads_count'])} started
</div>
<div
class=
"sidebar-comments-count"
>
${discussion_user['comments_count']} ${pluralize('comment', discussion_user['comments_count'])}
</div>
<a
href=
"#"
class=
"sidebar-promote-moderator-button"
>
Promote to Moderator
</a>
<a
href=
"#"
class=
"sidebar-revoke-moderator-button"
>
Revoke Moderator provileges
</a>
% if check_permissions_by_view(user, course.id, content=None, name='update_moderator_status'):
% if "Moderator" in role_names:
<a
href=
"javascript:void(0)"
class=
"sidebar-revoke-moderator-button"
>
Revoke Moderator provileges
</a>
% else:
<a
href=
"javascript:void(0)"
class=
"sidebar-promote-moderator-button"
>
Promote to Moderator
</a>
% endif
% endif
</article>
</nav>
...
...
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