Commit 98b5a532 authored by Georges Racinet's avatar Georges Racinet 🦑
Browse files

Wikis: resynced access class with upstream

The general move to the container concept broke this as well,
but that is largely compensated by the abstractions in the base
class that make the acess_wiki classes now simpler.

--HG--
branch : heptapod
parent 31e76cb6664e
...@@ -2,12 +2,21 @@ ...@@ -2,12 +2,21 @@
module Gitlab module Gitlab
class HgAccessWiki < HgAccess class HgAccessWiki < HgAccess
extend ::Gitlab::Utils::Override
ERROR_MESSAGES = { ERROR_MESSAGES = {
read_only: "You can't push code to a read-only GitLab instance.", download: 'You are not allowed to download files from this wiki.',
not_found: 'The wiki you were looking for could not be found.',
no_repo: 'A repository for this wiki does not exist yet.',
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." write_to_wiki: "You are not allowed to write to this project's wiki."
}.freeze }.freeze
override :project
def project
container.project if container.is_a?(ProjectWiki)
end
override :download_ability override :download_ability
def download_ability def download_ability
:download_wiki_code :download_wiki_code
...@@ -18,32 +27,14 @@ def push_ability ...@@ -18,32 +27,14 @@ def push_ability
:create_wiki :create_wiki
end end
def guest_can_download_code? override :check_change_access!
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_change_access! def check_change_access!
unless user_access.can_do_action?(:create_wiki) raise ForbiddenError, write_to_wiki_message unless user_can_push?
raise UnauthorizedError, ERROR_MESSAGES[:write_to_wiki]
end
if Gitlab::Database.read_only?
raise UnauthorizedError, push_to_read_only_message
end
true true
end end
def user_can_push? override :user_allowed_to_push_can_also_publish?
res = user_access.can_do_action?(:create_wiki) && !Gitlab::Database.read_only?
can_do = user_access.can_do_action?(:create_wiki)
res
end
def user_allowed_to_push_can_also_publish? def user_allowed_to_push_can_also_publish?
# Wikis are meant to have linear history directly in `default` branch # Wikis are meant to have linear history directly in `default` branch
# We don't distinguish between basic and publishing contributors. # We don't distinguish between basic and publishing contributors.
...@@ -52,13 +43,15 @@ def user_allowed_to_push_can_also_publish? ...@@ -52,13 +43,15 @@ def user_allowed_to_push_can_also_publish?
end end
def push_to_read_only_message def push_to_read_only_message
ERROR_MESSAGES[:read_only] error_message(:read_only)
end end
private def write_to_wiki_message
error_message(:write_to_wiki)
end
def repository def not_found_message
project.wiki.repository error_message(:not_found)
end end
end end
end end
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment