debian-mirror-gitlab/lib/gitlab/git_access_wiki.rb

39 lines
944 B
Ruby
Raw Normal View History

2015-04-26 12:48:37 +05:30
module Gitlab
class GitAccessWiki < GitAccess
2017-09-10 17:25:29 +05:30
ERROR_MESSAGES = {
2018-03-17 18:26:18 +05:30
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
2017-08-17 22:00:37 +05:30
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
2018-03-17 18:26:18 +05:30
def check_single_change_access(change, _options = {})
2017-09-10 17:25:29 +05:30
unless user_access.can_do_action?(:create_wiki)
raise UnauthorizedError, ERROR_MESSAGES[:write_to_wiki]
2015-04-26 12:48:37 +05:30
end
2017-09-10 17:25:29 +05:30
2018-03-17 18:26:18 +05:30
if Gitlab::Database.read_only?
raise UnauthorizedError, push_to_read_only_message
end
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
ERROR_MESSAGES[:read_only]
end
private
def repository
project.wiki.repository
end
2015-04-26 12:48:37 +05:30
end
end