Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Boxiang Sun
gitlab-ce
Commits
f9e849c0
Commit
f9e849c0
authored
Apr 04, 2017
by
James Edwards-Jones
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Cleaned up duplication with ProtectedRefAccess concern
parent
3bb3a688
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
27 additions
and
55 deletions
+27
-55
app/controllers/projects/settings/repository_controller.rb
app/controllers/projects/settings/repository_controller.rb
+9
-10
app/models/concerns/protected_branch_access.rb
app/models/concerns/protected_branch_access.rb
+2
-13
app/models/concerns/protected_ref_access.rb
app/models/concerns/protected_ref_access.rb
+14
-18
app/models/concerns/protected_tag_access.rb
app/models/concerns/protected_tag_access.rb
+2
-13
spec/lib/gitlab/user_access_spec.rb
spec/lib/gitlab/user_access_spec.rb
+0
-1
No files found.
app/controllers/projects/settings/repository_controller.rb
View file @
f9e849c0
...
@@ -23,17 +23,16 @@ module Projects
...
@@ -23,17 +23,16 @@ module Projects
#TODO: consider protected tags
#TODO: consider protected tags
#TODO: Refactor ProtectedBranch::PushAccessLevel so it doesn't mention branches
#TODO: Refactor ProtectedBranch::PushAccessLevel so it doesn't mention branches
{
{
push_access_levels:
{
push_access_levels:
levels_for_dropdown
(
ProtectedBranch
::
PushAccessLevel
),
roles:
ProtectedBranch
::
PushAccessLevel
.
human_access_levels
.
map
do
|
id
,
text
|
merge_access_levels:
levels_for_dropdown
(
ProtectedBranch
::
MergeAccessLevel
)
{
id:
id
,
text:
text
,
before_divider:
true
}
}
end
end
},
merge_access_levels:
{
def
levels_for_dropdown
(
access_level_type
)
roles:
ProtectedBranch
::
MergeAccessLevel
.
human_access_levels
.
map
do
|
id
,
text
|
roles
=
access_level_type
.
human_access_levels
.
map
do
|
id
,
text
|
{
id:
id
,
text:
text
,
before_divider:
true
}
{
id:
id
,
text:
text
,
before_divider:
true
}
end
end
}
{
roles:
roles
}
}
end
end
def
protectable_tags_for_dropdown
def
protectable_tags_for_dropdown
...
...
app/models/concerns/protected_branch_access.rb
View file @
f9e849c0
...
@@ -2,20 +2,9 @@ module ProtectedBranchAccess
...
@@ -2,20 +2,9 @@ module ProtectedBranchAccess
extend
ActiveSupport
::
Concern
extend
ActiveSupport
::
Concern
included
do
included
do
include
ProtectedRefAccess
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
: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
end
end
app/models/concerns/protected_ref_access.rb
View file @
f9e849c0
#TODO: Refactor, checking EE
module
ProtectedRefAccess
# module ProtectedRefAccess
extend
ActiveSupport
::
Concern
# extend ActiveSupport::Concern
# included do
included
do
# # belongs_to :protected_branch
scope
:master
,
->
{
where
(
access_level:
Gitlab
::
Access
::
MASTER
)
}
# # delegate :project, to: :protected_branch
scope
:developer
,
->
{
where
(
access_level:
Gitlab
::
Access
::
DEVELOPER
)
}
end
# scope :master, -> { where(access_level: Gitlab::Access::MASTER) }
def
humanize
# scope :developer, -> { where(access_level: Gitlab::Access::DEVELOPER) }
self
.
class
.
human_access_levels
[
self
.
access_level
]
#
end
end
# def humanize
def
check_access
(
user
)
# self.class.human_access_levels[self.access_level]
return
true
if
user
.
is_admin?
# end
# def check_access(user)
project
.
team
.
max_member_access
(
user
.
id
)
>=
access_level
# return true if user.is_admin?
end
end
# project.team.max_member_access(user.id) >= access_level
# end
# end
app/models/concerns/protected_tag_access.rb
View file @
f9e849c0
...
@@ -2,20 +2,9 @@ module ProtectedTagAccess
...
@@ -2,20 +2,9 @@ module ProtectedTagAccess
extend
ActiveSupport
::
Concern
extend
ActiveSupport
::
Concern
included
do
included
do
include
ProtectedRefAccess
belongs_to
:protected_tag
belongs_to
:protected_tag
delegate
:project
,
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
end
end
spec/lib/gitlab/user_access_spec.rb
View file @
f9e849c0
...
@@ -164,7 +164,6 @@ describe Gitlab::UserAccess, lib: true do
...
@@ -164,7 +164,6 @@ describe Gitlab::UserAccess, lib: true do
end
end
end
end
describe
'push to protected tag'
do
describe
'push to protected tag'
do
let
(
:tag
)
{
create
(
:protected_tag
,
project:
project
,
name:
"test"
)
}
let
(
:tag
)
{
create
(
:protected_tag
,
project:
project
,
name:
"test"
)
}
let
(
:not_existing_tag
)
{
create
:protected_tag
,
project:
project
}
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