Skip to content

Commit

Permalink
Merge pull request #9 from brwali/development/E2458
Browse files Browse the repository at this point in the history
Completion of E2458- refactor fullname to name, name to username, and paginate all users option
  • Loading branch information
mhpatel4 authored Oct 29, 2024
2 parents d0e73f1 + 5b0d2ec commit f466be4
Show file tree
Hide file tree
Showing 243 changed files with 1,008 additions and 967 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ after_script:
- ls -lah coverage/
- cd $HOME
- git config --global user.email "[email protected]"
- git config --global user.name "Winbobob"
- git config --global user.username "Winbobob"
- git clone --quiet https://[email protected]/expertiza/$REPORT_REPO_NAME.git
- cd $REPORT_REPO_NAME
- if [ ! -d "./$TRAVIS_PULL_REQUEST" ]; then mkdir $TRAVIS_PULL_REQUEST; fi
Expand Down
22 changes: 11 additions & 11 deletions app/controllers/account_request_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def create_approved_user
if requested_user.status.nil?
flash[:error] = 'Please Approve or Reject before submitting'
elsif requested_user.update_attributes(requested_user_params)
flash[:success] = "The user \"#{requested_user.name}\" has been successfully updated."
flash[:success] = "The user \"#{requested_user.username}\" has been successfully updated."
end
# If the users request is approved, they are stored as a user in the database
if requested_user.status == 'Approved'
Expand All @@ -47,7 +47,7 @@ def create_approved_user
elsif requested_user.status == 'Rejected'
# If the user request has been rejected, a flash message is shown and redirected to review page
if requested_user.update_columns(status: is_approved)
flash[:success] = "The user \"#{requested_user.name}\" has been Rejected."
flash[:success] = "The user \"#{requested_user.username}\" has been Rejected."
# redirect_to action: 'list_pending_requested'
# return
else
Expand All @@ -61,10 +61,10 @@ def create_approved_user
# Creates a new user if their request is approved
def user_new(requested_user)
new_user = User.new
new_user.name = requested_user.name
new_user.username = requested_user.username
new_user.role_id = requested_user.role_id
new_user.institution_id = requested_user.institution_id
new_user.fullname = requested_user.fullname
new_user.name = requested_user.name
new_user.email = requested_user.email
new_user.parent_id = session[:user].id
new_user.timezonepref = User.find_by(id: new_user.parent_id).timezonepref
Expand All @@ -75,7 +75,7 @@ def user_new(requested_user)
prepared_mail = MailerHelper.send_mail_to_user(new_user, 'Your Expertiza account and password have been created.', 'user_welcome', password)
prepared_mail.deliver_now
flash[:success] = "A new password has been sent to new user's e-mail address."
undo_link("The user \"#{requested_user.name}\" has been successfully created. ")
undo_link("The user \"#{requested_user.username}\" has been successfully created. ")
else
foreign
end
Expand Down Expand Up @@ -108,7 +108,7 @@ def list_pending_requested
def create_requested_user_record
requested_user = AccountRequest.new(requested_user_params)
# An object is created with respect to AccountRequest model inorder to populate the users information when account is requested
(user_exists = User.find_by(name: requested_user.name)) || User.find_by(name: requested_user.email)
(user_exists = User.find_by(username: requested_user.username)) || User.find_by(username: requested_user.email)
requested_user_saved = save_requested_user(requested_user, params)
# Stores a boolean value with respect to whether the user data is saved or not
if !user_exists && requested_user_saved
Expand All @@ -122,7 +122,7 @@ def create_requested_user_record
flash[:error] = requested_user.errors.full_messages.to_sentence
# If saving in the AccountRequests model has failed
end
ExpertizaLogger.error LoggerMessage.new(controller_name, requested_user.name, flash[:error], request)
ExpertizaLogger.error LoggerMessage.new(controller_name, requested_user.username, flash[:error], request)
redirect_to controller: 'account_request', action: 'new', role: 'Student'
# if the first if clause fails, redirect back to the account requests page!
end
Expand All @@ -148,12 +148,12 @@ def save_requested_user(requested_user, params)
def notify_supers_new_request(requested_user)
super_users = User.joins(:role).where('roles.name = ?', 'Super-Administrator')
super_users.each do |super_user|
prepared_mail = MailerHelper.send_mail_to_all_super_users(super_user, requested_user, 'New Account Request: ' + requested_user.fullname)
prepared_mail = MailerHelper.send_mail_to_all_super_users(super_user, requested_user, 'New Account Request: ' + requested_user.name)
prepared_mail.deliver
end
# Notifying an email to the administrator regarding the new user request!
ExpertizaLogger.info LoggerMessage.new(controller_name, requested_user.name, 'The account you are requesting has been created successfully.', request)
flash[:success] = "User signup for \"#{requested_user.name}\" has been successfully requested."
ExpertizaLogger.info LoggerMessage.new(controller_name, requested_user.username, 'The account you are requesting has been created successfully.', request)
flash[:success] = "User signup for \"#{requested_user.username}\" has been successfully requested."
# Print out the acknowledgement message to the user and redirect to /instructors/home page when successful
end

