Commit 6d9efba1 authored by James Lopez's avatar James Lopez

refactor applications service

parent fd6e03de
...@@ -19,7 +19,7 @@ class Admin::ApplicationsController < Admin::ApplicationController ...@@ -19,7 +19,7 @@ class Admin::ApplicationsController < Admin::ApplicationController
end end
def create def create
@application = Applications::CreateService.new(current_user, application_params.merge(ip_address: request.remote_ip)).execute @application = Applications::CreateService.new(current_user, application_params).execute(request)
if @application.persisted? if @application.persisted?
flash[:notice] = I18n.t(:notice, scope: [:doorkeeper, :flash, :applications, :create]) flash[:notice] = I18n.t(:notice, scope: [:doorkeeper, :flash, :applications, :create])
......
...@@ -16,7 +16,7 @@ class Oauth::ApplicationsController < Doorkeeper::ApplicationsController ...@@ -16,7 +16,7 @@ class Oauth::ApplicationsController < Doorkeeper::ApplicationsController
end end
def create def create
@application = Applications::CreateService.new(current_user, create_application_params).execute @application = Applications::CreateService.new(current_user, create_application_params).execute(request)
if @application.persisted? if @application.persisted?
flash[:notice] = I18n.t(:notice, scope: [:doorkeeper, :flash, :applications, :create]) flash[:notice] = I18n.t(:notice, scope: [:doorkeeper, :flash, :applications, :create])
...@@ -58,7 +58,6 @@ class Oauth::ApplicationsController < Doorkeeper::ApplicationsController ...@@ -58,7 +58,6 @@ class Oauth::ApplicationsController < Doorkeeper::ApplicationsController
def create_application_params def create_application_params
application_params.tap do |params| application_params.tap do |params|
params[:owner] = current_user params[:owner] = current_user
params[:ip_address] = request.remote_ip
end end
end end
end end
...@@ -5,10 +5,9 @@ module Applications ...@@ -5,10 +5,9 @@ module Applications
def initialize(current_user, params) def initialize(current_user, params)
@current_user = current_user @current_user = current_user
@params = params @params = params
@ip_address = @params.delete(:ip_address)
end end
def execute def execute(request = nil)
Doorkeeper::Application.create(@params) Doorkeeper::Application.create(@params)
end end
end end
......
module EE module EE
module Applications module Applications
module CreateService module CreateService
def execute def execute(request)
super.tap do |application| super.tap do |application|
audit_event_service.for_user(application.name).security_event audit_event_service(request.ip_address).for_user(application.name).security_event
end end
end end
def audit_event_service def audit_event_service(ip_address)
::AuditEventService.new(@current_user, ::AuditEventService.new(@current_user,
@current_user, @current_user,
action: :custom, action: :custom,
custom_message: 'OAuth access granted', custom_message: 'OAuth access granted',
ip_address: @ip_address) ip_address: ip_address)
end end
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