Module: UffizziCore::ProjectService

Defined in:
app/services/uffizzi_core/project_service.rb

Class Method Summary collapse

Class Method Details

.add_users_to_project!(project, current_user) ⇒ Object



38
39
40
41
42
43
44
45
46
# File 'app/services/uffizzi_core/project_service.rb', line 38

def add_users_to_project!(project, current_user)
  user_projects = []

  current_user..memberships.where(role: UffizziCore::Membership.role.admin).map do |membership|
    user_projects << { project: project, user: membership.user, role: UffizziCore::UserProject.role.admin }
  end

  UffizziCore::UserProject.create!(user_projects)
end

.update_compose_secret_errors(project, secret) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'app/services/uffizzi_core/project_service.rb', line 24

def update_compose_secret_errors(project, secret)
  compose_file = project.compose_file
  return if compose_file.nil?
  return unless UffizziCore::ComposeFileService.has_secret?(compose_file, secret)

  error_message = I18n.t('compose.project_secret_not_found', secret: secret['name'])
  error = { UffizziCore::ComposeFile::ErrorsService::SECRETS_ERROR_KEY => [error_message] }

  existing_errors = compose_file.payload['errors'].presence || {}
  new_errors = existing_errors.merge(error)

  UffizziCore::ComposeFile::ErrorsService.update_compose_errors!(compose_file, new_errors, compose_file.content)
end

.update_compose_secrets(project) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'app/services/uffizzi_core/project_service.rb', line 5

def update_compose_secrets(project)
  compose_file = project.compose_file
  return if compose_file&.template.nil?

  project.secrets.each do |secret|
    if UffizziCore::ComposeFileService.has_secret?(compose_file, secret)
      UffizziCore::ComposeFileService.update_secret!(compose_file, secret)
    end
  end

  return unless UffizziCore::ComposeFileService.secrets_valid?(compose_file, project.secrets)

  secrets_error_key = UffizziCore::ComposeFile::ErrorsService::SECRETS_ERROR_KEY
  return unless UffizziCore::ComposeFile::ErrorsService.has_error?(compose_file, secrets_error_key)

  UffizziCore::ComposeFile::ErrorsService.reset_error!(compose_file, secrets_error_key)
  compose_file.set_valid! unless UffizziCore::ComposeFile::ErrorsService.has_errors?(compose_file)
end