2018-10-22 03:00:50 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2014-10-07 09:05:24 -04:00
|
|
|
module Gitlab
|
|
|
|
class GitAccessWiki < GitAccess
|
2020-07-21 14:09:45 -04:00
|
|
|
extend ::Gitlab::Utils::Override
|
2020-05-22 17:08:22 -04:00
|
|
|
|
2017-05-15 19:13:36 -04:00
|
|
|
ERROR_MESSAGES = {
|
2020-07-21 14:09:45 -04:00
|
|
|
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.",
|
2017-05-15 19:13:36 -04:00
|
|
|
write_to_wiki: "You are not allowed to write to this project's wiki."
|
|
|
|
}.freeze
|
|
|
|
|
2020-10-05 11:08:56 -04:00
|
|
|
override :project
|
|
|
|
def project
|
|
|
|
container.project if container.is_a?(ProjectWiki)
|
|
|
|
end
|
|
|
|
|
2020-07-21 14:09:45 -04:00
|
|
|
override :download_ability
|
|
|
|
def download_ability
|
|
|
|
:download_wiki_code
|
2016-11-29 13:59:25 -05:00
|
|
|
end
|
|
|
|
|
2020-07-21 14:09:45 -04:00
|
|
|
override :push_ability
|
|
|
|
def push_ability
|
|
|
|
:create_wiki
|
2016-11-29 13:59:25 -05:00
|
|
|
end
|
|
|
|
|
2020-07-21 14:09:45 -04:00
|
|
|
override :check_change_access!
|
2018-12-20 11:40:56 -05:00
|
|
|
def check_change_access!
|
2020-07-21 14:09:45 -04:00
|
|
|
raise ForbiddenError, write_to_wiki_message unless user_can_push?
|
2017-09-19 03:44:58 -04:00
|
|
|
|
2017-05-23 15:21:57 -04:00
|
|
|
true
|
2014-10-07 09:05:24 -04:00
|
|
|
end
|
2017-12-07 11:13:40 -05:00
|
|
|
|
|
|
|
def push_to_read_only_message
|
2020-07-21 14:09:45 -04:00
|
|
|
error_message(:read_only)
|
2017-12-07 11:13:40 -05:00
|
|
|
end
|
2018-02-21 19:20:30 -05:00
|
|
|
|
2020-07-21 14:09:45 -04:00
|
|
|
def write_to_wiki_message
|
|
|
|
error_message(:write_to_wiki)
|
|
|
|
end
|
2020-05-22 17:08:22 -04:00
|
|
|
|
2020-07-21 14:09:45 -04:00
|
|
|
def not_found_message
|
|
|
|
error_message(:not_found)
|
|
|
|
end
|
2014-10-07 09:05:24 -04:00
|
|
|
end
|
|
|
|
end
|
2020-07-21 14:09:45 -04:00
|
|
|
|
|
|
|
Gitlab::GitAccessWiki.prepend_if_ee('EE::Gitlab::GitAccessWiki')
|