Skip to content

Commit

Permalink
idempotency for add_admin_role task
Browse files Browse the repository at this point in the history
  • Loading branch information
alepbloyd committed Jan 9, 2024
1 parent 99d93b4 commit 30ea28a
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions lib/tasks/gwss.rake
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,16 @@ namespace :gwss do

desc "Add a user to the admin role"
task :add_admin_role => :environment do
# Expect this variable to be set when running from the command line
if ENV["admin_user"]
r = Role.find_by_name("admin")
r.users << User.find_by_user_key(ENV["admin_user"])
r.save
if User.find_by(email: ENV['DEV_ADMIN_USER_EMAIL']) == nil
admin_user = User.create(email: ENV['DEV_ADMIN_USER_EMAIL'], password: ENV['DEV_ADMIN_USER_PASSWORD'])
admin_role = Role.find_or_create_by(name: 'admin')
admin_role.users << admin_user
end

if User.find_by(email: ENV['DEV_CONTENT_ADMIN_USER_EMAIL']) == nil
content_admin_user = User.create(email: ENV['DEV_CONTENT_ADMIN_USER_EMAIL'], password: ENV['DEV_CONTENT_ADMIN_USER_PASSWORD'])
content_admin_role = Role.find_or_create_by(name: 'content-admin')
content_admin_role.users << content_admin_user
end
end

Expand Down

0 comments on commit 30ea28a

Please sign in to comment.