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

added user rake task set_admin_role #5587

Merged
Merged
Changes from 2 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
23 changes: 23 additions & 0 deletions lib/tasks/user.rake
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,29 @@ namespace :user do
exit 0
end

desc 'Set user role to Administrator'
task :set_admin_role, %i[email] => :environment do |_task, args|
email = args[:email]

if email.blank?
info 'Please provide an email address of the user you wish to set to Administrator role.'
else
user = User.find_by(email:, provider: 'greenlight')
if user
role = Role.find_by(name: 'Administrator', provider: 'greenlight')
if role
user.role = role
user.save!
success "User role set to Administrator for email: #{email}"
else
info "Role 'Administrator' not found for provider 'greenlight'"
end
else
info "User with email: #{email} not found"
end
end
end
Copy link
Collaborator

@farhatahmad farhatahmad Nov 28, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The nested ifs make this super difficult to follow. Might be clearer to use guard clauses here instead

user = User.find_by(email:, provider: 'greenlight')
err 'User with email: #{email} not found' if user.blank?
...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah that sounds good. I updated the code with the guard clauses so its easier to read!


private

def check_role!(user:)
Expand Down
Loading