2020-10-24 23:57:45 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module PersonalAccessTokens
|
|
|
|
class RevokeService
|
2021-01-03 14:25:43 +05:30
|
|
|
attr_reader :token, :current_user, :group
|
2020-10-24 23:57:45 +05:30
|
|
|
|
2021-01-03 14:25:43 +05:30
|
|
|
def initialize(current_user = nil, params = { token: nil, group: nil })
|
2020-10-24 23:57:45 +05:30
|
|
|
@current_user = current_user
|
|
|
|
@token = params[:token]
|
2021-01-03 14:25:43 +05:30
|
|
|
@group = params[:group]
|
2020-10-24 23:57:45 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def execute
|
|
|
|
return ServiceResponse.error(message: 'Not permitted to revoke') unless revocation_permitted?
|
|
|
|
|
|
|
|
if token.revoke!
|
|
|
|
ServiceResponse.success(message: success_message)
|
|
|
|
else
|
|
|
|
ServiceResponse.error(message: error_message)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def error_message
|
|
|
|
_("Could not revoke personal access token %{personal_access_token_name}.") % { personal_access_token_name: token.name }
|
|
|
|
end
|
|
|
|
|
|
|
|
def success_message
|
|
|
|
_("Revoked personal access token %{personal_access_token_name}!") % { personal_access_token_name: token.name }
|
|
|
|
end
|
|
|
|
|
|
|
|
def revocation_permitted?
|
|
|
|
Ability.allowed?(current_user, :revoke_token, token)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2021-01-03 14:25:43 +05:30
|
|
|
|
|
|
|
PersonalAccessTokens::RevokeService.prepend_if_ee('EE::PersonalAccessTokens::RevokeService')
|