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
8d7e07d0
Commit
8d7e07d0
authored
Oct 04, 2017
by
Toon Claes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Rename Gitlab::Database.readonly? to read_only?
parent
7746792a
Changes
31
Hide whitespace changes
Inline
Side-by-side
Showing
31 changed files
with
52 additions
and
52 deletions
+52
-52
app/controllers/admin/application_controller.rb
app/controllers/admin/application_controller.rb
+6
-6
app/controllers/boards/issues_controller.rb
app/controllers/boards/issues_controller.rb
+1
-1
app/controllers/projects/lfs_api_controller.rb
app/controllers/projects/lfs_api_controller.rb
+3
-3
app/controllers/projects/merge_requests/application_controller.rb
...rollers/projects/merge_requests/application_controller.rb
+1
-1
app/models/concerns/routable.rb
app/models/concerns/routable.rb
+1
-1
app/models/merge_request.rb
app/models/merge_request.rb
+1
-1
app/models/project.rb
app/models/project.rb
+2
-2
app/models/user.rb
app/models/user.rb
+3
-7
app/services/keys/last_used_service.rb
app/services/keys/last_used_service.rb
+1
-1
app/services/users/activity_service.rb
app/services/users/activity_service.rb
+1
-1
app/views/admin/geo_nodes/index.html.haml
app/views/admin/geo_nodes/index.html.haml
+1
-1
doc/development/geo.md
doc/development/geo.md
+1
-1
ee/app/controllers/ee/admin/application_controller.rb
ee/app/controllers/ee/admin/application_controller.rb
+1
-1
ee/app/controllers/ee/projects/lfs_api_controller.rb
ee/app/controllers/ee/projects/lfs_api_controller.rb
+1
-1
ee/lib/ee/gitlab/database.rb
ee/lib/ee/gitlab/database.rb
+1
-1
lib/banzai/renderer.rb
lib/banzai/renderer.rb
+1
-1
lib/gitlab/database.rb
lib/gitlab/database.rb
+6
-1
lib/gitlab/git_access.rb
lib/gitlab/git_access.rb
+1
-1
lib/gitlab/git_access_wiki.rb
lib/gitlab/git_access_wiki.rb
+3
-3
lib/gitlab/middleware/readonly.rb
lib/gitlab/middleware/readonly.rb
+1
-1
spec/ee/spec/models/ee/user_spec.rb
spec/ee/spec/models/ee/user_spec.rb
+2
-2
spec/ee/spec/services/ee/keys/last_used_service_spec.rb
spec/ee/spec/services/ee/keys/last_used_service_spec.rb
+1
-1
spec/lib/banzai/renderer_spec.rb
spec/lib/banzai/renderer_spec.rb
+1
-1
spec/lib/gitlab/geo_spec.rb
spec/lib/gitlab/geo_spec.rb
+1
-1
spec/lib/gitlab/git_access_spec.rb
spec/lib/gitlab/git_access_spec.rb
+1
-1
spec/lib/gitlab/git_access_wiki_spec.rb
spec/lib/gitlab/git_access_wiki_spec.rb
+1
-1
spec/lib/gitlab/middleware/readonly_spec.rb
spec/lib/gitlab/middleware/readonly_spec.rb
+2
-2
spec/models/concerns/routable_spec.rb
spec/models/concerns/routable_spec.rb
+1
-1
spec/models/project_spec.rb
spec/models/project_spec.rb
+2
-2
spec/requests/lfs_http_spec.rb
spec/requests/lfs_http_spec.rb
+2
-3
spec/services/users/activity_service_spec.rb
spec/services/users/activity_service_spec.rb
+1
-1
No files found.
app/controllers/admin/application_controller.rb
View file @
8d7e07d0
...
...
@@ -3,23 +3,23 @@
# Automatically sets the layout and ensures an administrator is logged in
class
Admin::ApplicationController
<
ApplicationController
before_action
:authenticate_admin!
before_action
:display_readonly_information
before_action
:display_read
_
only_information
layout
'admin'
def
authenticate_admin!
render_404
unless
current_user
.
admin?
end
def
display_readonly_information
return
unless
Gitlab
::
Database
.
readonly?
def
display_read
_
only_information
return
unless
Gitlab
::
Database
.
read
_
only?
flash
.
now
[
:notice
]
=
readonly_message
flash
.
now
[
:notice
]
=
read
_
only_message
end
private
# Overridden in EE
def
readonly_message
_
(
'You are on a read-only GitLab instance.'
)
.
html_safe
def
read
_
only_message
_
(
'You are on a read-only GitLab instance.'
)
end
end
app/controllers/boards/issues_controller.rb
View file @
8d7e07d0
...
...
@@ -12,7 +12,7 @@ module Boards
def
index
issues
=
Boards
::
Issues
::
ListService
.
new
(
board_parent
,
current_user
,
filter_params
).
execute
issues
=
issues
.
page
(
params
[
:page
]).
per
(
params
[
:per
]
||
20
)
make_sure_position_is_set
(
issues
)
unless
Gitlab
::
Database
.
readonly
?
make_sure_position_is_set
(
issues
)
if
Gitlab
::
Database
.
read_write
?
issues
=
issues
.
preload
(
:project
,
:milestone
,
:assignees
,
...
...
app/controllers/projects/lfs_api_controller.rb
View file @
8d7e07d0
...
...
@@ -98,10 +98,10 @@ class Projects::LfsApiController < Projects::GitHttpClientController
end
def
lfs_check_batch_operation!
if
upload_request?
&&
Gitlab
::
Database
.
readonly?
if
upload_request?
&&
Gitlab
::
Database
.
read
_
only?
render
(
json:
{
message:
lfs_readonly_message
message:
lfs_read
_
only_message
},
content_type:
'application/vnd.git-lfs+json'
,
status:
403
...
...
@@ -110,7 +110,7 @@ class Projects::LfsApiController < Projects::GitHttpClientController
end
# Overridden in EE
def
lfs_readonly_message
def
lfs_read
_
only_message
_
(
'You cannot write to this read-only GitLab instance.'
)
end
end
app/controllers/projects/merge_requests/application_controller.rb
View file @
8d7e07d0
...
...
@@ -15,7 +15,7 @@ class Projects::MergeRequests::ApplicationController < Projects::ApplicationCont
# Make sure merge requests created before 8.0
# have head file in refs/merge-requests/
def
ensure_ref_fetched
@merge_request
.
ensure_ref_fetched
unless
Gitlab
::
Database
.
readonly
?
@merge_request
.
ensure_ref_fetched
if
Gitlab
::
Database
.
read_write
?
end
def
merge_request_params
...
...
app/models/concerns/routable.rb
View file @
8d7e07d0
...
...
@@ -152,7 +152,7 @@ module Routable
end
def
update_route
return
if
Gitlab
::
Database
.
readonly?
return
if
Gitlab
::
Database
.
read
_
only?
prepare_route
route
.
save
...
...
app/models/merge_request.rb
View file @
8d7e07d0
...
...
@@ -498,7 +498,7 @@ class MergeRequest < ActiveRecord::Base
end
def
check_if_can_be_merged
return
unless
unchecked?
&&
!
Gitlab
::
Database
.
readonly
?
return
unless
unchecked?
&&
Gitlab
::
Database
.
read_write
?
can_be_merged
=
!
broken?
&&
project
.
repository
.
can_be_merged?
(
diff_head_sha
,
target_branch
)
...
...
app/models/project.rb
View file @
8d7e07d0
...
...
@@ -811,7 +811,7 @@ class Project < ActiveRecord::Base
end
def
cache_has_external_issue_tracker
update_column
(
:has_external_issue_tracker
,
services
.
external_issue_trackers
.
any?
)
unless
Gitlab
::
Database
.
readonly
?
update_column
(
:has_external_issue_tracker
,
services
.
external_issue_trackers
.
any?
)
if
Gitlab
::
Database
.
read_write
?
end
def
has_wiki?
...
...
@@ -831,7 +831,7 @@ class Project < ActiveRecord::Base
end
def
cache_has_external_wiki
update_column
(
:has_external_wiki
,
services
.
external_wikis
.
any?
)
unless
Gitlab
::
Database
.
readonly
?
update_column
(
:has_external_wiki
,
services
.
external_wikis
.
any?
)
if
Gitlab
::
Database
.
read_write
?
end
def
find_or_initialize_services
(
exceptions:
[])
...
...
app/models/user.rb
View file @
8d7e07d0
...
...
@@ -478,15 +478,11 @@ class User < ActiveRecord::Base
end
def
remember_me!
raise
NotImplementedError
unless
defined?
(
super
)
super
unless
::
Gitlab
::
Database
.
readonly?
super
if
::
Gitlab
::
Database
.
read_write?
end
def
forget_me!
raise
NotImplementedError
unless
defined?
(
super
)
super
unless
::
Gitlab
::
Database
.
readonly?
super
if
::
Gitlab
::
Database
.
read_write?
end
def
disable_two_factor!
...
...
@@ -1079,7 +1075,7 @@ class User < ActiveRecord::Base
# we do this on read since migrating all existing users is not a feasible
# solution.
def
rss_token
return
read_attribute
(
:rss_token
)
if
Gitlab
::
Database
.
readonly?
return
read_attribute
(
:rss_token
)
if
Gitlab
::
Database
.
read
_
only?
ensure_rss_token!
end
...
...
app/services/keys/last_used_service.rb
View file @
8d7e07d0
...
...
@@ -16,7 +16,7 @@ module Keys
end
def
update?
return
false
if
::
Gitlab
::
Database
.
readonly?
return
false
if
::
Gitlab
::
Database
.
read
_
only?
last_used
=
key
.
last_used_at
...
...
app/services/users/activity_service.rb
View file @
8d7e07d0
...
...
@@ -14,7 +14,7 @@ module Users
private
def
record_activity
Gitlab
::
UserActivities
.
record
(
@author
.
id
)
unless
Gitlab
::
Database
.
readonly
?
Gitlab
::
UserActivities
.
record
(
@author
.
id
)
if
Gitlab
::
Database
.
read_write
?
Rails
.
logger
.
debug
(
"Recorded activity:
#{
@activity
}
for User ID:
#{
@author
.
id
}
(username:
#{
@author
.
username
}
)"
)
end
...
...
app/views/admin/geo_nodes/index.html.haml
View file @
8d7e07d0
...
...
@@ -84,7 +84,7 @@
%p
.js-health
-
unless
Gitlab
::
Database
.
readonly
?
-
if
Gitlab
::
Database
.
read_write
?
.node-actions
-
if
Gitlab
::
Geo
.
license_allows?
-
if
node
.
missing_oauth_application?
...
...
doc/development/geo.md
View file @
8d7e07d0
...
...
@@ -89,7 +89,7 @@ and prevent user from trying to update the database and getting a 500 error
Database will already be read-only in a replicated setup, so we don't need to
take any extra step for that.
We do use our feature toggle
`Gitlab::Database.readonly?`
to deny write operations
We do use our feature toggle
`Gitlab::Database.read
_
only?`
to deny write operations
on a node that is in read-only mode. This toggle is also available in CE.
## File Transfers
...
...
ee/app/controllers/application_controller.rb
→
ee/app/controllers/
ee/admin/
application_controller.rb
View file @
8d7e07d0
module
EE
module
Admin
module
ApplicationController
def
readonly_message
def
read
_
only_message
raise
NotImplementedError
unless
defined?
(
super
)
return
super
unless
Gitlab
::
Geo
.
secondary_with_primary?
...
...
ee/app/controllers/ee/projects/lfs_api_controller.rb
View file @
8d7e07d0
module
EE
module
Projects
module
LfsApiController
def
lfs_readonly_message
def
lfs_read
_
only_message
raise
NotImplementedError
unless
defined?
(
super
)
return
super
unless
::
Gitlab
::
Geo
.
secondary_with_primary?
...
...
ee/lib/ee/gitlab/database.rb
View file @
8d7e07d0
module
EE
module
Gitlab
module
Database
def
self
.
readonly?
def
self
.
read
_
only?
raise
NotImplementedError
unless
defined?
(
super
)
Gitlab
::
Geo
.
secondary?
||
super
...
...
lib/banzai/renderer.rb
View file @
8d7e07d0
...
...
@@ -165,7 +165,7 @@ module Banzai
# GitLab needs to disable updates on GET requests if database is readonly
def
self
.
update_object?
(
object
)
!
Gitlab
::
Database
.
readonly
?
Gitlab
::
Database
.
read_write
?
end
end
end
lib/gitlab/database.rb
View file @
8d7e07d0
...
...
@@ -31,10 +31,15 @@ module Gitlab
adapter_name
.
casecmp
(
'postgresql'
).
zero?
end
def
self
.
readonly?
# Overridden in EE
def
self
.
read_only?
false
end
def
self
.
read_write?
!
self
.
read_only?
end
def
self
.
version
database_version
.
match
(
/\A(?:PostgreSQL |)([^\s]+).*\z/
)[
1
]
end
...
...
lib/gitlab/git_access.rb
View file @
8d7e07d0
...
...
@@ -176,7 +176,7 @@ module Gitlab
raise
UnauthorizedError
,
ERROR_MESSAGES
[
:readonly
]
end
if
Gitlab
::
Database
.
readonly?
if
Gitlab
::
Database
.
read
_
only?
raise
UnauthorizedError
,
ERROR_MESSAGES
[
:cannot_push_to_readonly
]
end
...
...
lib/gitlab/git_access_wiki.rb
View file @
8d7e07d0
module
Gitlab
class
GitAccessWiki
<
GitAccess
ERROR_MESSAGES
=
{
read
only:
"You can't push code to this
read-only GitLab instance."
,
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."
}.
freeze
...
...
@@ -18,8 +18,8 @@ module Gitlab
raise
UnauthorizedError
,
ERROR_MESSAGES
[
:write_to_wiki
]
end
if
Gitlab
::
Geo
.
enabled?
&&
Gitlab
::
Database
.
read
only?
raise
UnauthorizedError
,
ERROR_MESSAGES
[
:readonly
]
if
Gitlab
::
Database
.
read_
only?
raise
UnauthorizedError
,
ERROR_MESSAGES
[
:read
_
only
]
end
true
...
...
lib/gitlab/middleware/readonly.rb
View file @
8d7e07d0
...
...
@@ -13,7 +13,7 @@ module Gitlab
def
call
(
env
)
@env
=
env
if
disallowed_request?
&&
Gitlab
::
Database
.
readonly?
if
disallowed_request?
&&
Gitlab
::
Database
.
read
_
only?
Rails
.
logger
.
debug
(
'GitLab Readonly: preventing possible non readonly operation'
)
error_message
=
'You cannot do writing operations on a read-only GitLab instance'
...
...
spec/ee/spec/models/ee/user_spec.rb
View file @
8d7e07d0
...
...
@@ -84,7 +84,7 @@ describe EE::User do
end
it
'does not clear remember_created_at when in a GitLab readonly instance'
do
allow
(
Gitlab
::
Database
).
to
receive
(
:readonly?
)
{
true
}
allow
(
Gitlab
::
Database
).
to
receive
(
:read
_
only?
)
{
true
}
expect
{
subject
.
forget_me!
}.
not_to
change
(
subject
,
:remember_created_at
)
end
...
...
@@ -100,7 +100,7 @@ describe EE::User do
end
it
'does not update remember_created_at when in a Geo readonly instance'
do
allow
(
Gitlab
::
Database
).
to
receive
(
:readonly?
)
{
true
}
allow
(
Gitlab
::
Database
).
to
receive
(
:read
_
only?
)
{
true
}
expect
{
subject
.
remember_me!
}.
not_to
change
(
subject
,
:remember_created_at
)
end
...
...
spec/ee/spec/services/ee/keys/last_used_service_spec.rb
View file @
8d7e07d0
...
...
@@ -5,7 +5,7 @@ describe Keys::LastUsedService do
key
=
create
(
:key
,
last_used_at:
1
.
year
.
ago
)
original_time
=
key
.
last_used_at
allow
(
::
Gitlab
::
Database
).
to
receive
(
:readonly?
).
and_return
(
true
)
allow
(
::
Gitlab
::
Database
).
to
receive
(
:read
_
only?
).
and_return
(
true
)
described_class
.
new
(
key
).
execute
expect
(
key
.
reload
.
last_used_at
).
to
be_like_time
(
original_time
)
...
...
spec/lib/banzai/renderer_spec.rb
View file @
8d7e07d0
...
...
@@ -37,7 +37,7 @@ describe Banzai::Renderer do
end
it
"skips database caching on a GitLab readonly instance"
do
allow
(
Gitlab
::
Database
).
to
receive
(
:readonly?
).
and_return
(
true
)
allow
(
Gitlab
::
Database
).
to
receive
(
:read
_
only?
).
and_return
(
true
)
expect
(
object
).
to
receive
(
:refresh_markdown_cache!
).
with
(
do_update:
false
)
is_expected
.
to
eq
(
'field_html'
)
...
...
spec/lib/gitlab/geo_spec.rb
View file @
8d7e07d0
...
...
@@ -110,7 +110,7 @@ describe Gitlab::Geo do
end
end
describe
'
readonl
y?'
do
describe
'
secondar
y?'
do
context
'when current node is secondary'
do
it
'returns true'
do
stub_current_geo_node
(
secondary_node
)
...
...
spec/lib/gitlab/git_access_spec.rb
View file @
8d7e07d0
...
...
@@ -747,7 +747,7 @@ describe Gitlab::GitAccess do
context
"when in a read-only GitLab instance"
do
before
do
create
(
:protected_branch
,
name:
'feature'
,
project:
project
)
allow
(
Gitlab
::
Database
).
to
receive
(
:readonly?
)
{
true
}
allow
(
Gitlab
::
Database
).
to
receive
(
:read
_
only?
)
{
true
}
end
# Only check admin; if an admin can't do it, other roles can't either
...
...
spec/lib/gitlab/git_access_wiki_spec.rb
View file @
8d7e07d0
...
...
@@ -27,7 +27,7 @@ describe Gitlab::GitAccessWiki do
context
'when in a read-only GitLab instance'
do
before
do
allow
(
Gitlab
::
Database
).
to
receive
(
:readonly?
)
{
true
}
allow
(
Gitlab
::
Database
).
to
receive
(
:read
_
only?
)
{
true
}
end
it
'does not give access to upload wiki code'
do
...
...
spec/lib/gitlab/middleware/readonly_spec.rb
View file @
8d7e07d0
...
...
@@ -42,7 +42,7 @@ describe Gitlab::Middleware::Readonly do
let
(
:fake_app
)
{
lambda
{
|
env
|
[
200
,
{
'Content-Type'
=>
'text/plain'
},
[
'OK'
]]
}
}
before
do
allow
(
Gitlab
::
Database
).
to
receive
(
:readonly?
)
{
true
}
allow
(
Gitlab
::
Database
).
to
receive
(
:read
_
only?
)
{
true
}
end
it
'expects PATCH requests to be disallowed'
do
...
...
@@ -112,7 +112,7 @@ describe Gitlab::Middleware::Readonly do
let
(
:content_json
)
{
{
'CONTENT_TYPE'
=>
'application/json'
}
}
before
do
allow
(
Gitlab
::
Database
).
to
receive
(
:readonly?
)
{
true
}
allow
(
Gitlab
::
Database
).
to
receive
(
:read
_
only?
)
{
true
}
end
it
'expects PATCH requests to be disallowed'
do
...
...
spec/models/concerns/routable_spec.rb
View file @
8d7e07d0
...
...
@@ -15,7 +15,7 @@ describe Group, 'Routable' do
describe
'GitLab read-only instance'
do
it
'does not save route if route is not present'
do
group
.
route
.
path
=
''
allow
(
Gitlab
::
Database
).
to
receive
(
:readonly?
).
and_return
(
true
)
allow
(
Gitlab
::
Database
).
to
receive
(
:read
_
only?
).
and_return
(
true
)
expect
(
group
).
to
receive
(
:update_route
).
and_call_original
expect
{
group
.
full_path
}.
to
change
{
Route
.
count
}.
by
(
0
)
...
...
spec/models/project_spec.rb
View file @
8d7e07d0
...
...
@@ -823,7 +823,7 @@ describe Project do
end
it
'does not cache data when in a read-only GitLab instance'
do
allow
(
Gitlab
::
Database
).
to
receive
(
:readonly?
)
{
true
}
allow
(
Gitlab
::
Database
).
to
receive
(
:read
_
only?
)
{
true
}
expect
do
project
.
cache_has_external_issue_tracker
...
...
@@ -853,7 +853,7 @@ describe Project do
end
it
'does not cache data when in a read-only GitLab instance'
do
allow
(
Gitlab
::
Database
).
to
receive
(
:readonly?
)
{
true
}
allow
(
Gitlab
::
Database
).
to
receive
(
:read
_
only?
)
{
true
}
expect
do
project
.
cache_has_external_wiki
...
...
spec/requests/lfs_http_spec.rb
View file @
8d7e07d0
...
...
@@ -877,8 +877,7 @@ describe 'Git LFS API and storage' do
end
end
describe
'when handling lfs batch request on a secondary Geo node'
do
let!
(
:primary
)
{
create
(
:geo_node
,
:primary
)
}
describe
'when handling lfs batch request on a read-only GitLab instance'
do
let
(
:authorization
)
{
authorize_user
}
let
(
:project
)
{
create
(
:project
)
}
let
(
:path
)
{
"
#{
project
.
http_url_to_repo
}
/info/lfs/objects/batch"
}
...
...
@@ -887,7 +886,7 @@ describe 'Git LFS API and storage' do
end
before
do
allow
(
Gitlab
::
Database
).
to
receive
(
:readonly?
)
{
true
}
allow
(
Gitlab
::
Database
).
to
receive
(
:read
_
only?
)
{
true
}
project
.
team
<<
[
user
,
:master
]
enable_lfs
end
...
...
spec/services/users/activity_service_spec.rb
View file @
8d7e07d0
...
...
@@ -41,7 +41,7 @@ describe Users::ActivityService do
context
'when in GitLab read-only instance'
do
before
do
allow
(
Gitlab
::
Database
).
to
receive
(
:readonly?
).
and_return
(
true
)
allow
(
Gitlab
::
Database
).
to
receive
(
:read
_
only?
).
and_return
(
true
)
end
it
'does not update last_activity_at'
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