Fix seeds to work with new UserRoles, fix Templates creation job [SCI-6270]

This commit is contained in:
Oleksii Kriuchykhin 2021-11-15 21:36:06 +01:00
parent 22623c821d
commit 2e92500a73
4 changed files with 8 additions and 2 deletions

View file

@ -29,7 +29,7 @@ module Api
project = @team.projects.build(project_params.merge!(created_by: current_user))
if project.visible? # set default viewer role for public projects
project.default_public_user_role = UserRole.find_by(name: I18n.t('user_roles.predefined.viewer'))
project.default_public_user_role = UserRole.predefined.find_by(name: I18n.t('user_roles.predefined.viewer'))
end
project.save!

View file

@ -15,6 +15,8 @@ class UserRole < ApplicationRecord
belongs_to :last_modified_by, class_name: 'User', optional: true
has_many :user_assignments, dependent: :destroy
scope :predefined, -> { where(predefined: true) }
def self.owner_role
new(
name: I18n.t('user_roles.predefined.owner'),

View file

@ -21,9 +21,9 @@ class TemplatesService
name: Constants::TEMPLATES_PROJECT_NAME,
visibility: :visible,
template: true,
default_public_user_role: UserRole.predefined.find_by(name: I18n.t('user_roles.predefined.viewer')),
created_by: team.created_by
)
tmpl_project.user_projects.create!(user: team.created_by, role: 'owner')
end
end
owner = tmpl_project.user_projects

View file

@ -1,5 +1,9 @@
include UsersGenerator
if ActiveRecord::Base.connection.migration_context.needs_migration?
raise "There are pending migrations. Run 'rails db:migrate' first."
end
MyModuleStatusFlow.ensure_default
if User.count.zero?