This instance will be upgraded to Heptapod 0.20.1 on 2020-03-08 at 14:00 UTC+1 (10 minutes of downtime)

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

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 @@
module Gitlab
class HgAccessWiki < HgAccess
extend ::Gitlab::Utils::Override
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."
}.freeze
override :project
def project
container.project if container.is_a?(ProjectWiki)
end
override :download_ability
def download_ability
:download_wiki_code
......@@ -18,32 +27,14 @@ def push_ability
:create_wiki
end
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
override :check_change_access!
def check_change_access!
unless user_access.can_do_action?(:create_wiki)
raise UnauthorizedError, ERROR_MESSAGES[:write_to_wiki]
end
if Gitlab::Database.read_only?
raise UnauthorizedError, push_to_read_only_message
end
raise ForbiddenError, write_to_wiki_message unless user_can_push?
true
end
def user_can_push?
res = user_access.can_do_action?(:create_wiki) && !Gitlab::Database.read_only?
can_do = user_access.can_do_action?(:create_wiki)
res
end
override :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
# We don't distinguish between basic and publishing contributors.
......@@ -52,13 +43,15 @@ def user_allowed_to_push_can_also_publish?
end
def push_to_read_only_message
ERROR_MESSAGES[:read_only]
error_message(:read_only)
end
private
def write_to_wiki_message
error_message(:write_to_wiki)
end
def repository
project.wiki.repository
def not_found_message
error_message(:not_found)
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