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
b229cfb8
Commit
b229cfb8
authored
Aug 23, 2012
by
Arjun Singh
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
make discussions work for new users
parent
551c5a9f
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
29 additions
and
23 deletions
+29
-23
common/djangoapps/student/models.py
+11
-1
lms/djangoapps/django_comment_client/__init__.py
+0
-2
lms/djangoapps/django_comment_client/base/views.py
+1
-1
lms/djangoapps/django_comment_client/forum/views.py
+3
-3
lms/djangoapps/django_comment_client/management/commands/create_roles_for_existing.py
+2
-5
lms/djangoapps/django_comment_client/permissions.py
+2
-11
lms/lib/comment_client/user.py
+10
-0
No files found.
common/djangoapps/student/models.py
View file @
b229cfb8
...
@@ -51,6 +51,7 @@ from django.dispatch import receiver
...
@@ -51,6 +51,7 @@ from django.dispatch import receiver
from
functools
import
partial
from
functools
import
partial
import
comment_client
as
cc
import
comment_client
as
cc
from
django_comment_client.models
import
Role
,
Permission
import
logging
import
logging
...
@@ -174,7 +175,6 @@ class PendingEmailChange(models.Model):
...
@@ -174,7 +175,6 @@ class PendingEmailChange(models.Model):
new_email
=
models
.
CharField
(
blank
=
True
,
max_length
=
255
,
db_index
=
True
)
new_email
=
models
.
CharField
(
blank
=
True
,
max_length
=
255
,
db_index
=
True
)
activation_key
=
models
.
CharField
((
'activation key'
),
max_length
=
32
,
unique
=
True
,
db_index
=
True
)
activation_key
=
models
.
CharField
((
'activation key'
),
max_length
=
32
,
unique
=
True
,
db_index
=
True
)
class
CourseEnrollment
(
models
.
Model
):
class
CourseEnrollment
(
models
.
Model
):
user
=
models
.
ForeignKey
(
User
)
user
=
models
.
ForeignKey
(
User
)
course_id
=
models
.
CharField
(
max_length
=
255
,
db_index
=
True
)
course_id
=
models
.
CharField
(
max_length
=
255
,
db_index
=
True
)
...
@@ -184,6 +184,16 @@ class CourseEnrollment(models.Model):
...
@@ -184,6 +184,16 @@ class CourseEnrollment(models.Model):
class
Meta
:
class
Meta
:
unique_together
=
((
'user'
,
'course_id'
),
)
unique_together
=
((
'user'
,
'course_id'
),
)
@receiver
(
post_save
,
sender
=
CourseEnrollment
)
def
assign_default_role
(
sender
,
instance
,
**
kwargs
):
if
instance
.
user
.
is_staff
:
role
=
Role
.
objects
.
get_or_create
(
course_id
=
instance
.
course_id
,
name
=
"Moderator"
)[
0
]
else
:
role
=
Role
.
objects
.
get_or_create
(
course_id
=
instance
.
course_id
,
name
=
"Student"
)[
0
]
logging
.
info
(
"assign_default_role: adding
%
s as
%
s"
%
(
instance
.
user
,
role
))
instance
.
user
.
roles
.
add
(
role
)
#cache_relation(User.profile)
#cache_relation(User.profile)
#### Helper methods for use from python manage.py shell.
#### Helper methods for use from python manage.py shell.
...
...
lms/djangoapps/django_comment_client/__init__.py
View file @
b229cfb8
# call some function from permissions so that the post_save hook is imported
from
permissions
import
assign_default_role
lms/djangoapps/django_comment_client/base/views.py
View file @
b229cfb8
...
@@ -51,7 +51,7 @@ def ajax_content_response(request, course_id, content, template_name):
...
@@ -51,7 +51,7 @@ def ajax_content_response(request, course_id, content, template_name):
'content'
:
content
,
'content'
:
content
,
}
}
html
=
render_to_string
(
template_name
,
context
)
html
=
render_to_string
(
template_name
,
context
)
user_info
=
cc
.
User
.
from_django_user
(
request
.
user
)
.
to_dict
()
user_info
=
cc
.
User
.
from_django_user
(
request
.
user
)
.
safe_attributes
()
annotated_content_info
=
utils
.
get_annotated_content_info
(
course_id
,
content
,
request
.
user
,
user_info
)
annotated_content_info
=
utils
.
get_annotated_content_info
(
course_id
,
content
,
request
.
user
,
user_info
)
return
JsonResponse
({
return
JsonResponse
({
'html'
:
html
,
'html'
:
html
,
...
...
lms/djangoapps/django_comment_client/forum/views.py
View file @
b229cfb8
...
@@ -64,7 +64,7 @@ def render_discussion(request, course_id, threads, *args, **kwargs):
...
@@ -64,7 +64,7 @@ def render_discussion(request, course_id, threads, *args, **kwargs):
'user'
:
(
lambda
:
reverse
(
'django_comment_client.forum.views.user_profile'
,
args
=
[
course_id
,
user_id
])),
'user'
:
(
lambda
:
reverse
(
'django_comment_client.forum.views.user_profile'
,
args
=
[
course_id
,
user_id
])),
}[
discussion_type
]()
}[
discussion_type
]()
user_info
=
cc
.
User
.
from_django_user
(
request
.
user
)
.
to_dict
()
user_info
=
cc
.
User
.
from_django_user
(
request
.
user
)
.
safe_attributes
()
def
infogetter
(
thread
):
def
infogetter
(
thread
):
return
utils
.
get_annotated_content_infos
(
course_id
,
thread
,
request
.
user
,
user_info
)
return
utils
.
get_annotated_content_infos
(
course_id
,
thread
,
request
.
user
,
user_info
)
...
@@ -176,7 +176,7 @@ def render_single_thread(request, discussion_id, course_id, thread_id):
...
@@ -176,7 +176,7 @@ def render_single_thread(request, discussion_id, course_id, thread_id):
thread
=
cc
.
Thread
.
find
(
thread_id
)
.
retrieve
(
recursive
=
True
)
.
to_dict
()
thread
=
cc
.
Thread
.
find
(
thread_id
)
.
retrieve
(
recursive
=
True
)
.
to_dict
()
user_info
=
cc
.
User
.
from_django_user
(
request
.
user
)
.
to_dict
()
user_info
=
cc
.
User
.
from_django_user
(
request
.
user
)
.
safe_attributes
()
annotated_content_info
=
utils
.
get_annotated_content_infos
(
course_id
,
thread
=
thread
,
user
=
request
.
user
,
user_info
=
user_info
)
annotated_content_info
=
utils
.
get_annotated_content_infos
(
course_id
,
thread
=
thread
,
user
=
request
.
user
,
user_info
=
user_info
)
...
@@ -194,7 +194,7 @@ def single_thread(request, course_id, discussion_id, thread_id):
...
@@ -194,7 +194,7 @@ def single_thread(request, course_id, discussion_id, thread_id):
if
request
.
is_ajax
():
if
request
.
is_ajax
():
user_info
=
cc
.
User
.
from_django_user
(
request
.
user
)
.
to_dict
()
user_info
=
cc
.
User
.
from_django_user
(
request
.
user
)
.
safe_attributes
()
thread
=
cc
.
Thread
.
find
(
thread_id
)
.
retrieve
(
recursive
=
True
)
thread
=
cc
.
Thread
.
find
(
thread_id
)
.
retrieve
(
recursive
=
True
)
annotated_content_info
=
utils
.
get_annotated_content_infos
(
course_id
,
thread
,
request
.
user
,
user_info
=
user_info
)
annotated_content_info
=
utils
.
get_annotated_content_infos
(
course_id
,
thread
,
request
.
user
,
user_info
=
user_info
)
context
=
{
'thread'
:
thread
.
to_dict
(),
'course_id'
:
course_id
}
context
=
{
'thread'
:
thread
.
to_dict
(),
'course_id'
:
course_id
}
...
...
lms/djangoapps/django_comment_client/management/commands/create_roles_for_existing.py
View file @
b229cfb8
...
@@ -6,9 +6,7 @@ Enrollments.
...
@@ -6,9 +6,7 @@ Enrollments.
"""
"""
from
django.core.management.base
import
BaseCommand
,
CommandError
from
django.core.management.base
import
BaseCommand
,
CommandError
from
student.models
import
CourseEnrollment
from
student.models
import
CourseEnrollment
,
assign_default_role
from
django_comment_client.permissions
import
assign_default_role
class
Command
(
BaseCommand
):
class
Command
(
BaseCommand
):
args
=
'course_id'
args
=
'course_id'
...
@@ -23,4 +21,4 @@ class Command(BaseCommand):
...
@@ -23,4 +21,4 @@ class Command(BaseCommand):
assign_default_role
(
None
,
enrollment
)
assign_default_role
(
None
,
enrollment
)
if
i
%
1000
==
0
:
if
i
%
1000
==
0
:
print
"{0}..."
.
format
(
i
),
print
"{0}..."
.
format
(
i
),
print
print
\ No newline at end of file
lms/djangoapps/django_comment_client/permissions.py
View file @
b229cfb8
import
comment_client
as
cc
from
.models
import
Role
,
Permission
from
.models
import
Role
,
Permission
from
django.contrib.auth.models
import
User
from
django.db.models.signals
import
post_save
from
django.db.models.signals
import
post_save
from
django.dispatch
import
receiver
from
django.dispatch
import
receiver
from
student.models
import
CourseEnrollment
from
student.models
import
CourseEnrollment
...
@@ -8,16 +9,6 @@ import logging
...
@@ -8,16 +9,6 @@ import logging
from
util.cache
import
cache
from
util.cache
import
cache
@receiver
(
post_save
,
sender
=
CourseEnrollment
)
def
assign_default_role
(
sender
,
instance
,
**
kwargs
):
if
instance
.
user
.
is_staff
:
role
=
Role
.
objects
.
get_or_create
(
course_id
=
instance
.
course_id
,
name
=
"Moderator"
)[
0
]
else
:
role
=
Role
.
objects
.
get_or_create
(
course_id
=
instance
.
course_id
,
name
=
"Student"
)[
0
]
logging
.
info
(
"assign_default_role: adding
%
s as
%
s"
%
(
instance
.
user
,
role
))
instance
.
user
.
roles
.
add
(
role
)
def
cached_has_permission
(
user
,
permission
,
course_id
=
None
):
def
cached_has_permission
(
user
,
permission
,
course_id
=
None
):
"""
"""
Call has_permission if it's not cached. A change in a user's role or
Call has_permission if it's not cached. A change in a user's role or
...
...
lms/lib/comment_client/user.py
View file @
b229cfb8
...
@@ -33,6 +33,16 @@ class User(models.Model):
...
@@ -33,6 +33,16 @@ class User(models.Model):
params
=
{
'source_type'
:
source
.
type
,
'source_id'
:
source
.
id
}
params
=
{
'source_type'
:
source
.
type
,
'source_id'
:
source
.
id
}
response
=
perform_request
(
'delete'
,
_url_for_subscription
(
self
.
id
),
params
)
response
=
perform_request
(
'delete'
,
_url_for_subscription
(
self
.
id
),
params
)
# TODO this is a hack to compensate for the fact that synchronization isn't
# happening properly.
def
safe_attributes
(
self
):
try
:
return
self
.
to_dict
()
except
:
self
.
save
()
self
.
_retrieve
()
return
self
.
to_dict
()
def
vote
(
self
,
voteable
,
value
):
def
vote
(
self
,
voteable
,
value
):
if
voteable
.
type
==
'thread'
:
if
voteable
.
type
==
'thread'
:
url
=
_url_for_vote_thread
(
voteable
.
id
)
url
=
_url_for_vote_thread
(
voteable
.
id
)
...
...
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