2018-12-05 23:21:45 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2015-04-26 12:48:37 +05:30
|
|
|
class Admin::ApplicationsController < Admin::ApplicationController
|
2017-08-17 22:00:37 +05:30
|
|
|
include OauthApplications
|
|
|
|
|
2023-05-27 22:25:52 +05:30
|
|
|
before_action :set_application, only: [:show, :edit, :update, :renew, :destroy]
|
2017-08-17 22:00:37 +05:30
|
|
|
before_action :load_scopes, only: [:new, :create, :edit, :update]
|
2015-04-26 12:48:37 +05:30
|
|
|
|
2023-05-27 22:25:52 +05:30
|
|
|
feature_category :system_access
|
2021-01-03 14:25:43 +05:30
|
|
|
|
2015-04-26 12:48:37 +05:30
|
|
|
def index
|
2019-12-04 20:38:33 +05:30
|
|
|
applications = ApplicationsFinder.new.execute
|
|
|
|
@applications = Kaminari.paginate_array(applications).page(params[:page])
|
2015-04-26 12:48:37 +05:30
|
|
|
end
|
|
|
|
|
2023-05-27 22:25:52 +05:30
|
|
|
def show; end
|
2015-04-26 12:48:37 +05:30
|
|
|
|
|
|
|
def new
|
2022-07-16 23:28:13 +05:30
|
|
|
@application = Doorkeeper::Application.new
|
2015-04-26 12:48:37 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def edit
|
|
|
|
end
|
|
|
|
|
|
|
|
def create
|
2018-03-17 18:26:18 +05:30
|
|
|
@application = Applications::CreateService.new(current_user, application_params).execute(request)
|
2015-04-26 12:48:37 +05:30
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
if @application.persisted?
|
2015-04-26 12:48:37 +05:30
|
|
|
flash[:notice] = I18n.t(:notice, scope: [:doorkeeper, :flash, :applications, :create])
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2023-05-27 22:25:52 +05:30
|
|
|
@created = true
|
|
|
|
render :show
|
2015-04-26 12:48:37 +05:30
|
|
|
else
|
|
|
|
render :new
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def update
|
|
|
|
if @application.update(application_params)
|
2019-07-07 11:18:12 +05:30
|
|
|
redirect_to admin_application_path(@application), notice: _('Application was successfully updated.')
|
2015-04-26 12:48:37 +05:30
|
|
|
else
|
|
|
|
render :edit
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-05-27 22:25:52 +05:30
|
|
|
def renew
|
|
|
|
@application.renew_secret
|
|
|
|
|
|
|
|
if @application.save
|
2023-06-20 00:43:36 +05:30
|
|
|
render json: { secret: @application.plaintext_secret }
|
2023-05-27 22:25:52 +05:30
|
|
|
else
|
2023-06-20 00:43:36 +05:30
|
|
|
render json: { errors: @application.errors }, status: :unprocessable_entity
|
2023-05-27 22:25:52 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-04-26 12:48:37 +05:30
|
|
|
def destroy
|
|
|
|
@application.destroy
|
2019-12-26 22:10:19 +05:30
|
|
|
redirect_to admin_applications_url, status: :found, notice: _('Application was successfully destroyed.')
|
2015-04-26 12:48:37 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def set_application
|
2018-12-13 13:39:08 +05:30
|
|
|
@application = ApplicationsFinder.new(id: params[:id]).execute
|
2015-04-26 12:48:37 +05:30
|
|
|
end
|
|
|
|
|
2021-11-11 11:23:49 +05:30
|
|
|
def permitted_params
|
|
|
|
super << :trusted
|
|
|
|
end
|
|
|
|
|
2015-04-26 12:48:37 +05:30
|
|
|
def application_params
|
2021-11-11 11:23:49 +05:30
|
|
|
super.tap do |params|
|
|
|
|
params[:owner] = nil
|
|
|
|
end
|
2015-04-26 12:48:37 +05:30
|
|
|
end
|
|
|
|
end
|