Expand All @@ -163,7 +163,7 @@ def roles_for_request_sign_up
end

def requested_user_params
params.require(:user).permit(:name, :role_id, :fullname, :institution_id, :email)
params.require(:user).permit(:username, :role_id, :name, :institution_id, :email)
.merge(self_introduction: params[:requested_user][:self_introduction])
end
end
4 changes: 2 additions & 2 deletions app/controllers/admin_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def show_super_administrator
end

def list_administrators
@users = User.admins.order(:name).where('parent_id = ?', current_user.id).paginate(page: params[:page], per_page: 50)
@users = User.admins.order(:username).where('parent_id = ?', current_user.id).paginate(page: params[:page], per_page: 50)
end

def show_administrator
Expand All @@ -31,7 +31,7 @@ def show_administrator
end

def list_instructors
@users = User.instructors.order(:name).where('parent_id = ?', current_user.id).paginate(page: params[:page], per_page: 50)
@users = User.instructors.order(:username).where('parent_id = ?', current_user.id).paginate(page: params[:page], per_page: 50)
end

def show_instructor
Expand Down
10 changes: 5 additions & 5 deletions app/controllers/advertise_for_partner_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def create
team = AssignmentTeam.find_by(id: params[:id])
team.update_attributes(advertise_for_partner: true, comments_for_advertisement: params[:comments_for_advertisement])
participant = AssignmentParticipant.find_by(parent_id: team.assignment.id, user_id: session[:user].id)
ExpertizaLogger.info LoggerMessage.new(controller_name, session[:user].name, 'Your advertisement has been successfully created.', request)
ExpertizaLogger.info LoggerMessage.new(controller_name, session[:user].username, 'Your advertisement has been successfully created.', request)
redirect_to view_student_teams_path student_id: participant.id
end

