2018-12-04 11:55:49 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Gitlab
|
|
|
|
module Checks
|
2021-06-15 18:09:57 +00:00
|
|
|
class TagCheck < BaseSingleChecker
|
2018-12-04 11:55:49 +00:00
|
|
|
ERROR_MESSAGES = {
|
|
|
|
change_existing_tags: 'You are not allowed to change existing tags on this project.',
|
|
|
|
update_protected_tag: 'Protected tags cannot be updated.',
|
|
|
|
delete_protected_tag: 'Protected tags cannot be deleted.',
|
|
|
|
create_protected_tag: 'You are not allowed to create this tag as it is protected.'
|
|
|
|
}.freeze
|
|
|
|
|
|
|
|
LOG_MESSAGES = {
|
|
|
|
tag_checks: "Checking if you are allowed to change existing tags...",
|
|
|
|
protected_tag_checks: "Checking if you are creating, updating or deleting a protected tag..."
|
|
|
|
}.freeze
|
|
|
|
|
|
|
|
def validate!
|
|
|
|
return unless tag_name
|
|
|
|
|
|
|
|
logger.log_timed(LOG_MESSAGES[:tag_checks]) do
|
2019-06-19 07:08:56 +00:00
|
|
|
if tag_exists? && user_access.cannot_do_action?(:admin_tag)
|
2020-02-26 18:09:24 +00:00
|
|
|
raise GitAccess::ForbiddenError, ERROR_MESSAGES[:change_existing_tags]
|
2018-12-04 11:55:49 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
protected_tag_checks
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def protected_tag_checks
|
|
|
|
logger.log_timed(LOG_MESSAGES[__method__]) do
|
|
|
|
return unless ProtectedTag.protected?(project, tag_name) # rubocop:disable Cop/AvoidReturnFromBlocks
|
|
|
|
|
2020-02-26 18:09:24 +00:00
|
|
|
raise(GitAccess::ForbiddenError, ERROR_MESSAGES[:update_protected_tag]) if update?
|
|
|
|
raise(GitAccess::ForbiddenError, ERROR_MESSAGES[:delete_protected_tag]) if deletion?
|
2018-12-04 11:55:49 +00:00
|
|
|
|
|
|
|
unless user_access.can_create_tag?(tag_name)
|
2020-02-26 18:09:24 +00:00
|
|
|
raise GitAccess::ForbiddenError, ERROR_MESSAGES[:create_protected_tag]
|
2018-12-04 11:55:49 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|