Skip to content

Commit

Permalink
Updates (#132)
Browse files Browse the repository at this point in the history
* Adding methods to onboard

* Upgrading puma to 6.4.0 + few other updates
  • Loading branch information
spaquet authored Sep 22, 2023
1 parent b299f79 commit 061d330
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ gem 'sprockets-rails'
gem 'pg', '~> 1.5.4'

# Use the Puma web server [https://github.com/puma/puma]
gem 'puma', '~> 6.3.0'
gem 'puma', '~> 6.4.0'

# Bundle and transpile JavaScript [https://github.com/rails/jsbundling-rails]
gem 'jsbundling-rails'
Expand Down
12 changes: 6 additions & 6 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -100,16 +100,16 @@ GEM
ffi-compiler (~> 1.0)
ast (2.4.2)
aws-eventstream (1.2.0)
aws-partitions (1.824.0)
aws-sdk-core (3.181.1)
aws-partitions (1.826.0)
aws-sdk-core (3.183.0)
aws-eventstream (~> 1, >= 1.0.2)
aws-partitions (~> 1, >= 1.651.0)
aws-sigv4 (~> 1.5)
jmespath (~> 1, >= 1.6.1)
aws-sdk-kms (1.71.0)
aws-sdk-core (~> 3, >= 3.177.0)
aws-sigv4 (~> 1.1)
aws-sdk-s3 (1.134.0)
aws-sdk-s3 (1.135.0)
aws-sdk-core (~> 3, >= 3.181.0)
aws-sdk-kms (~> 1)
aws-sigv4 (~> 1.6)
Expand Down Expand Up @@ -265,7 +265,7 @@ GEM
timeout
net-scp (4.0.0)
net-ssh (>= 2.6.5, < 8.0.0)
net-smtp (0.3.3)
net-smtp (0.4.0)
net-protocol
net-ssh (7.2.0)
nio4r (2.5.9)
Expand Down Expand Up @@ -317,7 +317,7 @@ GEM
psych (5.1.0)
stringio
public_suffix (5.0.3)
puma (6.3.1)
puma (6.4.0)
nio4r (~> 2.0)
pundit (2.3.1)
activesupport (>= 3.0.0)
Expand Down Expand Up @@ -533,7 +533,7 @@ DEPENDENCIES
paper_trail (~> 15.0.0)
pg (~> 1.5.4)
pg_search (~> 2.3.6)
puma (~> 6.3.0)
puma (~> 6.4.0)
pundit
rails (~> 7.0.8)
redis (~> 5.0.5)
Expand Down
70 changes: 70 additions & 0 deletions lib/tasks/onboard.rake
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,76 @@ namespace :onboard do
end_task
end

# Usage:
# Used to create a user, the user profile and make this user a member of an organization
# - rake "onboard:create_organization_user[org_id, test@test.com, nickname]"
desc 'Create a user and associate this user with an existing organization'
task :create_organization_user, [:organization_id, :email, :nickname] => :environment do |_t, args|
begin
puts("[#{Time.now.utc}] Running create_organization_user :: INI")

organization = Organization.find(args[:organization_id])
unless organization
puts("[#{Time.now.utc}] Organization with ID #{args[:organization_id]} not found.")
end_task(-1)
end

user = User.find_or_initialize_by(email: args[:email])
user.profile ||= Profile.new # Create a profile if it doesn't exist
user.profile.nickname = args[:nickname]

if user.save
member = Member.find_or_initialize_by(user: user, organization: organization)
member.owner = false # You can set this to true if this user should be the owner
member.save
puts("[#{Time.now.utc}] User #{user.email} has been created and added to organization #{organization.name} as a member.")
puts("[#{Time.now.utc}] User #{user.email} ID is: #{user.id}")
end_task(0)
else
puts("[#{Time.now.utc}] Failed to create user. Errors: #{user.errors.full_messages.join(', ')}")
end_task(-1)
end
rescue => e
puts("[#{Time.now.utc}] An error occurred: #{e.message}")
end_task(-1)
end
end

# Usage:
# Used to assign the admin role for a user who is already a member of an organization
# - rake "onboard:make_org_admin[org_id, test@test.com]"
desc 'Make a user admin of an organization'
task :make_org_admin, [:organization_id, :email] => :environment do |_t, args|
begin
puts("[#{Time.now.utc}] Running make_org_admin :: INI")

organization = Organization.find(args[:organization_id])
user = User.find_by(email: args[:email])

unless organization
puts("[#{Time.now.utc}] Organization with ID #{args[:organization_id]} not found.")
end_task(-1)
end

unless user
puts("[#{Time.now.utc}] User with email #{args[:email]} not found.")
end_task(-1)
end

unless user.has_role?(:admin, organization)
user.add_role(:admin, organization)
puts("[#{Time.now.utc}] User #{user.email} is now an admin of organization #{organization.name}.")
else
puts("[#{Time.now.utc}] User #{user.email} is already an admin of organization #{organization.name}.")
end

end_task(0)
rescue => e
puts("An error occurred: #{e.message}")
end_task(-1)
end
end

def end_task(status = 0)
puts("[#{Time.now.utc}] Running create_first_user_and_org :: END")
exit(status)
Expand Down

0 comments on commit 061d330

Please sign in to comment.