diff options
Diffstat (limited to 'app/models')
-rw-r--r-- | app/models/container_expiration_policy.rb | 41 | ||||
-rw-r--r-- | app/models/namespace.rb | 4 | ||||
-rw-r--r-- | app/models/project.rb | 7 | ||||
-rw-r--r-- | app/models/user.rb | 4 |
4 files changed, 54 insertions, 2 deletions
diff --git a/app/models/container_expiration_policy.rb b/app/models/container_expiration_policy.rb new file mode 100644 index 00000000000..f60a0179c83 --- /dev/null +++ b/app/models/container_expiration_policy.rb @@ -0,0 +1,41 @@ +# frozen_string_literal: true + +class ContainerExpirationPolicy < ApplicationRecord + belongs_to :project, inverse_of: :container_expiration_policy + + validates :project, presence: true + validates :enabled, inclusion: { in: [true, false] } + validates :cadence, presence: true, inclusion: { in: ->(_) { self.cadence_options.stringify_keys } } + validates :older_than, inclusion: { in: ->(_) { self.older_than_options.stringify_keys } }, allow_nil: true + validates :keep_n, inclusion: { in: ->(_) { self.keep_n_options.keys } }, allow_nil: true + + def self.keep_n_options + { + 1 => _('%{tags} tag per image name') % { tags: 1 }, + 5 => _('%{tags} tags per image name') % { tags: 5 }, + 10 => _('%{tags} tags per image name') % { tags: 10 }, + 25 => _('%{tags} tags per image name') % { tags: 25 }, + 50 => _('%{tags} tags per image name') % { tags: 50 }, + 100 => _('%{tags} tags per image name') % { tags: 100 } + } + end + + def self.cadence_options + { + '1d': _('Every day'), + '7d': _('Every week'), + '14d': _('Every two weeks'), + '1month': _('Every month'), + '3month': _('Every three months') + } + end + + def self.older_than_options + { + '7d': _('%{days} days until tags are automatically removed') % { days: 7 }, + '14d': _('%{days} days until tags are automatically removed') % { days: 14 }, + '30d': _('%{days} days until tags are automatically removed') % { days: 30 }, + '90d': _('%{days} days until tags are automatically removed') % { days: 90 } + } + end +end diff --git a/app/models/namespace.rb b/app/models/namespace.rb index 5663ebf8ba1..d5a7c172fec 100644 --- a/app/models/namespace.rb +++ b/app/models/namespace.rb @@ -123,8 +123,10 @@ class Namespace < ApplicationRecord def find_by_pages_host(host) gitlab_host = "." + Settings.pages.host.downcase - name = host.downcase.delete_suffix(gitlab_host) + host = host.downcase + return unless host.ends_with?(gitlab_host) + name = host.delete_suffix(gitlab_host) Namespace.find_by_full_path(name) end end diff --git a/app/models/project.rb b/app/models/project.rb index 1cf69bf8403..84289e1d5ac 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -97,8 +97,11 @@ class Project < ApplicationRecord unless: :ci_cd_settings, if: proc { ProjectCiCdSetting.available? } + after_create :create_container_expiration_policy, + unless: :container_expiration_policy + after_create :create_pages_metadatum, - unless: :pages_metadatum + unless: :pages_metadatum after_create :set_timestamps_for_create after_update :update_forks_visibility_level @@ -248,6 +251,7 @@ class Project < ApplicationRecord # which is not managed by the DB. Hence we're still using dependent: :destroy # here. has_many :container_repositories, dependent: :destroy # rubocop:disable Cop/ActiveRecordDependent + has_one :container_expiration_policy, inverse_of: :project has_many :commit_statuses # The relation :all_pipelines is intended to be used when we want to get the @@ -305,6 +309,7 @@ class Project < ApplicationRecord accepts_nested_attributes_for :import_data accepts_nested_attributes_for :auto_devops, update_only: true accepts_nested_attributes_for :ci_cd_settings, update_only: true + accepts_nested_attributes_for :container_expiration_policy, update_only: true accepts_nested_attributes_for :remote_mirrors, allow_destroy: true, diff --git a/app/models/user.rb b/app/models/user.rb index fd02db86582..6a29de20d86 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -996,6 +996,10 @@ class User < ApplicationRecord @ldap_identity ||= identities.find_by(["provider LIKE ?", "ldap%"]) end + def matches_identity?(provider, extern_uid) + identities.where(provider: provider, extern_uid: extern_uid).exists? + end + def project_deploy_keys DeployKey.in_projects(authorized_projects.select(:id)).distinct(:id) end |