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
1cdd33ca
Commit
1cdd33ca
authored
May 04, 2017
by
James Edwards-Jones
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use Concern#class_methods in ProtectedRef instead of “def self.”
parent
454abdfc
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
11 additions
and
9 deletions
+11
-9
app/models/concerns/protected_ref.rb
app/models/concerns/protected_ref.rb
+11
-9
No files found.
app/models/concerns/protected_ref.rb
View file @
1cdd33ca
...
...
@@ -8,8 +8,14 @@ module ProtectedRef
validates
:project
,
presence:
true
delegate
:matching
,
:matches?
,
:wildcard?
,
to: :ref_matcher
end
def
commit
project
.
commit
(
self
.
name
)
end
def
self
.
protected_ref_access_levels
(
*
types
)
class_methods
do
def
protected_ref_access_levels
(
*
types
)
types
.
each
do
|
type
|
has_many
:"
#{
type
}
_access_levels"
,
dependent: :destroy
...
...
@@ -25,31 +31,27 @@ module ProtectedRef
end
end
def
self
.
protected_ref_accessible_to?
(
ref
,
user
,
action
:)
def
protected_ref_accessible_to?
(
ref
,
user
,
action
:)
access_levels_for_ref
(
ref
,
action:
action
).
any?
do
|
access_level
|
access_level
.
check_access
(
user
)
end
end
def
self
.
developers_can?
(
action
,
ref
)
def
developers_can?
(
action
,
ref
)
access_levels_for_ref
(
ref
,
action:
action
).
any?
do
|
access_level
|
access_level
.
access_level
==
Gitlab
::
Access
::
DEVELOPER
end
end
def
self
.
access_levels_for_ref
(
ref
,
action
:)
def
access_levels_for_ref
(
ref
,
action
:)
self
.
matching
(
ref
).
map
(
&
:"
#{
action
}
_access_levels"
).
flatten
end
def
self
.
matching
(
ref_name
,
protected_refs:
nil
)
def
matching
(
ref_name
,
protected_refs:
nil
)
ProtectedRefMatcher
.
matching
(
self
,
ref_name
,
protected_refs:
protected_refs
)
end
end
def
commit
project
.
commit
(
self
.
name
)
end
private
def
ref_matcher
...
...
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