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
|
2017-05-15 19:13:36 -04:00
|
|
|
ERROR_MESSAGES = {
|
2017-09-19 03:44:58 -04:00
|
|
|
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
|
|
|
|
|
2016-12-06 08:10:27 -05:00
|
|
|
def guest_can_download_code?
|
2016-11-29 13:59:25 -05:00
|
|
|
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
|
|
|
|
|
2018-12-20 11:40:56 -05:00
|
|
|
def check_change_access!
|
2017-05-23 15:21:57 -04:00
|
|
|
unless user_access.can_do_action?(:create_wiki)
|
2020-02-26 13:09:24 -05:00
|
|
|
raise ForbiddenError, ERROR_MESSAGES[:write_to_wiki]
|
2014-11-14 11:23:55 -05:00
|
|
|
end
|
2017-05-23 15:21:57 -04:00
|
|
|
|
2017-09-19 03:44:58 -04:00
|
|
|
if Gitlab::Database.read_only?
|
2020-02-26 13:09:24 -05:00
|
|
|
raise ForbiddenError, push_to_read_only_message
|
2017-09-19 03:44:58 -04:00
|
|
|
end
|
|
|
|
|
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
|
|
|
|
ERROR_MESSAGES[:read_only]
|
|
|
|
end
|
2018-02-21 19:20:30 -05:00
|
|
|
|
2020-04-15 02:09:49 -04:00
|
|
|
def container
|
|
|
|
project.wiki
|
2018-02-21 19:20:30 -05:00
|
|
|
end
|
2014-10-07 09:05:24 -04:00
|
|
|
end
|
|
|
|
end
|