Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add mononym support #1580

Merged
merged 11 commits into from
Aug 30, 2022
3 changes: 2 additions & 1 deletion app/assets/javascripts/watchlist.js
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,8 @@ function get_watchlist_function(){
var id = _.get(watchlist_instance,'id');
var course_id = _.get(watchlist_instance,'course_id');
var user_id = _.get(watchlist_instance,'course_user_datum_id');
var user_name = _.get(data,`["users"][${user_id}].first_name`) + " " + _.get(data,`["users"][${user_id}].last_name`);
// https://stackoverflow.com/questions/19902860/join-strings-with-a-delimiter-only-if-strings-are-not-null-or-empty
var user_name = [_.get(data,`["users"][${user_id}].first_name`), _.get(data,`["users"][${user_id}].last_name`)].filter(Boolean).join(' ');
var user_email = _.get(data,`["users"][${user_id}].email`);
var risk_condition_id = _.get(watchlist_instance,'risk_condition_id');
var watchlist_status = _.get(watchlist_instance,'status');
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/assessment/grading.rb
Original file line number Diff line number Diff line change
Expand Up @@ -293,11 +293,11 @@ def score_grader_info
grader = (if score then score.grader else nil end)
grader_info = ""
if grader
grader_info = "#{grader.first_name} #{grader.last_name} (#{grader.email})"
grader_info = grader.full_name_with_email
end

feedback = score.feedback
response = {"grader" => grader_info, "feedback" => feedback, "score" => score.score}
response = { "grader" => grader_info, "feedback" => feedback, "score" => score.score }
render json: response
end

Expand Down
2 changes: 1 addition & 1 deletion app/controllers/courses_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ def upload_roster
if params[:doIt]
begin
save_uploaded_roster
flash[:success] = "Success!"
flash.now[:success] = "Successfully updated roster!"
rescue StandardError => e
if e != "Roster validation error"
flash[:error] = e
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/scoreboards_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def show
@grades[uid] = {}
@grades[uid][:nickname] = user.nickname
@grades[uid][:andrewID] = user.email
@grades[uid][:fullName] = "#{user.first_name} #{user.last_name}"
@grades[uid][:fullName] = user.full_name
@grades[uid][:problems] = {}
end
if @grades[uid][:version] != row["version"]
Expand Down
15 changes: 12 additions & 3 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ class User < ApplicationRecord
has_one :github_integration

trim_field :school
validates :first_name, :last_name, :email, presence: true
validates :email, presence: true
validate :first_or_last_name

# check if user is instructor in any course
def instructor?
Expand All @@ -41,15 +42,15 @@ def instructor_of?(user)
end

def full_name
"#{first_name} #{last_name}"
[first_name, last_name].reject(&:empty?).join(' ')
end

def full_name_with_email
"#{full_name} (#{email})"
end

def display_name
first_name && last_name ? full_name : email
first_name.present? && last_name.present? ? full_name : email
end

def after_create
Expand Down Expand Up @@ -261,4 +262,12 @@ def self.ldap_lookup(andrew_id)

result
end

private

def first_or_last_name
return if first_name.present? || last_name.present?

errors.add(:base, "Student first name and last name can't both be blank")
end
end
2 changes: 1 addition & 1 deletion app/views/assessments/viewGradesheet.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
<% for s in @submissions do %>
{ "id": "",
"name": {
name: "<%= s.course_user_datum.last_name %>, <%= s.course_user_datum.first_name %>",
name: "<%= [s.course_user_datum.last_name, s.course_user_datum.first_name].reject(&:blank?).join(', ') %>",
email: "<%= s.course_user_datum.email %>"
},
"lec": "<%= s.course_user_datum.lecture %>",
Expand Down
2 changes: 1 addition & 1 deletion app/views/course_user_data/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<h3>Account Details for <%= @user.andrewID %></h3>
<table class="noStyle" >
<tr><td>Name</td><td><td> <%= @user.first_name %> <%= @user.last_name %> </td></tr>
<tr><td>Name</td><td><td> <%= @user.full_name %> </td></tr>
<tr><td class="noStyle" >First Name</td><td class="noStyle"><%= @user.first_name %></td></tr>
<tr><td class="noStyle" >Last Name</td><td class="noStyle"><%= @user.last_name %></td></tr>
<tr><td class="noStyle" >andrewID</td><td class="noStyle"><%= @user.andrewID %></td></tr>
Expand Down
4 changes: 2 additions & 2 deletions app/views/course_user_data/show.html.erb
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<h2><%= @requestedUser.first_name %> <%= @requestedUser.last_name %> (<%= @requestedUser.nickname %>)</h2>
<h2><%= @requestedUser.full_name %> (<%= @requestedUser.nickname %>)</h2>
<ul class="gray-box">
<li><b>Contact</b><br>
<a href="mailto:<%= @requestedUser.email %>"><%= @requestedUser.email %></a></li>
<li> <b>About</b><br>
<li><b>About</b><br>
Lecture <strong><%= @requestedUser.lecture %></strong><br>
Section <strong><%= @requestedUser.section %></strong><br>
Course <strong><%= @requestedUser.course.full_name %></strong><br>
Expand Down
4 changes: 2 additions & 2 deletions app/views/course_user_data/user.html.erb
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<h2><%= @requestedUser.first_name %> <%= @requestedUser.last_name %> (<%= @requestedUser.nickname %>)</h2>
<h2><%= @requestedUser.full_name %> (<%= @requestedUser.nickname %>)</h2>
<ul class="gray-box">
<li><b>Contact</b><br>
<%= @requestedUser.andrewID %> (andrewid)<br>
<a href="mailto:<%= @requestedUser.email %>"><%= @requestedUser.email %></a></li>
<li> <b>About</b><br>
<li><b>About</b><br>
Lecture <strong><%= @requestedUser.lecture %></strong><br>
Section <strong><%= @requestedUser.section %></strong><br>
Course <strong><%= @requestedUser.course.display_name %></strong><br>
Expand Down
2 changes: 1 addition & 1 deletion app/views/submissions/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@
</label>
</p>
</td>
<td><%= "#{submission.course_user_datum.last_name}, #{submission.course_user_datum.first_name}" %>
<td><%= [submission.course_user_datum.last_name, submission.course_user_datum.first_name].reject(&:blank?).join(', ') %>
<%= link_to submission.course_user_datum.email,
history_course_assessment_path(@course, @assessment, cud_id: submission.course_user_datum_id, partial: true),
{remote: true, class: :trigger}
Expand Down
14 changes: 12 additions & 2 deletions app/views/users/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,18 @@
<a href="mailto:<%= @user.email %>"><%= @user.email %></a>
</li>
<li> <b>About</b><br>
First name <strong><%= @user.first_name %></strong><br>
Last name <strong><%= @user.last_name %></strong><br>
<% if @user.first_name.present? %>
First name: <strong><%= @user.first_name %></strong>
<% else %>
First name: (student has no first name)
<% end %>
<br>
<% if @user.last_name.present? %>
Last name: <strong><%= @user.last_name %></strong>
<% else %>
Last name: (student has no last name)
<% end %>
<br>
Courses
<% if @cuds.empty? %>
<strong> None </strong>
Expand Down