Expand All @@ -41,11 +41,11 @@ def update
@team.update_attributes(comments_for_advertisement: params[:comments_for_advertisement])
participant = AssignmentParticipant.find_by(parent_id: @team.assignment.id, user_id: session[:user].id)
rescue StandardError
ExpertizaLogger.error LoggerMessage.new(controller_name, session[:user].name, 'An error occurred and your advertisement was not updated.', request)
ExpertizaLogger.error LoggerMessage.new(controller_name, session[:user].username, 'An error occurred and your advertisement was not updated.', request)
flash[:error] = 'An error occurred and your advertisement was not updated!'
render action: 'edit'
else
ExpertizaLogger.info LoggerMessage.new(controller_name, session[:user].name, 'Your advertisement has been successfully updated.', request)
ExpertizaLogger.info LoggerMessage.new(controller_name, session[:user].username, 'Your advertisement has been successfully updated.', request)
flash[:success] = 'Your advertisement was successfully updated!'
redirect_to view_student_teams_path student_id: participant.id
end
Expand All @@ -55,11 +55,11 @@ def remove
team.update_attributes(advertise_for_partner: false, comments_for_advertisement: nil)
participant = AssignmentParticipant.find_by(parent_id: team.assignment.id, user_id: session[:user].id)
rescue StandardError
ExpertizaLogger.error LoggerMessage.new(controller_name, session[:user].name, 'An error occurred and your advertisement was not removed', request)
ExpertizaLogger.error LoggerMessage.new(controller_name, session[:user].username, 'An error occurred and your advertisement was not removed', request)
flash[:error] = 'An error occurred and your advertisement was not removed!'
redirect_back fallback_location: root_path
else
ExpertizaLogger.info LoggerMessage.new(controller_name, session[:user].name, 'Your advertisement has been successfully removed.', request)
ExpertizaLogger.info LoggerMessage.new(controller_name, session[:user].username, 'Your advertisement has been successfully removed.', request)
flash[:success] = 'Your advertisement was successfully removed!'
redirect_to view_student_teams_path student_id: participant.id
end
Expand Down
14 changes: 7 additions & 7 deletions app/controllers/assignments_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -150,10 +150,10 @@ def delete
# FixB : Instrucor will be able to delete any assignment belonging to his/her courses.
if (user.role.name == 'Instructor') || ((user.role.name == 'Teaching Assistant') && (user.id == assignment_form.assignment.instructor_id))
assignment_form.delete(params[:force])
ExpertizaLogger.info LoggerMessage.new(controller_name, session[:user].name, "Assignment #{assignment_form.assignment.id} was deleted.", request)
ExpertizaLogger.info LoggerMessage.new(controller_name, session[:user].username, "Assignment #{assignment_form.assignment.id} was deleted.", request)
flash[:success] = 'The assignment was successfully deleted.'
else
ExpertizaLogger.info LoggerMessage.new(controller_name, session[:user].name, 'You are not authorized to delete this assignment.', request)
ExpertizaLogger.info LoggerMessage.new(controller_name, session[:user].username, 'You are not authorized to delete this assignment.', request)
flash[:error] = 'You are not authorized to delete this assignment.'
end
rescue StandardError => e
Expand Down Expand Up @@ -410,7 +410,7 @@ def check_questionnaires_usage
def unassigned_rubrics_warning
if !list_unassigned_rubrics.empty? && request.original_fullpath == "/assignments/#{@assignment_form.assignment.id}/edit"
rubrics_needed = needed_rubrics(list_unassigned_rubrics)
ExpertizaLogger.error LoggerMessage.new(controller_name, session[:user].name, "Rubrics missing for #{@assignment_form.assignment.name}.", request)
ExpertizaLogger.error LoggerMessage.new(controller_name, session[:user].username, "Rubrics missing for #{@assignment_form.assignment.name}.", request)
if flash.now[:error] != 'Failed to save the assignment: ["Total weight of rubrics should add up to either 0 or 100%"]'
flash.now[:error] = 'You did not specify all the necessary rubrics. You need ' + rubrics_needed +
" of assignment <b>#{@assignment_form.assignment.name}</b> before saving the assignment. You can assign rubrics" \
Expand Down Expand Up @@ -445,7 +445,7 @@ def update_assignment_badges

# flash notice if the time zone is not specified for an assignment's due date
def user_timezone_specified
ExpertizaLogger.error LoggerMessage.new(controller_name, session[:user].name, 'Timezone not specified', request) if current_user.timezonepref.nil?
ExpertizaLogger.error LoggerMessage.new(controller_name, session[:user].username, 'Timezone not specified', request) if current_user.timezonepref.nil?
flash.now[:error] = 'You have not specified your preferred timezone yet. Please do this before you set up the deadlines.' if current_user.timezonepref.nil?
end

Expand All @@ -457,11 +457,11 @@ def key_nonexistent_handler
@assignment.course_id = params[:course_id]

