Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 22 additions & 22 deletions app/controllers/courses_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,8 @@ def handle_add_students
ActiveRecord::Base.transaction do
# Remove the leading 'S-' from student IDs if present
csv_obj.each do |row|
student_id = row['ID number']
row['ID number'] = student_id&.replace(student_id[2..]) if student_id&.start_with?('S-')
instid = row['ID number']
row['ID number'] = instid&.replace(instid[2..]) if instid&.start_with?('S-')
end

if @course.grouped
Expand Down Expand Up @@ -381,16 +381,16 @@ def create_db_entries_grouped(hash_map, parent_course, unregistered_students, re
new_user = User.find_by(email_address: group_member[:email_address], is_staff: false)

if new_user
new_user.update!(student_id: group_member[:student_id])
new_user.update!(instid: group_member[:instid])

registered_students.push(group_member[:email_address]) if new_user.enrolments.where(course: parent_course).empty?
else
new_user = User.create!(
email_address: group_member[:email_address],
username: group_member[:name],
name: group_member[:name],
password: SecureRandom.base64(24),
has_registered: false,
student_id: group_member[:student_id],
instid: group_member[:instid],
is_staff: false
)

Expand Down Expand Up @@ -463,16 +463,16 @@ def create_db_entries_solo(student_set, parent_course, unregistered_students, re
new_user = User.find_by(email_address: student[:email_address], is_staff: false)

if new_user
new_user.update!(student_id: student[:student_id])
new_user.update!(instid: student[:instid])

registered_students.push(student[:email_address]) if new_user.enrolments.where(course: parent_course).empty?
else
new_user = User.create!(
email_address: student[:email_address],
username: student[:name],
name: student[:name],
password: SecureRandom.base64(24),
has_registered: false,
student_id: student[:student_id],
instid: student[:instid],
is_staff: false
)

Expand Down Expand Up @@ -512,7 +512,7 @@ def create_lecturer_enrolments(lecturer_emails, parent_course, unregistered_lect
password: SecureRandom.base64(24),
has_registered: false,
is_staff: true,
username: "Lecturer-#{SecureRandom.hex(2)}"
name: "Lecturer-#{SecureRandom.hex(2)}"
)

new_otp_instance = Otp.create!(
Expand Down Expand Up @@ -562,7 +562,7 @@ def generate_csv_export
end

def build_csv_headers(template_fields)
headers = %w[Student_Name Student_ID Email_Address]
headers = %w[Student_Name instid Email_Address]
headers << 'Student Group' if @course.grouped?
headers += %w[Supervisor_Name Supervisor_Email_Address Project_Title Project_Status]

Expand All @@ -589,11 +589,11 @@ def build_group_rows(group, template_fields)
group.project_group_members.each do |member|
user = member.user
row = [
user.username || '',
user.student_id || '',
user.name || '',
user.instid || '',
user.email_address || '',
group.group_name || '',
supervisor&.username || '',
supervisor&.name || '',
supervisor&.email_address || '',
project&.current_title || '',
project_status.humanize
Expand All @@ -612,10 +612,10 @@ def build_student_rows(student, template_fields)
field_values = get_project_details_values(current_instance, template_fields)

row = [
student.username || '',
student.student_id || '',
student.name || '',
student.instid || '',
student.email_address || '',
supervisor&.username || '',
supervisor&.name || '',
supervisor&.email_address || '',
project&.current_title || '',
project_status.humanize
Expand Down Expand Up @@ -744,7 +744,7 @@ def search_groups(group_list, query)

group_name_match = group.group_name.downcase.include?(downcased_query)
member_match = group.project_group_members.any? do |member|
member.user.username.downcase.include?(downcased_query)
member.user.name.downcase.include?(downcased_query)
end
title_match = project&.current_title&.downcase&.include?(downcased_query) || false

Expand All @@ -758,8 +758,8 @@ def search_students(student_list, query)
student_list.select do |student|
project = participant_project(student, 'User')

name_match = student.username.downcase.include?(downcased_query)
id_match = student.student_id&.downcase&.include?(downcased_query) || false
name_match = student.name.downcase.include?(downcased_query)
id_match = student.instid&.downcase&.include?(downcased_query) || false
title_match = project&.current_title&.downcase&.include?(downcased_query) || false

name_match || id_match || title_match
Expand All @@ -782,7 +782,7 @@ def sort_value_for_group(group)
when 'project_title'
project&.current_title&.downcase || ''
when 'supervisor'
project&.supervisor&.username&.downcase || ''
project&.supervisor&.name&.downcase || ''
else
group.group_name.downcase
end
Expand All @@ -796,9 +796,9 @@ def sort_value_for_student(student)
when 'project_title'
project&.current_title&.downcase || ''
when 'supervisor'
project&.supervisor&.username&.downcase || ''
project&.supervisor&.name&.downcase || ''
else
student.username.downcase
student.name.downcase
end
end

Expand Down
10 changes: 5 additions & 5 deletions app/controllers/projects_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def change_status
GeneralMailer.with(
course: @course,
project: @project,
supervisor_username: Current.user.username
supervisor_name: Current.user.name
).Project_Status_Updated.deliver_later

redirect_to course_project_path(@course, @project), notice: "Status updated to #{new_status.humanize}."
Expand Down Expand Up @@ -197,8 +197,8 @@ def create

GeneralMailer.with(
email_address: @project.supervisor.email_address,
supervisor_username: @project.supervisor.username,
owner_name: @course.grouped? ? @project.owner.group_name : @project.owner.username,
supervisor_name: @project.supervisor.name,
owner_name: @course.grouped? ? @project.owner.group_name : @project.owner.name,
course: @course,
project: @project
).New_Student_Submission.deliver_later
Expand Down Expand Up @@ -297,8 +297,8 @@ def update

if previous_supervisor_id != @project.supervisor.id || new_instance_created
GeneralMailer.with(
supervisor_username: @project.supervisor.username,
owner_name: @course.grouped? ? @project.owner.group_name : @project.owner.username,
supervisor_name: @project.supervisor.name,
owner_name: @course.grouped? ? @project.owner.group_name : @project.owner.name,
course: @course,
project: @project
).New_Student_Submission.deliver_later
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/topics_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -188,11 +188,11 @@ def change_status
end

GeneralMailer.with(
username: @topic.owner.username,
name: @topic.owner.name,
email_address: @topic.owner.email_address,
course: @course,
topic: @topic,
supervisor_username: Current.user.username
supervisor_name: Current.user.name
).Topic_Status_Updated.deliver_later

redirect_to course_topic_path(@course, @topic), notice: 'Status updated.'
Expand Down
12 changes: 6 additions & 6 deletions app/controllers/user_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ def edit
return
end

if params[:user][:username].blank?
redirect_back_or_to '/', alert: 'Username cannot be empty'
if params[:user][:name].blank?
redirect_back_or_to '/', alert: 'Name cannot be empty'
return
end

Expand All @@ -56,7 +56,7 @@ def edit

begin
Current.user.update!(
username: params[:user][:username],
name: params[:user][:name],
web_link: params[:user][:web_link],
description: params[:user][:description]
)
Expand All @@ -71,7 +71,7 @@ def edit
end

def create
response = params.permit(:password, :password_confirmation, :username, :token, :otp)
response = params.permit(:password, :password_confirmation, :name, :token, :otp)
return if response[:token].blank?

if response[:otp].blank?
Expand Down Expand Up @@ -108,7 +108,7 @@ def create

user = otp_instance.user

if response[:username].blank? && user.is_staff
if response[:name].blank? && user.is_staff
redirect_back_or_to '/', alert: 'Name cannot be empty'
return
end
Expand All @@ -120,7 +120,7 @@ def create
else
redirect_back_or_to '/', alert: 'Something went wrong'
end
elsif user.update(has_registered: true, password: response[:password], username: response[:username].strip)
elsif user.update(has_registered: true, password: response[:password], name: response[:name].strip)
redirect_to '/session/new', notice: 'Account successfully claimed'
else
redirect_back_or_to '/', alert: 'Something went wrong'
Expand Down
4 changes: 2 additions & 2 deletions app/helpers/projects_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ def show_progress_tab?
@course.use_progress_updates && @current_instance.status == 'approved'
end

def username(user_id)
def name(user_id)
return nil unless user_id.present?

User.find_by(id: user_id)&.username
User.find_by(id: user_id)&.name
end
end
10 changes: 5 additions & 5 deletions app/mailers/general_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,29 +10,29 @@ def ProPro_Invite
def Project_Status_Updated
@course = params[:course]
@project = params[:project]
@supervisor_username = params[:supervisor_username]
@supervisor_name = params[:supervisor_name]

if @course.grouped?
emails = @project.owner.project_group_members.joins(:user).pluck('user.email_address')
@recipient = @project.owner.group_name
mail(to: emails, Subject: 'Status Updated')
else
@recipient = @project.owner.username
@recipient = @project.owner.name
mail(to: @project.owner.email_address, Subject: 'Status Updated')
end
end

def Topic_Status_Updated
@course = params[:course]
@topic = params[:topic]
@supervisor_username = params[:supervisor_username]
@supervisor_name = params[:supervisor_name]

@recipient = @topic.owner.username
@recipient = @topic.owner.name
mail(to: @topic.owner.email_address, Subject: 'Status Updated')
end

def New_Student_Submission
@supervisor_username = params[:supervisor_username]
@supervisor_name = params[:supervisor_name]
@owner_name = params[:owner_name]
@course = params[:course]
@project = params[:project]
Expand Down
4 changes: 2 additions & 2 deletions app/models/course.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def parse_csv_grouped(csv_obj)
ret[group] ||= Set[]
ret[group].add({
name: row['Last name'].strip,
student_id: row['ID number'].strip,
instid: row['ID number'].strip,
email_address: row['Email address'].strip
})
end
Expand All @@ -87,7 +87,7 @@ def parse_csv_solo(csv_obj)

ret.add({
name: row['Last name'].strip,
student_id: row['ID number'].strip,
instid: row['ID number'].strip,
email_address: row['Email address'].strip
})
end
Expand Down
2 changes: 1 addition & 1 deletion app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ class User < ApplicationRecord
has_many :sessions, dependent: :destroy

normalizes :email_address, with: ->(e) { e.strip.downcase }
normalizes :username, with: ->(n) { n.strip }
normalizes :name, with: ->(n) { n.strip }

has_many :enrolments, dependent: :destroy
has_many :courses, through: :enrolments
Expand Down
4 changes: 2 additions & 2 deletions app/views/courses/_copy_course_overlay.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@

<div class="pt-4 border-t border-gray-100 flex items-center gap-2">
<div class="w-6 h-6 rounded-full bg-gray-100 flex items-center justify-center text-xs font-bold text-gray-500">
<%= course_item.coordinators.first&.username&.first&.upcase || "?" %>
<%= course_item.coordinators.first&.name&.first&.upcase || "?" %>
</div>
<span class="text-xs font-medium text-gray-400">
Coordinator:
<span class="text-gray-600"><%= course_item.coordinators.first&.username || "None" %></span>
<span class="text-gray-600"><%= course_item.coordinators.first&.name || "None" %></span>
</span>
</div>
</div>
Expand Down
4 changes: 2 additions & 2 deletions app/views/courses/_course_card.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@

<div class="pt-4 border-t border-gray-100 flex items-center gap-2">
<div class="w-6 h-6 rounded-full bg-gray-100 flex items-center justify-center text-xs font-bold text-gray-500">
<%= course.coordinators.first&.username&.first&.upcase || "?" %>
<%= course.coordinators.first&.name&.first&.upcase || "?" %>
</div>
<span class="text-xs font-medium text-gray-400">
Coordinator: <span class="text-gray-600"><%= course.coordinators.first&.username || "None" %></span>
Coordinator: <span class="text-gray-600"><%= course.coordinators.first&.name || "None" %></span>
</span>
</div>
</div>
Expand Down
4 changes: 2 additions & 2 deletions app/views/courses/_lecturers.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
w-10 h-10 bg-[#d9d9d9] rounded-full shrink-0 flex justify-center items-center
text-[20px] text-gray-700 font-medium
">
<%= lecturer.username.first.upcase %>
<%= lecturer.name.first.upcase %>
</div>

<div class="flex-1 min-w-0">

<div class="flex items-center gap-[30px] mb-1 text-sm font-bold">
<div class="text-[#454343] text-base truncate">
<%= lecturer.username %>
<%= lecturer.name %>
</div>

<% capacity_info = @lecturer_capacity_info[lecturer.id] %>
Expand Down
2 changes: 1 addition & 1 deletion app/views/courses/_participants.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@
<option
value="<%= lecturer.id %>"
<%= 'selected' if params[:lecturer_filter] == lecturer.id.to_s %>
><%= lecturer.username %></option>
><%= lecturer.name %></option>
<% end %>
</select>

Expand Down
Loading
Loading