Commit 22cb2366 authored by Dmitry Gruzd's avatar Dmitry Gruzd

Merge branch '334873-creating-an-application-dumps-user-to-an-inescapable-screen' into 'master'

Add `Continue` button to view shown after creating an OAuth application

See merge request gitlab-org/gitlab!71964
parents be126962 d3c816a5
......@@ -15,6 +15,7 @@ class Admin::ApplicationsController < Admin::ApplicationController
end
def show
@created = get_created_session
end
def new
......@@ -33,6 +34,8 @@ class Admin::ApplicationsController < Admin::ApplicationController
if @application.persisted?
flash[:notice] = I18n.t(:notice, scope: [:doorkeeper, :flash, :applications, :create])
set_created_session
redirect_to admin_application_url(@application)
else
render :new
......
......@@ -3,6 +3,8 @@
module OauthApplications
extend ActiveSupport::Concern
CREATED_SESSION_KEY = :oauth_applications_created
included do
before_action :prepare_scopes, only: [:create, :update]
end
......@@ -15,6 +17,14 @@ module OauthApplications
end
end
def set_created_session
session[CREATED_SESSION_KEY] = true
end
def get_created_session
session.delete(CREATED_SESSION_KEY) || false
end
def load_scopes
@scopes ||= Doorkeeper.configuration.scopes
end
......
......@@ -16,6 +16,7 @@ module Groups
end
def show
@created = get_created_session
end
def edit
......@@ -27,6 +28,8 @@ module Groups
if @application.persisted?
flash[:notice] = I18n.t(:notice, scope: [:doorkeeper, :flash, :applications, :create])
set_created_session
redirect_to group_settings_application_url(@group, @application)
else
set_index_vars
......
......@@ -24,12 +24,18 @@ class Oauth::ApplicationsController < Doorkeeper::ApplicationsController
set_index_vars
end
def show
@created = get_created_session
end
def create
@application = Applications::CreateService.new(current_user, application_params).execute(request)
if @application.persisted?
flash[:notice] = I18n.t(:notice, scope: [:doorkeeper, :flash, :applications, :create])
set_created_session
redirect_to oauth_application_url(@application)
else
set_index_vars
......
......@@ -6,4 +6,5 @@
= render 'shared/doorkeeper/applications/show',
edit_path: edit_admin_application_path(@application),
delete_path: admin_application_path(@application),
index_path: admin_applications_path,
show_trusted_row: true
......@@ -6,4 +6,7 @@
%h3.page-title
= _("Application: %{name}") % { name: @application.name }
= render 'shared/doorkeeper/applications/show', edit_path: edit_oauth_application_path(@application), delete_path: oauth_application_path(@application)
= render 'shared/doorkeeper/applications/show',
edit_path: edit_oauth_application_path(@application),
delete_path: oauth_application_path(@application),
index_path: oauth_applications_path
......@@ -6,4 +6,7 @@
%h3.page-title
= _("Group application: %{name}") % { name: @application.name }
= render 'shared/doorkeeper/applications/show', edit_path: edit_group_settings_application_path(@group, @application), delete_path: group_settings_application_path(@group, @application)
= render 'shared/doorkeeper/applications/show',
edit_path: edit_group_settings_application_path(@group, @application),
delete_path: group_settings_application_path(@group, @application),
index_path: group_settings_applications_path
......@@ -39,6 +39,9 @@
= render "shared/tokens/scopes_list", token: @application
.form-actions
= link_to _('Edit'), edit_path, class: 'gl-button btn btn-confirm wide float-left'
= render 'shared/doorkeeper/applications/delete_form', path: delete_path, submit_btn_css: 'gl-button btn btn-danger gl-ml-3'
.form-actions.gl-display-flex.gl-justify-content-space-between
%div
- if @created
= link_to _('Continue'), index_path, class: 'btn btn-confirm btn-md gl-button gl-mr-3'
= link_to _('Edit'), edit_path, class: 'btn btn-default btn-md gl-button'
= render 'shared/doorkeeper/applications/delete_form', path: delete_path, submit_btn_css: 'btn btn-danger btn-md gl-button btn-danger-secondary'
......@@ -5,6 +5,7 @@ require 'spec_helper'
RSpec.describe 'admin manage applications' do
let_it_be(:new_application_path) { new_admin_application_path }
let_it_be(:applications_path) { admin_applications_path }
let_it_be(:index_path) { admin_applications_path }
before do
admin = create(:admin)
......
......@@ -6,6 +6,7 @@ RSpec.describe 'User manages applications' do
let_it_be(:group) { create(:group) }
let_it_be(:user) { create(:user) }
let_it_be(:new_application_path) { group_settings_applications_path(group) }
let_it_be(:index_path) { group_settings_applications_path(group) }
before do
group.add_owner(user)
......
......@@ -5,6 +5,7 @@ require 'spec_helper'
RSpec.describe 'User manages applications' do
let_it_be(:user) { create(:user) }
let_it_be(:new_application_path) { applications_profile_path }
let_it_be(:index_path) { oauth_applications_path }
before do
sign_in(user)
......
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Admin::ApplicationsController, :enable_admin_mode do
let_it_be(:admin) { create(:admin) }
let_it_be(:application) { create(:oauth_application, owner_id: nil, owner_type: nil) }
let_it_be(:show_path) { admin_application_path(application) }
let_it_be(:create_path) { admin_applications_path }
before do
sign_in(admin)
end
include_examples 'applications controller - GET #show'
include_examples 'applications controller - POST #create'
end
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Groups::Settings::ApplicationsController do
let_it_be(:user) { create(:user) }
let_it_be(:group) { create(:group) }
let_it_be(:application) { create(:oauth_application, owner_id: group.id, owner_type: 'Namespace') }
let_it_be(:show_path) { group_settings_application_path(group, application) }
let_it_be(:create_path) { group_settings_applications_path(group) }
before do
sign_in(user)
group.add_owner(user)
end
include_examples 'applications controller - GET #show'
include_examples 'applications controller - POST #create'
end
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Oauth::ApplicationsController do
let_it_be(:user) { create(:user) }
let_it_be(:application) { create(:oauth_application, owner: user) }
let_it_be(:show_path) { oauth_application_path(application) }
let_it_be(:create_path) { oauth_applications_path }
before do
sign_in(user)
end
include_examples 'applications controller - GET #show'
include_examples 'applications controller - POST #create'
end
......@@ -18,6 +18,7 @@ RSpec.shared_examples 'manage applications' do
click_on 'Save application'
validate_application(application_name, 'Yes')
expect(page).to have_link('Continue', href: index_path)
application = Doorkeeper::Application.find_by(name: application_name)
expect(page).to have_css("button[title=\"Copy secret\"][data-clipboard-text=\"#{application.secret}\"]", text: 'Copy')
......@@ -33,6 +34,7 @@ RSpec.shared_examples 'manage applications' do
click_on 'Save application'
validate_application(application_name_changed, 'No')
expect(page).not_to have_link('Continue')
visit_applications_path
......
# frozen_string_literal: true
RSpec.shared_examples 'applications controller - GET #show' do
describe 'GET #show' do
it 'renders template' do
get show_path
expect(response).to render_template :show
end
context 'when application is viewed after being created' do
before do
create_application
end
it 'sets `@created` instance variable to `true`' do
get show_path
expect(assigns[:created]).to eq(true)
end
end
context 'when application is reviewed' do
it 'sets `@created` instance variable to `false`' do
get show_path
expect(assigns[:created]).to eq(false)
end
end
end
end
RSpec.shared_examples 'applications controller - POST #create' do
it "sets `#{OauthApplications::CREATED_SESSION_KEY}` session key to `true`" do
create_application
expect(session[OauthApplications::CREATED_SESSION_KEY]).to eq(true)
end
end
def create_application
create_params = attributes_for(:application, trusted: true, confidential: false, scopes: ['api'])
post create_path, params: { doorkeeper_application: create_params }
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