2017-08-22 09:33:57 -07:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-12-12 13:32:13 -08:00
|
|
|
class Settings::ApplicationsController < Settings::BaseController
|
2017-08-22 15:59:35 -07:00
|
|
|
before_action :set_application, only: [:show, :update, :destroy, :regenerate]
|
2017-08-23 06:16:20 -07:00
|
|
|
before_action :prepare_scopes, only: [:create, :update]
|
2017-08-22 09:33:57 -07:00
|
|
|
|
|
|
|
def index
|
2018-05-22 05:44:53 -07:00
|
|
|
@applications = current_user.applications.order(id: :desc).page(params[:page])
|
2017-08-22 09:33:57 -07:00
|
|
|
end
|
|
|
|
|
2023-04-29 21:46:39 -07:00
|
|
|
def show; end
|
|
|
|
|
2017-08-22 09:33:57 -07:00
|
|
|
def new
|
|
|
|
@application = Doorkeeper::Application.new(
|
|
|
|
redirect_uri: Doorkeeper.configuration.native_redirect_uri,
|
2024-05-16 00:59:46 -07:00
|
|
|
scopes: 'read:me'
|
2017-08-22 09:33:57 -07:00
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
def create
|
|
|
|
@application = current_user.applications.build(application_params)
|
2017-08-22 15:59:35 -07:00
|
|
|
|
2017-08-22 09:33:57 -07:00
|
|
|
if @application.save
|
2017-08-22 15:59:35 -07:00
|
|
|
redirect_to settings_applications_path, notice: I18n.t('applications.created')
|
2017-08-22 09:33:57 -07:00
|
|
|
else
|
|
|
|
render :new
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def update
|
2017-08-22 15:59:35 -07:00
|
|
|
if @application.update(application_params)
|
2023-02-02 03:03:49 -08:00
|
|
|
if @application.scopes_previously_changed?
|
|
|
|
@access_token = current_user.token_for_app(@application)
|
|
|
|
@access_token.destroy
|
|
|
|
redirect_to settings_application_path(@application), notice: I18n.t('applications.token_regenerated')
|
|
|
|
else
|
|
|
|
redirect_to settings_application_path(@application), notice: I18n.t('generic.changes_saved_msg')
|
|
|
|
end
|
2017-08-22 09:33:57 -07:00
|
|
|
else
|
|
|
|
render :show
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def destroy
|
|
|
|
@application.destroy
|
2017-08-22 15:59:35 -07:00
|
|
|
redirect_to settings_applications_path, notice: I18n.t('applications.destroyed')
|
2017-08-22 09:33:57 -07:00
|
|
|
end
|
|
|
|
|
|
|
|
def regenerate
|
|
|
|
@access_token = current_user.token_for_app(@application)
|
|
|
|
@access_token.destroy
|
|
|
|
|
2017-08-22 15:59:35 -07:00
|
|
|
redirect_to settings_application_path(@application), notice: I18n.t('applications.token_regenerated')
|
2017-08-22 09:33:57 -07:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2017-08-22 15:59:35 -07:00
|
|
|
def set_application
|
|
|
|
@application = current_user.applications.find(params[:id])
|
|
|
|
end
|
|
|
|
|
2017-08-22 09:33:57 -07:00
|
|
|
def application_params
|
|
|
|
params.require(:doorkeeper_application).permit(
|
|
|
|
:name,
|
|
|
|
:redirect_uri,
|
|
|
|
:scopes,
|
|
|
|
:website
|
|
|
|
)
|
|
|
|
end
|
2017-08-23 06:16:20 -07:00
|
|
|
|
|
|
|
def prepare_scopes
|
|
|
|
scopes = params.fetch(:doorkeeper_application, {}).fetch(:scopes, nil)
|
|
|
|
params[:doorkeeper_application][:scopes] = scopes.join(' ') if scopes.is_a? Array
|
|
|
|
end
|
2017-08-22 09:33:57 -07:00
|
|
|
end
|