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-02-13 14:33:13 -05:00
|
|
|
def check_single_change_access(change, _options = {})
|
2017-05-23 15:21:57 -04:00
|
|
|
unless user_access.can_do_action?(:create_wiki)
|
2017-05-19 15:58:45 -04:00
|
|
|
raise UnauthorizedError, 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?
|
2017-12-07 11:13:40 -05:00
|
|
|
raise UnauthorizedError, 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
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def repository
|
|
|
|
project.wiki.repository
|
|
|
|
end
|
2014-10-07 09:05:24 -04:00
|
|
|
end
|
|
|
|
end
|