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
84358e6e
Commit
84358e6e
authored
Oct 24, 2017
by
Rubén Dávila
Committed by
Bob Van Landuyt
Nov 02, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move author validation to the PushRule model
parent
c80141dc
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
15 additions
and
6 deletions
+15
-6
app/models/push_rule.rb
app/models/push_rule.rb
+7
-0
lib/gitlab/checks/change_access.rb
lib/gitlab/checks/change_access.rb
+4
-6
spec/lib/gitlab/checks/change_access_spec.rb
spec/lib/gitlab/checks/change_access_spec.rb
+4
-0
No files found.
app/models/push_rule.rb
View file @
84358e6e
...
...
@@ -58,6 +58,13 @@ class PushRule < ActiveRecord::Base
commit
.
has_signature?
end
def
author_allowed?
(
committer_email
,
current_user_email
)
return
true
unless
available?
(
:commit_author_check
)
return
true
unless
commit_author_check
committer_email
.
casecmp
(
current_user_email
)
==
0
end
def
commit_message_allowed?
(
message
)
data_match?
(
message
,
commit_message_regex
)
end
...
...
lib/gitlab/checks/change_access.rb
View file @
84358e6e
...
...
@@ -213,6 +213,10 @@ module Gitlab
return
"Author's email '
#{
commit
.
author_email
}
' does not follow the pattern '
#{
push_rule
.
author_email_regex
}
'"
end
unless
push_rule
.
author_allowed?
(
commit
.
committer_email
,
user_access
.
user
.
email
)
return
"You can only push your own commits to this repository"
end
if
!
updated_from_web?
&&
!
push_rule
.
commit_signature_allowed?
(
commit
)
return
"Commit must be signed with a GPG key"
end
...
...
@@ -230,12 +234,6 @@ module Gitlab
end
end
if
push_rule
.
commit_author_check
unless
commit
.
committer_email
.
casecmp
(
user_access
.
user
.
email
)
==
0
return
"You can only push your own commits to this repository"
end
end
nil
end
...
...
spec/lib/gitlab/checks/change_access_spec.rb
View file @
84358e6e
...
...
@@ -442,6 +442,10 @@ describe Gitlab::Checks::ChangeAccess do
end
context
'Check commit author rules'
do
before
do
stub_licensed_features
(
commit_author_check:
true
)
end
let
(
:push_rule
)
{
create
(
:push_rule
,
commit_author_check:
true
)
}
context
'with a commit from the authenticated user'
do
...
...
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