123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899 |
- class UserAccessTokenController < ApplicationController
- prepend_before_action :authenticate_and_authorize!
- def index
- tokens = Service::User::AccessToken::List.new(current_user).execute
- permissions = current_user.permissions_with_child_and_parent_elements
- render json: {
- tokens: tokens,
- permissions: permissions,
- }, status: :ok
- end
- def create
- if Setting.get('api_token_access') == false
- raise Exceptions::UnprocessableEntity, 'API token access disabled!'
- end
- if params[:name].blank?
- raise Exceptions::UnprocessableEntity, __("The required parameter 'name' is missing.")
- end
- token = Service::User::AccessToken::Create
- .new(current_user, **params.permit(:name, :expires_at, permission: []).to_h.to_options)
- .execute
- render json: {
- token: token.token,
- }, status: :ok
- end
- def destroy
- token = Token.find_by(action: 'api', user_id: current_user.id, id: params[:id])
- raise Exceptions::UnprocessableEntity, __('The API token could not be found.') if !token
- token.destroy!
- render json: {}, status: :ok
- end
- end
|