-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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
added user rake task set_admin_role #5587
Conversation
lib/tasks/user.rake
Outdated
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 |
There was a problem hiding this comment.
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?
...
There was a problem hiding this comment.
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!
b99ccf8
to
919b4a9
Compare
lib/tasks/user.rake
Outdated
user.role = role | ||
user.save! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can do this in one line user.update(role:)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
got it and updated!
Kudos, SonarCloud Quality Gate passed! 0 Bugs No Coverage information |
Fixes #5515