diff options
author | James Edwards-Jones <jedwardsjones@gitlab.com> | 2017-04-04 02:59:37 +0100 |
---|---|---|
committer | James Edwards-Jones <jedwardsjones@gitlab.com> | 2017-04-04 02:59:37 +0100 |
commit | f9e849c076efb3162a3d951d8aae2e7be3e574f4 (patch) | |
tree | 8593f390302635cdfab2e733b305ee01f59bb885 | |
parent | 3bb3a6886f3b206a2ec089d6b1e8854615daa0b8 (diff) | |
download | gitlab-ce-f9e849c076efb3162a3d951d8aae2e7be3e574f4.tar.gz |
Cleaned up duplication with ProtectedRefAccess concern
-rw-r--r-- | app/controllers/projects/settings/repository_controller.rb | 19 | ||||
-rw-r--r-- | app/models/concerns/protected_branch_access.rb | 15 | ||||
-rw-r--r-- | app/models/concerns/protected_ref_access.rb | 32 | ||||
-rw-r--r-- | app/models/concerns/protected_tag_access.rb | 15 | ||||
-rw-r--r-- | spec/lib/gitlab/user_access_spec.rb | 1 |
5 files changed, 27 insertions, 55 deletions
diff --git a/app/controllers/projects/settings/repository_controller.rb b/app/controllers/projects/settings/repository_controller.rb index ff818d9e51a..9022cf8f0d8 100644 --- a/app/controllers/projects/settings/repository_controller.rb +++ b/app/controllers/projects/settings/repository_controller.rb @@ -23,19 +23,18 @@ module Projects #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| - { id: id, text: text, before_divider: true } - end - }, - merge_access_levels: { - roles: ProtectedBranch::MergeAccessLevel.human_access_levels.map do |id, text| - { id: id, text: text, before_divider: true } - end - } + push_access_levels: levels_for_dropdown(ProtectedBranch::PushAccessLevel), + merge_access_levels: levels_for_dropdown(ProtectedBranch::MergeAccessLevel) } end + def levels_for_dropdown(access_level_type) + roles = access_level_type.human_access_levels.map do |id, text| + { id: id, text: text, before_divider: true } + end + { roles: roles } + end + def protectable_tags_for_dropdown { open_tags: ProtectableDropdown.new(@project, :tags).hash } end diff --git a/app/models/concerns/protected_branch_access.rb b/app/models/concerns/protected_branch_access.rb index 9dd4d9c6f24..06cae00249a 100644 --- a/app/models/concerns/protected_branch_access.rb +++ b/app/models/concerns/protected_branch_access.rb @@ -2,20 +2,9 @@ module ProtectedBranchAccess extend ActiveSupport::Concern included do + include ProtectedRefAccess + 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 - - def humanize - self.class.human_access_levels[self.access_level] - end - - def check_access(user) - return true if user.is_admin? - - project.team.max_member_access(user.id) >= access_level end end diff --git a/app/models/concerns/protected_ref_access.rb b/app/models/concerns/protected_ref_access.rb index 08377127f69..0c7e5157cdf 100644 --- a/app/models/concerns/protected_ref_access.rb +++ b/app/models/concerns/protected_ref_access.rb @@ -1,22 +1,18 @@ -#TODO: Refactor, checking EE -# module ProtectedRefAccess -# extend ActiveSupport::Concern +module ProtectedRefAccess + extend ActiveSupport::Concern -# included do -# # belongs_to :protected_branch -# # delegate :project, to: :protected_branch + included do + 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/concerns/protected_tag_access.rb b/app/models/concerns/protected_tag_access.rb index cf66a6434b5..9b7d31a6fd5 100644 --- a/app/models/concerns/protected_tag_access.rb +++ b/app/models/concerns/protected_tag_access.rb @@ -2,20 +2,9 @@ module ProtectedTagAccess extend ActiveSupport::Concern included do + include ProtectedRefAccess + belongs_to :protected_tag delegate :project, to: :protected_tag - - 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 check_access(user) - return true if user.is_admin? - - project.team.max_member_access(user.id) >= access_level end end diff --git a/spec/lib/gitlab/user_access_spec.rb b/spec/lib/gitlab/user_access_spec.rb index c425aef359a..c69ff3446ea 100644 --- a/spec/lib/gitlab/user_access_spec.rb +++ b/spec/lib/gitlab/user_access_spec.rb @@ -164,7 +164,6 @@ describe Gitlab::UserAccess, lib: true do end end - describe 'push to protected tag' do let(:tag) { create(:protected_tag, project: project, name: "test") } let(:not_existing_tag) { create :protected_tag, project: project } |