Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
heptapod
heptapod
Commits
4ee50c558420
Commit
72b7b10d
authored
Oct 24, 2017
by
James Lopez
Browse files
add applications controller logic
parent
c891b24475cc
Changes
4
Hide whitespace changes
Inline
Side-by-side
app/controllers/admin/applications_controller.rb
View file @
4ee50c55
...
...
@@ -19,10 +19,12 @@ def edit
end
def
create
@application
=
Doorkeeper
::
Application
.
new
(
application_params
)
@application
=
Applications
::
CreateService
.
new
(
current_user
,
application_params
.
merge
(
ip_address:
request
.
remote_ip
)).
execute
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
...
...
@@ -41,13 +43,6 @@ def destroy
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
...
...
app/controllers/oauth/applications_controller.rb
View file @
4ee50c55
...
...
@@ -16,25 +16,16 @@ def index
end
def
create
@application
=
Doorkeeper
::
Application
.
new
(
application_params
)
@application
=
Applications
::
CreateService
.
new
(
current_user
,
create_
application_params
)
.
execute
@application
.
owner
=
current_user
if
@application
.
save
redirect_to_oauth_application_page
if
@application
.
persisted?
flash
[
:notice
]
=
I18n
.
t
(
:notice
,
scope:
[
:doorkeeper
,
:flash
,
:applications
,
:create
])
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
...
...
@@ -61,4 +52,11 @@ def set_application
rescue_from
ActiveRecord
::
RecordNotFound
do
|
exception
|
render
"errors/not_found"
,
layout:
"errors"
,
status:
404
end
def
create_application_params
application_params
.
tap
do
|
params
|
params
[
:owner
]
=
current_user
params
[
:ip_address
]
=
request
.
remote_ip
end
end
end
app/services/applications/create_searvice.rb
0 → 100644
View file @
4ee50c55
module
Applications
class
CreateService
prepend
::
EE
::
Applications
::
CreateService
def
initialize
(
current_user
,
params
)
@current_user
=
current_user
@params
=
params
@ip_address
=
@params
.
delete
(
:ip_address
)
end
def
execute
Doorkeeper
::
Application
.
create
(
@params
)
end
end
end
spec/services/applications/create_service_spec.rb
0 → 100644
View file @
4ee50c55
require
'spec_helper'
describe
::
Applications
::
CreateService
do
let
(
:user
)
{
create
(
:user
)
}
let
(
:params
)
{
attributes_for
(
:application
)
}
subject
{
described_class
.
new
(
user
,
params
)
}
it
'creates an application'
do
expect
{
subject
.
execute
}.
to
change
{
Doorkeeper
::
Application
.
count
}.
by
(
1
)
end
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment