2017-08-22 19:33:57 +03:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class Settings::ApplicationsController < ApplicationController
|
|
|
|
layout 'admin'
|
|
|
|
|
|
|
|
before_action :authenticate_user!
|
2017-08-23 01:59:35 +03:00
|
|
|
before_action :set_application, only: [:show, :update, :destroy, :regenerate]
|
2017-08-23 16:16:20 +03:00
|
|
|
before_action :prepare_scopes, only: [:create, :update]
|
2017-08-22 19:33:57 +03:00
|
|
|
|
|
|
|
def index
|
2018-05-22 15:44:53 +03:00
|
|
|
@applications = current_user.applications.order(id: :desc).page(params[:page])
|
2017-08-22 19:33:57 +03:00
|
|
|
end
|
|
|
|
|
|
|
|
def new
|
|
|
|
@application = Doorkeeper::Application.new(
|
|
|
|
redirect_uri: Doorkeeper.configuration.native_redirect_uri,
|
|
|
|
scopes: 'read write follow'
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
2017-08-23 01:59:35 +03:00
|
|
|
def show; end
|
2017-08-22 19:33:57 +03:00
|
|
|
|
|
|
|
def create
|
|
|
|
@application = current_user.applications.build(application_params)
|
2017-08-23 01:59:35 +03:00
|
|
|
|
2017-08-22 19:33:57 +03:00
|
|
|
if @application.save
|
2017-08-23 01:59:35 +03:00
|
|
|
redirect_to settings_applications_path, notice: I18n.t('applications.created')
|
2017-08-22 19:33:57 +03:00
|
|
|
else
|
|
|
|
render :new
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def update
|
2017-08-23 01:59:35 +03:00
|
|
|
if @application.update(application_params)
|
2017-08-22 19:33:57 +03:00
|
|
|
redirect_to settings_applications_path, notice: I18n.t('generic.changes_saved_msg')
|
|
|
|
else
|
|
|
|
render :show
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def destroy
|
|
|
|
@application.destroy
|
2017-08-23 01:59:35 +03:00
|
|
|
redirect_to settings_applications_path, notice: I18n.t('applications.destroyed')
|
2017-08-22 19:33:57 +03:00
|
|
|
end
|
|
|
|
|
|
|
|
def regenerate
|
|
|
|
@access_token = current_user.token_for_app(@application)
|
|
|
|
@access_token.destroy
|
|
|
|
|
2017-08-23 01:59:35 +03:00
|
|
|
redirect_to settings_application_path(@application), notice: I18n.t('applications.token_regenerated')
|
2017-08-22 19:33:57 +03:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2017-08-23 01:59:35 +03:00
|
|
|
def set_application
|
|
|
|
@application = current_user.applications.find(params[:id])
|
|
|
|
end
|
|
|
|
|
2017-08-22 19:33:57 +03:00
|
|
|
def application_params
|
|
|
|
params.require(:doorkeeper_application).permit(
|
|
|
|
:name,
|
|
|
|
:redirect_uri,
|
|
|
|
:scopes,
|
|
|
|
:website
|
|
|
|
)
|
|
|
|
end
|
2017-08-23 16:16:20 +03: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 19:33:57 +03:00
|
|
|
end
|