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
19c7851c
Commit
19c7851c
authored
Oct 10, 2017
by
Rubén Dávila
Committed by
Bob Van Landuyt
Nov 02, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add ability to dynamically define settings with a global default
parent
1fb2aa4b
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
26 additions
and
23 deletions
+26
-23
app/models/push_rule.rb
app/models/push_rule.rb
+26
-23
No files found.
app/models/push_rule.rb
View file @
19c7851c
...
...
@@ -5,6 +5,32 @@ class PushRule < ActiveRecord::Base
validates
:max_file_size
,
numericality:
{
greater_than_or_equal_to:
0
,
only_integer:
true
}
FILES_BLACKLIST
=
YAML
.
load_file
(
Rails
.
root
.
join
(
'lib/gitlab/checks/files_blacklist.yml'
))
SETTINGS_WITH_GLOBAL_DEFAULT
=
%i[reject_unsigned_commits commit_author_check]
.
freeze
SETTINGS_WITH_GLOBAL_DEFAULT
.
each
do
|
setting
|
define_method
(
setting
)
do
value
=
super
()
# return if value is true/false or if current object is the global setting
return
value
if
global?
||
!
value
.
nil?
PushRule
.
global
&
.
public_send
(
setting
)
end
alias_method
"
#{
setting
}
?"
,
setting
define_method
(
"
#{
setting
}
="
)
do
|
value
|
enabled_globally
=
PushRule
.
global
&
.
public_send
(
setting
)
is_disabled
=
!
Gitlab
::
Utils
.
to_boolean
(
value
)
# If setting is globally disabled and user disable it at project level,
# reset the attr so we can use the default global if required later.
if
!
enabled_globally
&&
is_disabled
super
(
nil
)
else
super
(
value
)
end
end
end
def
self
.
global
find_by
(
is_sample:
true
)
...
...
@@ -48,29 +74,6 @@ class PushRule < ActiveRecord::Base
regex_list
.
find
{
|
regex
|
data_match?
(
file_path
,
regex
)
}
end
def
reject_unsigned_commits
=
(
value
)
enabled_globally
=
PushRule
.
global
&
.
reject_unsigned_commits
is_disabled
=
!
Gitlab
::
Utils
.
to_boolean
(
value
)
# If setting is globally disabled and user disable it at project level,
# reset the attr so we can use the default global if required later.
if
!
enabled_globally
&&
is_disabled
super
(
nil
)
else
super
(
value
)
end
end
def
reject_unsigned_commits
value
=
super
# return if value is true/false or if current object is the global setting
return
value
if
global?
||
!
value
.
nil?
PushRule
.
global
&
.
reject_unsigned_commits
end
alias_method
:reject_unsigned_commits?
,
:reject_unsigned_commits
def
global?
is_sample?
end
...
...
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