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

refactor applications controller

parent 6f43a409
...@@ -20,10 +20,12 @@ class Admin::ApplicationsController < Admin::ApplicationController ...@@ -20,10 +20,12 @@ class Admin::ApplicationsController < Admin::ApplicationController
end end
def create def create
@application = Doorkeeper::Application.new(application_params) @application = Applications::CreateService.new(current_user, application_params)
if @application.save if @application.persisted?
redirect_to_admin_page flash[:notice] = I18n.t(:notice, scope: [:doorkeeper, :flash, :applications, :create])
redirect_to admin_application_url(@application)
else else
render :new render :new
end end
...@@ -42,13 +44,6 @@ class Admin::ApplicationsController < Admin::ApplicationController ...@@ -42,13 +44,6 @@ class Admin::ApplicationsController < Admin::ApplicationController
redirect_to admin_applications_url, status: 302, notice: 'Application was successfully destroyed.' redirect_to admin_applications_url, status: 302, notice: 'Application was successfully destroyed.'
end 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 private
def set_application def set_application
...@@ -57,6 +52,6 @@ class Admin::ApplicationsController < Admin::ApplicationController ...@@ -57,6 +52,6 @@ class Admin::ApplicationsController < Admin::ApplicationController
# Only allow a trusted parameter "white list" through. # Only allow a trusted parameter "white list" through.
def application_params 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
end end
module OauthApplications module OauthApplications
extend ActiveSupport::Concern extend ActiveSupport::Concern
prepend ::EE::Concerns::OauthApplications
included do included do
before_action :prepare_scopes, only: [:create, :update] before_action :prepare_scopes, only: [:create, :update]
......
...@@ -3,7 +3,6 @@ class Oauth::ApplicationsController < Doorkeeper::ApplicationsController ...@@ -3,7 +3,6 @@ class Oauth::ApplicationsController < Doorkeeper::ApplicationsController
include Gitlab::GonHelper include Gitlab::GonHelper
include PageLayoutHelper include PageLayoutHelper
include OauthApplications include OauthApplications
prepend ::EE::Oauth::ApplicationsController
before_action :verify_user_oauth_applications_enabled before_action :verify_user_oauth_applications_enabled
before_action :authenticate_user! before_action :authenticate_user!
...@@ -17,25 +16,18 @@ class Oauth::ApplicationsController < Doorkeeper::ApplicationsController ...@@ -17,25 +16,18 @@ class Oauth::ApplicationsController < Doorkeeper::ApplicationsController
end end
def create 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_url(@application)
redirect_to_oauth_application_page
else else
set_index_vars set_index_vars
render :index render :index
end end
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 private
def verify_user_oauth_applications_enabled def verify_user_oauth_applications_enabled
...@@ -62,4 +54,11 @@ class Oauth::ApplicationsController < Doorkeeper::ApplicationsController ...@@ -62,4 +54,11 @@ class Oauth::ApplicationsController < Doorkeeper::ApplicationsController
rescue_from ActiveRecord::RecordNotFound do |exception| rescue_from ActiveRecord::RecordNotFound do |exception|
render "errors/not_found", layout: "errors", status: 404 render "errors/not_found", layout: "errors", status: 404
end end
def application_params
super.tap do |params|
params[:owner] = current_user
params[:ip_address] = request.remote_ip
end
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