2018-12-13 13:39:08 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2015-04-26 12:48:37 +05:30
|
|
|
module Gitlab
|
|
|
|
class GitAccessWiki < GitAccess
|
2020-10-24 23:57:45 +05:30
|
|
|
extend ::Gitlab::Utils::Override
|
2020-06-23 00:09:42 +05:30
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
ERROR_MESSAGES = {
|
2020-10-24 23:57:45 +05:30
|
|
|
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-09-10 17:25:29 +05:30
|
|
|
write_to_wiki: "You are not allowed to write to this project's wiki."
|
|
|
|
}.freeze
|
|
|
|
|
2021-01-03 14:25:43 +05:30
|
|
|
override :project
|
|
|
|
def project
|
|
|
|
container.project if container.is_a?(ProjectWiki)
|
|
|
|
end
|
|
|
|
|
2020-10-24 23:57:45 +05:30
|
|
|
override :download_ability
|
|
|
|
def download_ability
|
|
|
|
:download_wiki_code
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
|
2020-10-24 23:57:45 +05:30
|
|
|
override :push_ability
|
|
|
|
def push_ability
|
|
|
|
:create_wiki
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
|
2022-07-23 23:45:48 +05:30
|
|
|
private
|
|
|
|
|
|
|
|
override :build_can_download?
|
|
|
|
def build_can_download?
|
|
|
|
super && user_access.can_do_action?(download_ability)
|
|
|
|
end
|
2021-12-07 22:27:20 +05:30
|
|
|
|
2022-07-23 23:45:48 +05:30
|
|
|
override :deploy_token_can_download?
|
|
|
|
def deploy_token_can_download?
|
|
|
|
super && deploy_token.can?(download_ability, container)
|
|
|
|
end
|
|
|
|
|
|
|
|
override :repository_access_level
|
|
|
|
def repository_access_level
|
|
|
|
project&.wiki_access_level
|
2021-12-07 22:27:20 +05:30
|
|
|
end
|
|
|
|
|
2020-10-24 23:57:45 +05:30
|
|
|
override :check_change_access!
|
2019-02-15 15:39:39 +05:30
|
|
|
def check_change_access!
|
2020-10-24 23:57:45 +05:30
|
|
|
raise ForbiddenError, write_to_wiki_message unless user_can_push?
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
true
|
2015-04-26 12:48:37 +05:30
|
|
|
end
|
2018-03-17 18:26:18 +05:30
|
|
|
|
|
|
|
def push_to_read_only_message
|
2020-10-24 23:57:45 +05:30
|
|
|
error_message(:read_only)
|
2018-03-17 18:26:18 +05:30
|
|
|
end
|
|
|
|
|
2020-10-24 23:57:45 +05:30
|
|
|
def write_to_wiki_message
|
|
|
|
error_message(:write_to_wiki)
|
|
|
|
end
|
2020-06-23 00:09:42 +05:30
|
|
|
|
2020-10-24 23:57:45 +05:30
|
|
|
def not_found_message
|
|
|
|
error_message(:not_found)
|
|
|
|
end
|
2015-04-26 12:48:37 +05:30
|
|
|
end
|
|
|
|
end
|
2020-10-24 23:57:45 +05:30
|
|
|
|
2021-06-08 01:23:25 +05:30
|
|
|
Gitlab::GitAccessWiki.prepend_mod_with('Gitlab::GitAccessWiki')
|