Class: UffizziCore::UserGeneratorService
- Inherits:
-
Object
- Object
- UffizziCore::UserGeneratorService
- Defined in:
- app/services/uffizzi_core/user_generator_service.rb
Constant Summary collapse
- DEFAULT_USER_EMAIL =
'[email protected]'
- DEFAULT_PROJECT_NAME =
'default'
- DEFAULT_ACCOUNT_NAME =
'default'
Class Method Summary collapse
- .generate(email, password, project_name) ⇒ Object
- .safe_generate(email, password, project_name) ⇒ Object
Class Method Details
.generate(email, password, project_name) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'app/services/uffizzi_core/user_generator_service.rb', line 15 def generate(email, password, project_name) user_attributes = build_user_attributes(email, password) project_attributes = build_project_attributes(project_name) ActiveRecord::Base.transaction do user = UffizziCore::User.create!(user_attributes) account_attributes = build_account_attributes(user) account = UffizziCore::Account.create!(account_attributes) user.memberships.create!(account: account, role: UffizziCore::Membership.role.admin) project = account.projects.create!(project_attributes) project.user_projects.create!(user: user, role: UffizziCore::UserProject.role.admin) end end |
.safe_generate(email, password, project_name) ⇒ Object
9 10 11 12 13 |
# File 'app/services/uffizzi_core/user_generator_service.rb', line 9 def safe_generate(email, password, project_name) generate(email, password, project_name) rescue StandardError => e puts e. end |