Commit 7d4fab34 authored by James Edwards-Jones's avatar James Edwards-Jones

Settings::RepositoryController includes protected tags in JS

parent a14dd5a1
...@@ -5,10 +5,9 @@ module Projects ...@@ -5,10 +5,9 @@ module Projects
before_action :remote_mirror, only: [:show] before_action :remote_mirror, only: [:show]
def show def show
@deploy_keys = DeployKeysPresenter @deploy_keys = DeployKeysPresenter.new(@project, current_user: current_user)
.new(@project, current_user: current_user)
define_protected_branches define_protected_refs
project.create_push_rule unless project.push_rule project.create_push_rule unless project.push_rule
@push_rule = project.push_rule @push_rule = project.push_rule
...@@ -16,21 +15,21 @@ module Projects ...@@ -16,21 +15,21 @@ module Projects
private private
def define_protected_branches
load_protected_branches
@protected_branch = @project.protected_branches.new
load_gon_index
end
def remote_mirror def remote_mirror
@remote_mirror = @project.remote_mirrors.first_or_initialize @remote_mirror = @project.remote_mirrors.first_or_initialize
end end
def load_protected_branches def define_protected_refs
@protected_branches = @project.protected_branches.order(:name).page(params[:page]) @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 end
def access_levels_options def access_levels_options
#TODO: consider protected tags
#TODO: Refactor ProtectedBranch::PushAccessLevel so it doesn't mention branches
{ {
push_access_levels: { push_access_levels: {
roles: ProtectedBranch::PushAccessLevel.human_access_levels.map do |id, text| roles: ProtectedBranch::PushAccessLevel.human_access_levels.map do |id, text|
...@@ -47,15 +46,29 @@ module Projects ...@@ -47,15 +46,29 @@ module Projects
} }
end 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 def open_branches
branches = @project.open_branches.map { |br| { text: br.name, id: br.name, title: br.name } } branches = @project.open_branches.map { |br| { text: br.name, id: br.name, title: br.name } }
{ open_branches: branches } { open_branches: branches }
end end
def load_gon_index def load_gon_index
params = open_branches gon.push(open_branches)
params[:current_project_id] = @project.id if @project gon.push(unprotected_tags_hash)
gon.push(params.merge(access_levels_options)) gon.push(access_levels_options)
gon.push(current_project_id: @project.id) if @project
end end
end end
end end
......
module ProtectedBranchAccess # module ProtectedRefAccess
extend ActiveSupport::Concern # extend ActiveSupport::Concern
included do # included do
belongs_to :protected_branch # # belongs_to :protected_branch
delegate :project, to: :protected_branch # # delegate :project, to: :protected_branch
scope :master, -> { where(access_level: Gitlab::Access::MASTER) } # scope :master, -> { where(access_level: Gitlab::Access::MASTER) }
scope :developer, -> { where(access_level: Gitlab::Access::DEVELOPER) } # scope :developer, -> { where(access_level: Gitlab::Access::DEVELOPER) }
end # end
def humanize # def humanize
self.class.human_access_levels[self.access_level] # self.class.human_access_levels[self.access_level]
end # end
def check_access(user) # def check_access(user)
return true if user.is_admin? # return true if user.is_admin?
project.team.max_member_access(user.id) >= access_level # project.team.max_member_access(user.id) >= access_level
end # end
end # end
...@@ -978,6 +978,7 @@ class Project < ActiveRecord::Base ...@@ -978,6 +978,7 @@ class Project < ActiveRecord::Base
end end
# Branches that are not _exactly_ matched by a protected branch. # Branches that are not _exactly_ matched by a protected branch.
#TODO: Move to Protections::BranchMatcher.new(project).unprotecte
def open_branches def open_branches
exact_protected_branch_names = protected_branches.reject(&:wildcard?).map(&:name) exact_protected_branch_names = protected_branches.reject(&:wildcard?).map(&:name)
branch_names = repository.branches.map(&:name) branch_names = repository.branches.map(&:name)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment