Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
heptapod
heptapod
Commits
900f0c76b246
Commit
f9e849c0
authored
Apr 04, 2017
by
James Edwards-Jones
Browse files
Cleaned up duplication with ProtectedRefAccess concern
parent
20cafafeb680
Changes
5
Hide whitespace changes
Inline
Side-by-side
app/controllers/projects/settings/repository_controller.rb
View file @
900f0c76
...
...
@@ -23,19 +23,18 @@ 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
|
{
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
...
...
app/models/concerns/protected_branch_access.rb
View file @
900f0c76
...
...
@@ -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
app/models/concerns/protected_ref_access.rb
View file @
900f0c76
#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) }
#
s
cope :developer, -> { where(access_level: Gitlab::Access::DEVELOPER) }
#
end
def
humanize
s
elf
.
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
app/models/concerns/protected_tag_access.rb
View file @
900f0c76
...
...
@@ -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
spec/lib/gitlab/user_access_spec.rb
View file @
900f0c76
...
...
@@ -164,7 +164,6 @@
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
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment