summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorJames Edwards-Jones <jedwardsjones@gitlab.com>2017-03-17 19:55:15 +0000
committerJames Edwards-Jones <jedwardsjones@gitlab.com>2017-03-31 19:37:15 +0100
commitf51eac1df967856299467f65ac6fb81e2d610ff5 (patch)
treedb8fa2a5d9c71d70acb83b246b8145336d6d9ad2 /app
parent91ed8ed687ee9edbda0098475e66ad41f886d7a5 (diff)
downloadgitlab-ce-f51eac1df967856299467f65ac6fb81e2d610ff5.tar.gz
Settings::RepositoryController includes protected tags in JS
Diffstat (limited to 'app')
-rw-r--r--app/controllers/projects/settings/repository_controller.rb30
-rw-r--r--app/models/concerns/protected_ref_access.rb32
-rw-r--r--app/models/project.rb1
3 files changed, 40 insertions, 23 deletions
diff --git a/app/controllers/projects/settings/repository_controller.rb b/app/controllers/projects/settings/repository_controller.rb
index b6ce4abca45..5160ee5e1e4 100644
--- a/app/controllers/projects/settings/repository_controller.rb
+++ b/app/controllers/projects/settings/repository_controller.rb
@@ -7,22 +7,23 @@ module Projects
@deploy_keys = DeployKeysPresenter
.new(@project, current_user: current_user)
- define_protected_branches
+ define_protected_refs
end
private
- def define_protected_branches
- load_protected_branches
+ def define_protected_refs
+ @protected_branches = @project.protected_branches.order(:name).page(params[:page])
+ @protected_tags = @project.protected_tags.order(:name).page(params[:page])
@protected_branch = @project.protected_branches.new
+ @protected_tag = @project.protected_tags.new
load_gon_index
end
- def load_protected_branches
- @protected_branches = @project.protected_branches.order(:name).page(params[:page])
- end
def access_levels_options
+ #TODO: consider protected tags
+ #TODO: Refactor ProtectedBranch::PushAccessLevel so it doesn't mention branches
{
push_access_levels: {
roles: ProtectedBranch::PushAccessLevel.human_access_levels.map do |id, text|
@@ -37,13 +38,28 @@ module Projects
}
end
+ #TODO: Move to Protections::TagMatcher.new(project).unprotected
+ def unprotected_tags
+ exact_protected_tag_names = @project.protected_tags.reject(&:wildcard?).map(&:name)
+ tag_names = @project.repository.tags.map(&:name)
+ non_open_tag_names = Set.new(exact_protected_tag_names).intersection(Set.new(tag_names))
+ @project.repository.tags.reject { |tag| non_open_tag_names.include? tag.name }
+ end
+
+ def unprotected_tags_hash
+ tags = unprotected_tags.map { |tag| { text: tag.name, id: tag.name, title: tag.name } }
+ { open_tags: tags }
+ end
+
def open_branches
branches = @project.open_branches.map { |br| { text: br.name, id: br.name, title: br.name } }
{ open_branches: branches }
end
def load_gon_index
- gon.push(open_branches.merge(access_levels_options))
+ gon.push(open_branches)
+ gon.push(unprotected_tags_hash)
+ gon.push(access_levels_options)
end
end
end
diff --git a/app/models/concerns/protected_ref_access.rb b/app/models/concerns/protected_ref_access.rb
index 9dd4d9c6f24..2870cd9385b 100644
--- a/app/models/concerns/protected_ref_access.rb
+++ b/app/models/concerns/protected_ref_access.rb
@@ -1,21 +1,21 @@
-module ProtectedBranchAccess
- extend ActiveSupport::Concern
+# module ProtectedRefAccess
+# extend ActiveSupport::Concern
- included do
- belongs_to :protected_branch
- delegate :project, to: :protected_branch
+# included do
+# # belongs_to :protected_branch
+# # delegate :project, to: :protected_branch
- scope :master, -> { where(access_level: Gitlab::Access::MASTER) }
- scope :developer, -> { where(access_level: Gitlab::Access::DEVELOPER) }
- end
+# scope :master, -> { where(access_level: Gitlab::Access::MASTER) }
+# scope :developer, -> { where(access_level: Gitlab::Access::DEVELOPER) }
+# end
- def humanize
- self.class.human_access_levels[self.access_level]
- end
+# def humanize
+# self.class.human_access_levels[self.access_level]
+# end
- def check_access(user)
- return true if user.is_admin?
+# def check_access(user)
+# return true if user.is_admin?
- project.team.max_member_access(user.id) >= access_level
- end
-end
+# project.team.max_member_access(user.id) >= access_level
+# end
+# end
diff --git a/app/models/project.rb b/app/models/project.rb
index 3f1a8a1a1e1..c04effc53bd 100644
--- a/app/models/project.rb
+++ b/app/models/project.rb
@@ -866,6 +866,7 @@ class Project < ActiveRecord::Base
end
# Branches that are not _exactly_ matched by a protected branch.
+ #TODO: Move to Protections::BranchMatcher.new(project).unprotecte
def open_branches
exact_protected_branch_names = protected_branches.reject(&:wildcard?).map(&:name)
branch_names = repository.branches.map(&:name)