d13669716a
In GitLab EE, a GitLab instance can be read-only (e.g. when it's a Geo secondary node). But in GitLab CE it also might be useful to have the "read-only" idea around. So port it back to GitLab CE. Also having the principle of read-only in GitLab CE would hopefully lead to less errors introduced, doing write operations when there aren't allowed for read-only calls. Closes gitlab-org/gitlab-ce#37534.
28 lines
783 B
Ruby
28 lines
783 B
Ruby
module Gitlab
|
|
class GitAccessWiki < GitAccess
|
|
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."
|
|
}.freeze
|
|
|
|
def guest_can_download_code?
|
|
Guest.can?(:download_wiki_code, project)
|
|
end
|
|
|
|
def user_can_download_code?
|
|
authentication_abilities.include?(:download_code) && user_access.can_do_action?(:download_wiki_code)
|
|
end
|
|
|
|
def check_single_change_access(change)
|
|
unless user_access.can_do_action?(:create_wiki)
|
|
raise UnauthorizedError, ERROR_MESSAGES[:write_to_wiki]
|
|
end
|
|
|
|
if Gitlab::Database.read_only?
|
|
raise UnauthorizedError, ERROR_MESSAGES[:read_only]
|
|
end
|
|
|
|
true
|
|
end
|
|
end
|
|
end
|