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
|
|
|
|
|
2015-04-26 12:48:37 +05:30
|
|
|
before_action :set_application, only: [:show, :edit, :update, :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
|
|
|
|
2021-01-03 14:25:43 +05:30
|
|
|
feature_category :authentication_and_authorization
|
|
|
|
|
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])
|
|
|
|
@application_counts = OauthAccessToken.distinct_resource_owner_counts(@applications)
|
2015-04-26 12:48:37 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def show
|
|
|
|
end
|
|
|
|
|
|
|
|
def new
|
2021-11-11 11:23:49 +05:30
|
|
|
# Default access tokens to expire. This preserves backward compatibility
|
|
|
|
# with existing applications. This will be removed in 15.0.
|
|
|
|
# Removal issue: https://gitlab.com/gitlab-org/gitlab/-/issues/340848
|
|
|
|
@application = Doorkeeper::Application.new(expire_access_tokens: true)
|
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
|
|
|
|
2015-04-26 12:48:37 +05:30
|
|
|
redirect_to admin_application_url(@application)
|
|
|
|
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
|
|
|
|
|
|
|
|
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
|