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

43 lines
1 KiB
Ruby
Raw Normal View History

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
2019-12-04 20:38:33 +05:30
prepend_if_ee('EE::Gitlab::GitAccessWiki') # rubocop: disable Cop/InjectEnterpriseEditionModule
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
2019-02-15 15:39:39 +05:30
def check_change_access!
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