if @assignment.save
ExpertizaLogger.info LoggerMessage.new(controller_name, session[:user].name, "The assignment was successfully saved: #{@assignment.as_json}", request)
ExpertizaLogger.info LoggerMessage.new(controller_name, session[:user].username, "The assignment was successfully saved: #{@assignment.as_json}", request)
flash[:note] = 'The assignment was successfully saved.'
redirect_to list_tree_display_index_path
else
ExpertizaLogger.error LoggerMessage.new(controller_name, session[:user].name, "Failed assignment: #{@assignment.errors.full_messages.join(' ')}", request)
ExpertizaLogger.error LoggerMessage.new(controller_name, session[:user].username, "Failed assignment: #{@assignment.errors.full_messages.join(' ')}", request)
flash[:error] = "Failed to save the assignment: #{@assignment.errors.full_messages.join(' ')}"
redirect_to edit_assignment_path @assignment.id
end
Expand Down Expand Up @@ -501,7 +501,7 @@ def update_feedback_attributes
else
flash[:error] = "Failed to save the assignment: #{@assignment_form.errors}"
end
ExpertizaLogger.info LoggerMessage.new('', session[:user].name, "The assignment was saved: #{@assignment_form.as_json}", request)
ExpertizaLogger.info LoggerMessage.new('', session[:user].username, "The assignment was saved: #{@assignment_form.as_json}", request)
end

