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
7560abb3
Commit
7560abb3
authored
Feb 20, 2016
by
Gabriel Mazetto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Prevent git push on secondary geo nodes.
parent
77456854
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
48 additions
and
11 deletions
+48
-11
lib/gitlab/git_access.rb
lib/gitlab/git_access.rb
+4
-0
lib/gitlab/git_access_wiki.rb
lib/gitlab/git_access_wiki.rb
+3
-1
spec/lib/gitlab/git_access_spec.rb
spec/lib/gitlab/git_access_spec.rb
+22
-0
spec/lib/gitlab/git_access_wiki_spec.rb
spec/lib/gitlab/git_access_wiki_spec.rb
+19
-10
No files found.
lib/gitlab/git_access.rb
View file @
7560abb3
...
...
@@ -113,6 +113,10 @@ module Gitlab
return
build_status_object
(
false
,
"A repository for this project does not exist yet."
)
end
if
Gitlab
::
Geo
.
enabled?
&&
Gitlab
::
Geo
.
readonly?
return
build_status_object
(
false
,
"You can't push code on a secondary Gitlab Geo node."
)
end
if
::
License
.
block_changes?
message
=
::
LicenseHelper
.
license_message
(
signed_in:
true
,
is_admin:
(
user
&&
user
.
is_admin?
))
return
build_status_object
(
false
,
message
)
...
...
lib/gitlab/git_access_wiki.rb
View file @
7560abb3
module
Gitlab
class
GitAccessWiki
<
GitAccess
def
change_access_check
(
change
)
if
user
.
can?
(
:create_wiki
,
project
)
if
Gitlab
::
Geo
.
enabled?
&&
Gitlab
::
Geo
.
readonly?
build_status_object
(
false
,
"You can't push code on a secondary Gitlab Geo node."
)
elsif
user
.
can?
(
:create_wiki
,
project
)
build_status_object
(
true
)
else
build_status_object
(
false
,
"You are not allowed to write to this project's wiki."
)
...
...
spec/lib/gitlab/git_access_spec.rb
View file @
7560abb3
...
...
@@ -249,6 +249,28 @@ describe Gitlab::GitAccess, lib: true do
end
end
context
"when in a readonly gitlab geo node"
do
before
do
allow
(
Gitlab
::
Geo
).
to
receive
(
:enabled?
)
{
true
}
allow
(
Gitlab
::
Geo
).
to
receive
(
:readonly?
)
{
true
}
end
permissions_matrix
.
keys
.
each
do
|
role
|
describe
"
#{
role
}
access"
do
before
{
protect_feature_branch
}
before
{
project
.
team
<<
[
user
,
role
]
}
permissions_matrix
[
role
].
each
do
|
action
,
allowed
|
context
action
do
subject
{
access
.
push_access_check
(
changes
[
action
])
}
it
{
expect
(
subject
.
allowed?
).
to
be_falsey
}
end
end
end
end
end
context
"when using git annex"
do
before
{
project
.
team
<<
[
user
,
:master
]
}
...
...
spec/lib/gitlab/git_access_wiki_spec.rb
View file @
7560abb3
...
...
@@ -4,19 +4,28 @@ describe Gitlab::GitAccessWiki, lib: true do
let
(
:access
)
{
Gitlab
::
GitAccessWiki
.
new
(
user
,
project
)
}
let
(
:project
)
{
create
(
:project
)
}
let
(
:user
)
{
create
(
:user
)
}
let
(
:changes
)
{
[
'6f6d7e7ed 570e7b2ab refs/heads/master'
]
}
describe
'push_allowed?'
do
before
do
create
(
:protected_branch
,
name:
'master'
,
project:
project
)
project
.
team
<<
[
user
,
:developer
]
end
describe
'#push_access_check'
do
context
'when user can :create_wiki'
do
before
do
create
(
:protected_branch
,
name:
'master'
,
project:
project
)
project
.
team
<<
[
user
,
:developer
]
end
subject
{
access
.
push_access_check
(
changes
)
}
subject
{
access
.
push_access_check
(
changes
)
}
it
{
expect
(
subject
.
allowed?
).
to
be_truthy
}
end
it
{
expect
(
subject
.
allowed?
).
to
be_truthy
}
context
'when in a readonly gitlab geo node'
do
before
do
allow
(
Gitlab
::
Geo
).
to
receive
(
:enabled?
)
{
true
}
allow
(
Gitlab
::
Geo
).
to
receive
(
:readonly?
)
{
true
}
end
it
{
expect
(
subject
.
allowed?
).
to
be_falsey
}
end
end
def
changes
[
'6f6d7e7ed 570e7b2ab refs/heads/master'
]
end
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