diff --git a/common/static/common/js/discussion/views/discussion_content_view.js b/common/static/common/js/discussion/views/discussion_content_view.js index 5876ee57c342..36ce1544769d 100644 --- a/common/static/common/js/discussion/views/discussion_content_view.js +++ b/common/static/common/js/discussion/views/discussion_content_view.js @@ -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'); diff --git a/common/static/common/js/discussion/views/discussion_thread_list_view.js b/common/static/common/js/discussion/views/discussion_thread_list_view.js index fc555efce692..b7a9795da38c 100644 --- a/common/static/common/js/discussion/views/discussion_thread_list_view.js +++ b/common/static/common/js/discussion/views/discussion_thread_list_view.js @@ -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, @@ -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'); diff --git a/common/static/common/js/discussion/views/discussion_thread_view.js b/common/static/common/js/discussion/views/discussion_thread_view.js index 041f68c9f0dd..fd3741487da9 100644 --- a/common/static/common/js/discussion/views/discussion_thread_view.js +++ b/common/static/common/js/discussion/views/discussion_thread_view.js @@ -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 }, diff --git a/common/static/common/js/discussion/views/thread_response_view.js b/common/static/common/js/discussion/views/thread_response_view.js index 077c6cdefdec..acd923781498 100644 --- a/common/static/common/js/discussion/views/thread_response_view.js +++ b/common/static/common/js/discussion/views/thread_response_view.js @@ -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' diff --git a/lms/djangoapps/django_comment_client/utils.py b/lms/djangoapps/django_comment_client/utils.py index 9c491798e759..037e8be8cc46 100644 --- a/lms/djangoapps/django_comment_client/utils.py +++ b/lms/djangoapps/django_comment_client/utils.py @@ -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)) diff --git a/lms/lib/comment_client/thread.py b/lms/lib/comment_client/thread.py index 2c859e36f560..7ad0dce43cc0 100644 --- a/lms/lib/comment_client/thread.py +++ b/lms/lib/comment_client/thread.py @@ -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 diff --git a/lms/lib/comment_client/user.py b/lms/lib/comment_client/user.py index b8c8b98ac9f6..c7cb54b5d351 100644 --- a/lms/lib/comment_client/user.py +++ b/lms/lib/comment_client/user.py @@ -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'] @@ -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): """