def query_participants_and_alert
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/auth_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def login
if request.get?
AuthController.clear_session(session)
else
user = User.find_by_login(params[:login][:name])
user = User.find_by_login(params[:login][:username])
if user && user.valid_password?(params[:login][:password])
after_login(user)
else
Expand All @@ -34,7 +34,7 @@ def login
def after_login(user)
session[:user] = user
session[:impersonate] = false
ExpertizaLogger.info LoggerMessage.new('', user.name, 'Login successful')
ExpertizaLogger.info LoggerMessage.new('', user.username, 'Login successful')
AuthController.set_current_role(user.role_id, session)
redirect_to controller: AuthHelper.get_home_controller(session[:user]),
action: AuthHelper.get_home_action(session[:user])
Expand Down
8 changes: 4 additions & 4 deletions app/controllers/bookmarks_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ def create
params[:url] = params[:url].gsub!(%r{https://}, '') if params[:url].start_with?('https://')
begin
Bookmark.create(url: create_bookmark_params[:url], title: create_bookmark_params[:title], description: create_bookmark_params[:description], user_id: session[:user].id, topic_id: create_bookmark_params[:topic_id])
ExpertizaLogger.info LoggerMessage.new(controller_name, session[:user].name, 'Your bookmark has been successfully created!', request)
ExpertizaLogger.info LoggerMessage.new(controller_name, session[:user].username, 'Your bookmark has been successfully created!', request)
flash[:success] = 'Your bookmark has been successfully created!'
rescue StandardError
ExpertizaLogger.info LoggerMessage.new(controller_name, session[:user].name, $ERROR_INFO, request)
ExpertizaLogger.info LoggerMessage.new(controller_name, session[:user].username, $ERROR_INFO, request)
flash[:error] = $ERROR_INFO
end
redirect_to action: 'list', id: params[:topic_id]
Expand All @@ -48,15 +48,15 @@ def edit
def update
@bookmark = Bookmark.find(params[:id])
@bookmark.update_attributes(url: update_bookmark_params[:bookmark][:url], title: update_bookmark_params[:bookmark][:title], description: update_bookmark_params[:bookmark][:description])
ExpertizaLogger.info LoggerMessage.new(controller_name, session[:user].name, 'Your bookmark has been successfully updated!', request)
ExpertizaLogger.info LoggerMessage.new(controller_name, session[:user].username, 'Your bookmark has been successfully updated!', request)
flash[:success] = 'Your bookmark has been successfully updated!'
redirect_to action: 'list', id: @bookmark.topic_id
end

def destroy
@bookmark = Bookmark.find(params[:id])
@bookmark.destroy
ExpertizaLogger.info LoggerMessage.new(controller_name, session[:user].name, 'Your bookmark has been successfully deleted!', request)
ExpertizaLogger.info LoggerMessage.new(controller_name, session[:user].username, 'Your bookmark has been successfully deleted!', request)
flash[:success] = 'Your bookmark has been successfully deleted!'
redirect_to action: 'list', id: @bookmark.topic_id
end
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/conference_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@ def create

def add_conference_user
# check if user is already present with given username in system
existing_user = User.find_by(name: params[:user][:name])
existing_user = User.find_by(username: params[:user][:username])
# if user exist then add user as participant to assignment else create account and then add as participant
if existing_user.nil?
if !User.find_by(email: params[:user][:email]).nil? || (params[:user][:name].nil? || params[:user][:name].empty?)
if !User.find_by(email: params[:user][:email]).nil? || (params[:user][:username].nil? || params[:user][:username].empty?)
flash[:error] = 'A user with username of this email already exists, Please provide a unique email to continue.'
# redirect_to request.referrer
return false
Expand Down
14 changes: 7 additions & 7 deletions app/controllers/courses_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ def action_allowed?
end

def auto_complete_for_user_name
search = params[:user][:name].to_s
search = params[:user][:username].to_s
@users = User.where(role_id: 6) if search.present?
render inline: "<%= auto_complete_result @users, 'name' %>", layout: false
render inline: "<%= auto_complete_result @users, 'username' %>", layout: false
end

# Creates a new course
Expand Down Expand Up @@ -121,18 +121,18 @@ def view_teaching_assistants
# Adds a teaching assistant to a course
def add_ta
@course = Course.find(params[:course_id])
@user = User.find_by(name: params[:user][:name])
@user = User.find_by(username: params[:user][:username])
if @user.nil?
flash.now[:error] = 'The user inputted "' + params[:user][:name] + '" does not exist.'
flash.now[:error] = 'The user inputted "' + params[:user][:username] + '" does not exist.'
elsif !TaMapping.where(ta_id: @user.id, course_id: @course.id).empty?
flash.now[:error] = 'The user inputted "' + params[:user][:name] + '" is already a TA for this course.'
flash.now[:error] = 'The user inputted "' + params[:user][:username] + '" is already a TA for this course.'
else
@ta_mapping = TaMapping.create(ta_id: @user.id, course_id: @course.id)
@user.role = Role.find_by name: 'Teaching Assistant'
@user.save

@course = @ta_mapping
undo_link("The TA \"#{@user.name}\" has been successfully added.")
undo_link("The TA \"#{@user.username}\" has been successfully added.")
end
render action: 'add_ta.js.erb', layout: false
end
Expand All @@ -151,7 +151,7 @@ def remove_ta
@ta_mapping.destroy

@course = @ta_mapping
undo_link("The TA \"#{@ta.name}\" has been successfully removed.")
undo_link("The TA \"#{@ta.username}\" has been successfully removed.")

render action: 'remove_ta.js.erb', layout: false
end
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/export_file_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def export_advices
end

def export_tags
@user_ids = User.where('name IN (?)', params[:names])
@user_ids = User.where('username IN (?)', params[:names])
@students = AnswerTag.select('answers.*, answer_tags.*').joins(:answer).where('answer_tags.answer_id = answers.id and answer_tags.user_id IN (?)', @user_ids.pluck(:id))
attributes = %w[user_id tag_prompt_deployment_id comments value]

Expand Down
4 changes: 2 additions & 2 deletions app/controllers/grades_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,9 @@ def update
unless format('%.2f', total_score) == params[:participant][:grade]
participant.update_attribute(:grade, params[:participant][:grade])
message = if participant.grade.nil?
'The computed score will be used for ' + participant.user.name + '.'
'The computed score will be used for ' + participant.user.username + '.'
else
'A score of ' + params[:participant][:grade] + '% has been saved for ' + participant.user.name + '.'
'A score of ' + params[:participant][:grade] + '% has been saved for ' + participant.user.username + '.'
end
end
flash[:note] = message
Expand Down
Loading

0 comments on commit f466be4

Please sign in to comment.