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
1
Merge Requests
1
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
nexedi
gitlab-ce
Commits
e0d09071
Commit
e0d09071
authored
Apr 10, 2017
by
James Edwards-Jones
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Protected Tags per user/group access levels backend
parent
570565fd
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
40 additions
and
29 deletions
+40
-29
app/controllers/projects/protected_tags/application_controller.rb
...rollers/projects/protected_tags/application_controller.rb
+7
-0
app/controllers/projects/protected_tags/create_access_levels_controller.rb
...rojects/protected_tags/create_access_levels_controller.rb
+15
-0
app/controllers/projects/settings/repository_controller.rb
app/controllers/projects/settings/repository_controller.rb
+1
-0
app/models/concerns/protected_ref.rb
app/models/concerns/protected_ref.rb
+15
-0
app/models/protected_branch.rb
app/models/protected_branch.rb
+1
-24
app/models/protected_tag.rb
app/models/protected_tag.rb
+1
-5
No files found.
app/controllers/projects/protected_tags/application_controller.rb
0 → 100644
View file @
e0d09071
class
Projects::ProtectedTags::ApplicationController
<
Projects
::
ApplicationController
protected
def
load_protected_tag
@protected_tag
=
@project
.
protected_tags
.
find
(
params
[
:protected_tag_id
])
end
end
app/controllers/projects/protected_tags/create_access_levels_controller.rb
0 → 100644
View file @
e0d09071
module
Projects
module
ProtectedTags
class
CreateAccessLevelsController
<
ProtectedTags
::
ApplicationController
before_action
:load_protected_tag
,
only:
[
:destroy
]
def
destroy
@create_access_level
=
@protected_tag
.
create_access_levels
.
find
(
params
[
:id
])
@create_access_level
.
destroy
redirect_to
namespace_project_protected_tag_path
(
@project
.
namespace
,
@project
,
@protected_tag
),
notice:
"Successfully deleted.
#{
@create_access_level
.
humanize
}
will not be able to create this protected tag."
end
end
end
end
app/controllers/projects/settings/repository_controller.rb
View file @
e0d09071
...
@@ -31,6 +31,7 @@ module Projects
...
@@ -31,6 +31,7 @@ module Projects
{
{
selected_merge_access_levels:
@protected_branch
.
merge_access_levels
.
map
{
|
access_level
|
access_level
.
user_id
||
access_level
.
access_level
},
selected_merge_access_levels:
@protected_branch
.
merge_access_levels
.
map
{
|
access_level
|
access_level
.
user_id
||
access_level
.
access_level
},
selected_push_access_levels:
@protected_branch
.
push_access_levels
.
map
{
|
access_level
|
access_level
.
user_id
||
access_level
.
access_level
},
selected_push_access_levels:
@protected_branch
.
push_access_levels
.
map
{
|
access_level
|
access_level
.
user_id
||
access_level
.
access_level
},
selected_create_access_levels:
@protected_tag
.
create_access_levels
.
map
{
|
access_level
|
access_level
.
user_id
||
access_level
.
access_level
},
create_access_levels:
levels_for_dropdown
(
ProtectedTag
::
CreateAccessLevel
),
create_access_levels:
levels_for_dropdown
(
ProtectedTag
::
CreateAccessLevel
),
push_access_levels:
levels_for_dropdown
(
ProtectedBranch
::
PushAccessLevel
),
push_access_levels:
levels_for_dropdown
(
ProtectedBranch
::
PushAccessLevel
),
merge_access_levels:
levels_for_dropdown
(
ProtectedBranch
::
MergeAccessLevel
)
merge_access_levels:
levels_for_dropdown
(
ProtectedBranch
::
MergeAccessLevel
)
...
...
app/models/concerns/protected_ref.rb
View file @
e0d09071
...
@@ -9,6 +9,21 @@ module ProtectedRef
...
@@ -9,6 +9,21 @@ module ProtectedRef
delegate
:matching
,
:matches?
,
:wildcard?
,
to: :ref_matcher
delegate
:matching
,
:matches?
,
:wildcard?
,
to: :ref_matcher
def
self
.
protected_ref_access_levels
(
*
types
)
types
.
each
do
|
type
|
has_many
:"
#{
type
}
_access_levels"
,
dependent: :destroy
validates
:"
#{
type
}
_access_levels"
,
length:
{
minimum:
0
}
accepts_nested_attributes_for
:"
#{
type
}
_access_levels"
,
allow_destroy:
true
# Returns access levels that grant the specified access type to the given user / group.
access_level_class
=
const_get
(
"
#{
type
}
_access_level"
.
camelize
)
scope
:"
#{
type
}
_access_by_user"
,
->
(
user
)
{
access_level_class
.
joins
(
:protected_branch
).
where
(
protected_branch_id:
self
.
ids
).
merge
(
access_level_class
.
by_user
(
user
))
}
scope
:"
#{
type
}
_access_by_group"
,
->
(
group
)
{
access_level_class
.
joins
(
:protected_branch
).
where
(
protected_branch_id:
self
.
ids
).
merge
(
access_level_class
.
by_group
(
group
))
}
end
end
def
self
.
protected_ref_accessible_to?
(
ref
,
user
,
action
:)
def
self
.
protected_ref_accessible_to?
(
ref
,
user
,
action
:)
access_levels_for_ref
(
ref
,
action:
action
).
any?
do
|
access_level
|
access_levels_for_ref
(
ref
,
action:
action
).
any?
do
|
access_level
|
access_level
.
check_access
(
user
)
access_level
.
check_access
(
user
)
...
...
app/models/protected_branch.rb
View file @
e0d09071
...
@@ -2,30 +2,7 @@ class ProtectedBranch < ActiveRecord::Base
...
@@ -2,30 +2,7 @@ class ProtectedBranch < ActiveRecord::Base
include
Gitlab
::
ShellAdapter
include
Gitlab
::
ShellAdapter
include
ProtectedRef
include
ProtectedRef
has_many
:merge_access_levels
,
dependent: :destroy
protected_ref_access_levels
:merge
,
:push
has_many
:push_access_levels
,
dependent: :destroy
validates
:merge_access_levels
,
length:
{
minimum:
0
}
validates
:push_access_levels
,
length:
{
minimum:
0
}
accepts_nested_attributes_for
:push_access_levels
,
allow_destroy:
true
accepts_nested_attributes_for
:merge_access_levels
,
allow_destroy:
true
# Returns all merge access levels (for protected branches in scope) that grant merge
# access to the given user.
scope
:merge_access_by_user
,
->
(
user
)
{
MergeAccessLevel
.
joins
(
:protected_branch
).
where
(
protected_branch_id:
self
.
ids
).
merge
(
MergeAccessLevel
.
by_user
(
user
))
}
# Returns all push access levels (for protected branches in scope) that grant push
# access to the given user.
scope
:push_access_by_user
,
->
(
user
)
{
PushAccessLevel
.
joins
(
:protected_branch
).
where
(
protected_branch_id:
self
.
ids
).
merge
(
PushAccessLevel
.
by_user
(
user
))
}
# Returns all merge access levels (for protected branches in scope) that grant merge
# access to the given group.
scope
:merge_access_by_group
,
->
(
group
)
{
MergeAccessLevel
.
joins
(
:protected_branch
).
where
(
protected_branch_id:
self
.
ids
).
merge
(
MergeAccessLevel
.
by_group
(
group
))
}
# Returns all push access levels (for protected branches in scope) that grant push
# access to the given group.
scope
:push_access_by_group
,
->
(
group
)
{
PushAccessLevel
.
joins
(
:protected_branch
).
where
(
protected_branch_id:
self
.
ids
).
merge
(
PushAccessLevel
.
by_group
(
group
))
}
# Returns a hash were keys are types of push access levels (user, role), and
# Returns a hash were keys are types of push access levels (user, role), and
# values are the number of access levels of the particular type.
# values are the number of access levels of the particular type.
...
...
app/models/protected_tag.rb
View file @
e0d09071
...
@@ -2,11 +2,7 @@ class ProtectedTag < ActiveRecord::Base
...
@@ -2,11 +2,7 @@ class ProtectedTag < ActiveRecord::Base
include
Gitlab
::
ShellAdapter
include
Gitlab
::
ShellAdapter
include
ProtectedRef
include
ProtectedRef
has_many
:create_access_levels
,
dependent: :destroy
protected_ref_access_levels
:create
validates
:create_access_levels
,
length:
{
is:
1
,
message:
"are restricted to a single instance per protected tag."
}
accepts_nested_attributes_for
:create_access_levels
def
self
.
protected?
(
project
,
ref_name
)
def
self
.
protected?
(
project
,
ref_name
)
self
.
matching
(
ref_name
,
protected_refs:
project
.
protected_tags
).
present?
self
.
matching
(
ref_name
,
protected_refs:
project
.
protected_tags
).
present?
...
...
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