Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2022-05-26 06:09:21 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2022-05-26 06:09:21 +0300
commit47ef8c6c530ee1cac0e1046b098755ec949da894 (patch)
treed09c3d5598aad53c0f2c721ce237ff8b1db5f7ec /app
parenteb90b0642d7949bfa03c8e9b5f39d211934fb0b5 (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app')
-rw-r--r--app/models/namespace.rb2
-rw-r--r--app/models/namespaces/project_namespace.rb7
-rw-r--r--app/models/project.rb24
-rw-r--r--app/models/protected_tag.rb6
-rw-r--r--app/serializers/linked_issue_entity.rb9
5 files changed, 40 insertions, 8 deletions
diff --git a/app/models/namespace.rb b/app/models/namespace.rb
index 865ca85d982..ec4b9786945 100644
--- a/app/models/namespace.rb
+++ b/app/models/namespace.rb
@@ -632,7 +632,7 @@ class Namespace < ApplicationRecord
return
end
- if parent.project_namespace?
+ if parent&.project_namespace?
errors.add(:parent_id, _('project namespace cannot be the parent of another namespace'))
end
diff --git a/app/models/namespaces/project_namespace.rb b/app/models/namespaces/project_namespace.rb
index fbd87e3232d..2a2ea11ddc5 100644
--- a/app/models/namespaces/project_namespace.rb
+++ b/app/models/namespaces/project_namespace.rb
@@ -2,6 +2,13 @@
module Namespaces
class ProjectNamespace < Namespace
+ # These aliases are added to make it easier to sync parent/parent_id attribute with
+ # project.namespace/project.namespace_id attribute.
+ #
+ # TODO: we can remove these attribute aliases when we no longer need to sync these with project model,
+ # see project#sync_attributes
+ alias_attribute :namespace, :parent
+ alias_attribute :namespace_id, :parent_id
has_one :project, foreign_key: :project_namespace_id, inverse_of: :project_namespace
def self.sti_name
diff --git a/app/models/project.rb b/app/models/project.rb
index e46f2a38cb0..759e3d348fb 100644
--- a/app/models/project.rb
+++ b/app/models/project.rb
@@ -3104,7 +3104,6 @@ class Project < ApplicationRecord
# create project_namespace when project is created
build_project_namespace if project_namespace_creation_enabled?
- # we need to keep project and project namespace in sync if there is one
sync_attributes(project_namespace) if sync_project_namespace?
end
@@ -3117,11 +3116,24 @@ class Project < ApplicationRecord
end
def sync_attributes(project_namespace)
- project_namespace.name = name
- project_namespace.path = path
- project_namespace.parent = namespace
- project_namespace.shared_runners_enabled = shared_runners_enabled
- project_namespace.visibility_level = visibility_level
+ attributes_to_sync = changes.slice(*%w(name path namespace_id namespace visibility_level shared_runners_enabled))
+ .transform_values { |val| val[1] }
+
+ # if visibility_level is not set explicitly for project, it defaults to 0,
+ # but for namespace visibility_level defaults to 20,
+ # so it gets out of sync right away if we do not set it explicitly when creating the project namespace
+ attributes_to_sync['visibility_level'] ||= visibility_level if new_record?
+
+ # when a project is associated with a group while the group is created we need to ensure we associate the new
+ # group with the project namespace as well.
+ # E.g.
+ # project = create(:project) <- project is saved
+ # create(:group, projects: [project]) <- associate project with a group that is not yet created.
+ if attributes_to_sync.has_key?('namespace_id') && attributes_to_sync['namespace_id'].blank? && namespace.present?
+ attributes_to_sync['parent'] = namespace
+ end
+
+ project_namespace.assign_attributes(attributes_to_sync)
end
# SyncEvents are created by PG triggers (with the function `insert_projects_sync_event`)
diff --git a/app/models/protected_tag.rb b/app/models/protected_tag.rb
index 6b507429e57..5b2467daddc 100644
--- a/app/models/protected_tag.rb
+++ b/app/models/protected_tag.rb
@@ -8,7 +8,11 @@ class ProtectedTag < ApplicationRecord
protected_ref_access_levels :create
def self.protected?(project, ref_name)
- refs = project.protected_tags.select(:name)
+ return false if ref_name.blank?
+
+ refs = Gitlab::SafeRequestStore.fetch("protected-tag:#{project.cache_key}:refs") do
+ project.protected_tags.select(:name)
+ end
self.matching(ref_name, protected_refs: refs).present?
end
diff --git a/app/serializers/linked_issue_entity.rb b/app/serializers/linked_issue_entity.rb
index 769e3ed7310..4a28213fbac 100644
--- a/app/serializers/linked_issue_entity.rb
+++ b/app/serializers/linked_issue_entity.rb
@@ -3,6 +3,10 @@
class LinkedIssueEntity < Grape::Entity
include RequestAwareEntity
+ format_with(:upcase) do |item|
+ item.try(:upcase)
+ end
+
expose :id, :confidential, :title
expose :assignees, using: UserEntity
@@ -21,6 +25,11 @@ class LinkedIssueEntity < Grape::Entity
Gitlab::UrlBuilder.build(link, only_path: true)
end
+ expose :issue_type,
+ as: :type,
+ format_with: :upcase,
+ documentation: { type: "String", desc: "One of #{::WorkItems::Type.base_types.keys.map(&:upcase)}" }
+
expose :relation_path
expose :due_date, :created_at, :closed_at