Skip to content

Commit

Permalink
chore: fixed more incorrect switches
Browse files Browse the repository at this point in the history
  • Loading branch information
brwali committed Oct 27, 2024
1 parent 8cd6a61 commit 562e78e
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 16 deletions.
16 changes: 8 additions & 8 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,7 +61,7 @@ def create_approved_user
# Creates a new user if their request is approved
def user_new(requested_user)
new_user = User.new
new_user.username = 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
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(username: requested_user.name)) || User.find_by(username: 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 Down Expand Up @@ -152,8 +152,8 @@ def notify_supers_new_request(requested_user)
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 Down
2 changes: 1 addition & 1 deletion app/controllers/impersonate_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def check_if_input_is_valid
if params[:user] && warn_for_special_chars(params[:user][:username], 'Username')
flash[:error] = 'Please enter valid user name'
redirect_back fallback_location: root_path
elsif params[:impersonate] && warn_for_special_chars(params[:impersonate][:username], 'Username')
elsif params[:impersonate] && warn_for_special_chars(params[:impersonate][:name], 'Username')
flash[:error] = 'Please enter valid user name'
redirect_back fallback_location: root_path
end
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/invitations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def create_utility

def check_user_before_invitation
# user is the student you are inviting to your team
@user = User.find_by(username: params[:user][:username].strip)
@user = User.find_by(username: params[:user][:name].strip)
# User/Author has information about the participant
@student = AssignmentParticipant.find(params[:student_id])
@assignment = Assignment.find(@student.parent_id)
Expand Down
6 changes: 3 additions & 3 deletions app/helpers/conference_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def get_redirect_url_link
end

def create_author
params[:user][:username] = params[:user][:email] unless !params[:user][:username].nil? && !params[:user][:username].empty?
params[:user][:name] = params[:user][:email] unless !params[:user][:name].nil? && !params[:user][:name].empty?
is_author = true
# Assign all user params for creating author using assign_user_params function
@user = assign_user_params(is_author)
Expand All @@ -53,8 +53,8 @@ def create_author
end

def create_coauthor
check = User.find_by(username: params[:user][:username])
params[:user][:username] = params[:user][:email] unless check.nil?
check = User.find_by(username: params[:user][:name])
params[:user][:name] = params[:user][:email] unless check.nil?
User.skip_callback(:create, :after, :email_welcome)
is_author = false
# Assign all user params for creating co-author using assign_user_params function
Expand Down
2 changes: 1 addition & 1 deletion app/models/account_request.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
class AccountRequest < ApplicationRecord
before_save { self.email = email.downcase }
before_save { name }
before_save { username }
validates :username, presence: true, length: { maximum: 50, message: 'is too long' }
VALID_EMAIL_REGEX = /\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/i.freeze
validates :email, presence: true, length: { maximum: 255, message: 'is too long' },
Expand Down
4 changes: 2 additions & 2 deletions app/models/team.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def full?

# Add member to the team, changed to hash by E1776
def add_member(user, _assignment_id = nil)
raise "The user #{user.username} is already a member of the team #{name}" if user?(user)
raise "The user #{user.name} is already a member of the team #{name}" if user?(user)

can_add_member = false
unless full?
Expand All @@ -87,7 +87,7 @@ def add_member(user, _assignment_id = nil)
parent = TeamNode.find_by(node_object_id: id)
TeamUserNode.create(parent_id: parent.id, node_object_id: t_user.id)
add_participant(parent_id, user)
ExpertizaLogger.info LoggerMessage.new('Model:Team', user.username, "Added member to the team #{id}")
ExpertizaLogger.info LoggerMessage.new('Model:Team', user.name, "Added member to the team #{id}")
end
can_add_member
end
Expand Down

0 comments on commit 562e78e

Please sign in to comment.