Skip to content

Commit

Permalink
MCKIN-10967 Update username in discussion. (openedx#1508)
Browse files Browse the repository at this point in the history
  • Loading branch information
attiyaIshaque authored and naeem91 committed Jun 20, 2019
1 parent bf8d9af commit 2ded7fa
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -494,13 +494,25 @@

DiscussionContentShowView.prototype.getAuthorDisplay = function() {
return _.template($('#post-user-display-template').html())({
username: this.model.get('username') || null,
username: this.getDisplayName(),
user_url: this.model.get('user_url'),
is_community_ta: this.model.get('community_ta_authored'),
is_staff: this.model.get('staff_authored')
});
};

DiscussionContentShowView.prototype.getDisplayName = function() {
var firstName, lastName, displayName;
firstName = this.model.get('first_name');
lastName = this.model.get('last_name');
if (typeof firstName === 'undefined' || typeof lastName === 'undefined') {
displayName = this.model.get('username');
} else {
displayName = firstName + ' ' + lastName[0];
}
return displayName;
};

DiscussionContentShowView.prototype.getEndorserDisplay = function() {
var endorsement;
endorsement = this.model.get('endorsement');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,7 @@
};

DiscussionThreadListView.prototype.renderThread = function(thread) {
this.getUserName(thread);
var threadCommentCount = thread.get('comments_count'),
threadUnreadCommentCount = thread.get('unread_comments_count'),
neverRead = !thread.get('read') && threadUnreadCommentCount === threadCommentCount,
Expand All @@ -369,6 +370,15 @@
return $(this.threadListItemTemplate(context).toString());
};

DiscussionThreadListView.prototype.getUserName = function(thread) {
var firstName, lastName, displayName;
firstName = thread.get('first_name');
lastName = thread.get('last_name');
if (typeof firstName !== 'undefined' && typeof lastName !== 'undefined') {
displayName = firstName + ' ' + lastName[0];
thread.set('username', displayName);
}
};
DiscussionThreadListView.prototype.threadSelected = function(e) {
var threadId;
threadId = $(e.target).closest('.forum-nav-thread').attr('data-id');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,8 @@
body: body,
created_at: (new Date()).toISOString(),
username: window.user.get('username'),
first_name: window.user.get('first_name'),
last_name: window.user.get('last_name'),
votes: {
up_count: 0
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,8 @@
body: body,
created_at: (new Date()).toISOString(),
username: window.user.get('username'),
first_name: window.user.get('first_name'),
last_name: window.user.get('last_name'),
abuse_flaggers: [],
user_id: window.user.get('id'),
id: 'unsaved'
Expand Down
2 changes: 1 addition & 1 deletion lms/djangoapps/django_comment_client/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -688,7 +688,7 @@ def prepare_content(content, course_key, is_staff=False, discussion_division_ena
]

if (content.get('anonymous') is False) and ((content.get('anonymous_to_peers') is False) or is_staff):
fields += ['username', 'user_id']
fields += ['username', 'user_id', 'first_name', 'last_name']

content = strip_none(extract(content, fields))

Expand Down
6 changes: 4 additions & 2 deletions lms/lib/comment_client/thread.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,15 @@ class Thread(models.Model):
'highlighted_body', 'endorsed', 'read', 'group_id', 'group_name', 'pinned',
'abuse_flaggers', 'resp_skip', 'resp_limit', 'resp_total', 'thread_type',
'endorsed_responses', 'non_endorsed_responses', 'non_endorsed_resp_total',
'context', 'last_activity_at',
'context', 'last_activity_at', 'first_name', 'last_name'
]

# updateable_fields are sent in PUT requests
updatable_fields = [
'title', 'body', 'anonymous', 'anonymous_to_peers', 'course_id', 'read',
'closed', 'user_id', 'commentable_id', 'group_id', 'group_name', 'pinned', 'thread_type'
'closed', 'user_id', 'commentable_id', 'group_id', 'group_name', 'pinned', 'thread_type',
'first_name', 'last_name'

]

# metric_tag_fields are used by Datadog to record metrics about the model
Expand Down
8 changes: 5 additions & 3 deletions lms/lib/comment_client/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ class User(models.Model):
'id', 'external_id', 'subscribed_user_ids', 'children', 'course_id',
'group_id', 'subscribed_thread_ids', 'subscribed_commentable_ids',
'subscribed_course_ids', 'threads_count', 'comments_count',
'default_sort_key'
'default_sort_key', "first_name", "last_name"
]

updatable_fields = ['username', 'external_id', 'default_sort_key']
updatable_fields = ['username', 'external_id', 'default_sort_key', 'first_name', 'last_name']
initializable_fields = updatable_fields

metric_tag_fields = ['course_id']
Expand All @@ -31,7 +31,9 @@ class User(models.Model):
def from_django_user(cls, user):
return cls(id=str(user.id),
external_id=str(user.id),
username=user.username)
username=user.username,
first_name=user.first_name,
last_name=user.last_name)

def read(self, source):
"""
Expand Down

0 comments on commit 2ded7fa

Please sign in to comment.