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
ce8e273a
Commit
ce8e273a
authored
Oct 14, 2017
by
Rubén Dávila
Committed by
Bob Van Landuyt
Nov 02, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Check commit author for regular commits
parent
c9caccd9
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
31 additions
and
0 deletions
+31
-0
app/models/push_rule.rb
app/models/push_rule.rb
+1
-0
lib/gitlab/checks/change_access.rb
lib/gitlab/checks/change_access.rb
+6
-0
spec/lib/gitlab/checks/change_access_spec.rb
spec/lib/gitlab/checks/change_access_spec.rb
+24
-0
No files found.
app/models/push_rule.rb
View file @
ce8e273a
...
@@ -44,6 +44,7 @@ class PushRule < ActiveRecord::Base
...
@@ -44,6 +44,7 @@ class PushRule < ActiveRecord::Base
branch_name_regex
.
present?
||
branch_name_regex
.
present?
||
author_email_regex
.
present?
||
author_email_regex
.
present?
||
reject_unsigned_commits
||
reject_unsigned_commits
||
commit_author_check
||
member_check
||
member_check
||
file_name_regex
.
present?
||
file_name_regex
.
present?
||
max_file_size
>
0
||
max_file_size
>
0
||
...
...
lib/gitlab/checks/change_access.rb
View file @
ce8e273a
...
@@ -230,6 +230,12 @@ module Gitlab
...
@@ -230,6 +230,12 @@ module Gitlab
end
end
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
nil
end
end
...
...
spec/lib/gitlab/checks/change_access_spec.rb
View file @
ce8e273a
...
@@ -440,6 +440,30 @@ describe Gitlab::Checks::ChangeAccess do
...
@@ -440,6 +440,30 @@ describe Gitlab::Checks::ChangeAccess do
end
end
end
end
end
end
context
'Check commit author rules'
do
let
(
:push_rule
)
{
create
(
:push_rule
,
commit_author_check:
true
)
}
context
'with a commit from the authenticated user'
do
before
do
allow_any_instance_of
(
Commit
).
to
receive
(
:committer_email
).
and_return
(
user
.
email
)
end
it
'does not return an error'
do
expect
{
subject
}.
not_to
raise_error
end
end
context
'with a commit from a different user'
do
before
do
allow_any_instance_of
(
Commit
).
to
receive
(
:committer_email
).
and_return
(
'some@mail.com'
)
end
it
'returns an error'
do
expect
{
subject
}.
to
raise_error
(
Gitlab
::
GitAccess
::
UnauthorizedError
,
"You can only push your own commits to this repository"
)
end
end
end
end
end
context
'file lock rules'
do
context
'file lock rules'
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