Commit 60a1ffee authored by James Lopez's avatar James Lopez

refactor applications controller

parent 6f43a409
......@@ -20,10 +20,12 @@ class Admin::ApplicationsController < Admin::ApplicationController
end
def create
@application = Doorkeeper::Application.new(application_params)
@application = Applications::CreateService.new(current_user, application_params)
if @application.save
redirect_to_admin_page
if @application.persisted?
flash[:notice] = I18n.t(:notice, scope: [:doorkeeper, :flash, :applications, :create])
redirect_to admin_application_url(@application)
else
render :new
end
......@@ -42,13 +44,6 @@ class Admin::ApplicationsController < Admin::ApplicationController
redirect_to admin_applications_url, status: 302, notice: 'Application was successfully destroyed.'
end
protected
def redirect_to_admin_page
flash[:notice] = I18n.t(:notice, scope: [:doorkeeper, :flash, :applications, :create])
redirect_to admin_application_url(@application)
end
private
def set_application
......@@ -57,6 +52,6 @@ class Admin::ApplicationsController < Admin::ApplicationController
# Only allow a trusted parameter "white list" through.
def application_params
params.require(:doorkeeper_application).permit(:name, :redirect_uri, :trusted, :scopes)
params.require(:doorkeeper_application).permit(:name, :redirect_uri, :trusted, :scopes).merge(ip_address: request.remote_ip)
end
end
module OauthApplications
extend ActiveSupport::Concern
prepend ::EE::Concerns::OauthApplications
included do
before_action :prepare_scopes, only: [:create, :update]
......
......@@ -3,7 +3,6 @@ class Oauth::ApplicationsController < Doorkeeper::ApplicationsController
include Gitlab::GonHelper
include PageLayoutHelper
include OauthApplications
prepend ::EE::Oauth::ApplicationsController
before_action :verify_user_oauth_applications_enabled
before_action :authenticate_user!
......@@ -17,25 +16,18 @@ class Oauth::ApplicationsController < Doorkeeper::ApplicationsController
end
def create
@application = Doorkeeper::Application.new(application_params)
@application = Applications::CreateService.new(current_user, application_params)
@application.owner = current_user
if @application.persited?
flash[:notice] = I18n.t(:notice, scope: [:doorkeeper, :flash, :applications, :create])
if @application.save
redirect_to_oauth_application_page
redirect_to oauth_application_url(@application)
else
set_index_vars
render :index
end
end
protected
def redirect_to_oauth_application_page
flash[:notice] = I18n.t(:notice, scope: [:doorkeeper, :flash, :applications, :create])
redirect_to oauth_application_url(@application)
end
private
def verify_user_oauth_applications_enabled
......@@ -62,4 +54,11 @@ class Oauth::ApplicationsController < Doorkeeper::ApplicationsController
rescue_from ActiveRecord::RecordNotFound do |exception|
render "errors/not_found", layout: "errors", status: 404
end
def application_params
super.tap do |params|
params[:owner] = current_user
params[:ip_address] = request.remote_ip
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment