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
903aab5f
Commit
903aab5f
authored
Dec 04, 2017
by
James Lopez
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor wiki and added spec
parent
c8321792
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
76 additions
and
1 deletion
+76
-1
ee/lib/ee/gitlab/geo_git_access.rb
ee/lib/ee/gitlab/geo_git_access.rb
+20
-0
lib/gitlab/git_access_wiki.rb
lib/gitlab/git_access_wiki.rb
+7
-1
spec/ee/spec/lib/ee/gitlab/git_access_wiki_spec.rb
spec/ee/spec/lib/ee/gitlab/git_access_wiki_spec.rb
+49
-0
No files found.
ee/lib/ee/gitlab/geo_git_access.rb
0 → 100644
View file @
903aab5f
module
EE
module
Gitlab
module
GeoGitAccess
GEO_SERVER_DOCS_URL
=
'https://docs.gitlab.com/ee/gitlab-geo/using_a_geo_server.html'
.
freeze
private
def
push_to_read_only_message
message
=
super
if
::
Gitlab
::
Geo
.
primary_node
primary_url
=
ActionController
::
Base
.
helpers
.
link_to
(
'primary node'
,
::
Gitlab
::
Geo
.
primary_node
.
url
)
message
+=
" Please use the Primary node URL:
#{
primary_url
.
html_safe
}
. Documentation:
#{
GEO_SERVER_DOCS_URL
}
"
end
message
end
end
end
end
lib/gitlab/git_access_wiki.rb
View file @
903aab5f
module
Gitlab
class
GitAccessWiki
<
GitAccess
prepend
EE
::
Gitlab
::
GeoGitAccess
ERROR_MESSAGES
=
{
read_only:
"You can't push code to a read-only GitLab instance."
,
write_to_wiki:
"You are not allowed to write to this project's wiki."
...
...
@@ -19,10 +21,14 @@ module Gitlab
end
if
Gitlab
::
Database
.
read_only?
raise
UnauthorizedError
,
ERROR_MESSAGES
[
:read_only
]
raise
UnauthorizedError
,
push_to_read_only_message
end
true
end
def
push_to_read_only_message
ERROR_MESSAGES
[
:read_only
]
end
end
end
spec/ee/spec/lib/ee/gitlab/git_access_wiki_spec.rb
0 → 100644
View file @
903aab5f
require
'spec_helper'
describe
Gitlab
::
GitAccessWiki
do
let
(
:access
)
{
described_class
.
new
(
user
,
project
,
'web'
,
authentication_abilities:
authentication_abilities
,
redirected_path:
redirected_path
)
}
let
(
:project
)
{
create
(
:project
,
:repository
)
}
let
(
:user
)
{
create
(
:user
)
}
let
(
:changes
)
{
[
'6f6d7e7ed 570e7b2ab refs/heads/master'
]
}
let
(
:redirected_path
)
{
nil
}
let
(
:authentication_abilities
)
do
[
:read_project
,
:download_code
,
:push_code
]
end
subject
{
access
.
check
(
'git-receive-pack'
,
changes
)
}
context
"when in a read-only GitLab instance"
do
before
do
create
(
:protected_branch
,
name:
'feature'
,
project:
project
)
allow
(
Gitlab
::
Database
).
to
receive
(
:read_only?
)
{
true
}
end
it
'denies push access'
do
project
.
add_master
(
user
)
expect
{
subject
}.
to
raise_unauthorized
(
"You can't push code to a read-only GitLab instance."
)
end
it
'denies push access with primary present'
do
error_message
=
"You can't push code to a read-only GitLab instance. Please use the Primary node URL:"
\
" <a href=
\"
https://localhost:3000/gitlab/
\"
>primary node</a>. Documentation: https://docs.gitlab.com/ee/gitlab-geo/using_a_geo_server.html"
primary_node
=
create
(
:geo_node
,
:primary
,
url:
'https://localhost:3000/gitlab'
)
allow
(
Gitlab
::
Geo
).
to
receive
(
:primary
).
and_return
(
primary_node
)
project
.
add_master
(
user
)
expect
{
subject
}.
to
raise_unauthorized
(
error_message
)
end
end
private
def
raise_unauthorized
(
message
)
raise_error
(
Gitlab
::
GitAccess
::
UnauthorizedError
,
message
)
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