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

39 lines
915 B
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
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)
2020-04-08 14:13:33 +05:30
raise ForbiddenError, 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?
2020-04-08 14:13:33 +05:30
raise ForbiddenError, push_to_read_only_message
2018-03-17 18:26:18 +05:30
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
2020-04-22 19:07:51 +05:30
def container
project.wiki
2018-03-17 18:26:18 +05:30
end
2015-04-26 12:48:37 +05:30
end
end