Commit 90e91e28 authored by Robert Speicher's avatar Robert Speicher

Merge branch 'application-settings' into 'master'

Applications tab on profile settings

Closes #13855

See merge request !3031
parents ea7d062f 8f21e2ae
...@@ -103,6 +103,10 @@ $border-red-dark: #CA264F; ...@@ -103,6 +103,10 @@ $border-red-dark: #CA264F;
$help-well-bg: #FAFAFA; $help-well-bg: #FAFAFA;
$help-well-border: #E5E5E5; $help-well-border: #E5E5E5;
$warning-message-bg: #FBF2D9;
$warning-message-color: #9E8E60;
$warning-message-border: #F0E2BB;
/* header */ /* header */
$light-grey-header: #faf9f9; $light-grey-header: #faf9f9;
......
...@@ -215,3 +215,21 @@ ...@@ -215,3 +215,21 @@
color: $provider-btn-not-active-color; color: $provider-btn-not-active-color;
} }
} }
.profile-settings-message {
line-height: 32px;
color: $warning-message-color;
background-color: $warning-message-bg;
border: 1px solid $warning-message-border;
border-radius: $border-radius-base;
}
.oauth-applications {
form {
display: inline-block;
}
.last-heading {
width: 105px;
}
}
...@@ -8,7 +8,7 @@ class Oauth::ApplicationsController < Doorkeeper::ApplicationsController ...@@ -8,7 +8,7 @@ class Oauth::ApplicationsController < Doorkeeper::ApplicationsController
layout 'profile' layout 'profile'
def index def index
head :forbidden and return set_index_vars
end end
def create def create
...@@ -20,18 +20,11 @@ class Oauth::ApplicationsController < Doorkeeper::ApplicationsController ...@@ -20,18 +20,11 @@ class Oauth::ApplicationsController < Doorkeeper::ApplicationsController
flash[:notice] = I18n.t(:notice, scope: [:doorkeeper, :flash, :applications, :create]) flash[:notice] = I18n.t(:notice, scope: [:doorkeeper, :flash, :applications, :create])
redirect_to oauth_application_url(@application) redirect_to oauth_application_url(@application)
else else
render :new set_index_vars
render :index
end end
end end
def destroy
if @application.destroy
flash[:notice] = I18n.t(:notice, scope: [:doorkeeper, :flash, :applications, :destroy])
end
redirect_to applications_profile_url
end
private private
def verify_user_oauth_applications_enabled def verify_user_oauth_applications_enabled
...@@ -40,6 +33,17 @@ class Oauth::ApplicationsController < Doorkeeper::ApplicationsController ...@@ -40,6 +33,17 @@ class Oauth::ApplicationsController < Doorkeeper::ApplicationsController
redirect_to applications_profile_url redirect_to applications_profile_url
end end
def set_index_vars
@applications = current_user.oauth_applications
@authorized_tokens = current_user.oauth_authorized_tokens
@authorized_anonymous_tokens = @authorized_tokens.reject(&:application)
@authorized_apps = @authorized_tokens.map(&:application).uniq.reject(&:nil?)
# Don't overwrite a value possibly set by `create`
@application ||= Doorkeeper::Application.new
end
# Override Doorkeeper to scope to the current user
def set_application def set_application
@application = current_user.oauth_applications.find(params[:id]) @application = current_user.oauth_applications.find(params[:id])
end end
......
...@@ -8,13 +8,6 @@ class ProfilesController < Profiles::ApplicationController ...@@ -8,13 +8,6 @@ class ProfilesController < Profiles::ApplicationController
def show def show
end end
def applications
@applications = current_user.oauth_applications
@authorized_tokens = current_user.oauth_authorized_tokens
@authorized_anonymous_tokens = @authorized_tokens.reject(&:application)
@authorized_apps = @authorized_tokens.map(&:application).uniq - [nil]
end
def update def update
user_params.except!(:email) if @user.ldap_user? user_params.except!(:email) if @user.ldap_user?
......
- submit_btn_css ||= 'btn btn-link btn-remove btn-sm' - submit_btn_css ||= 'btn btn-link btn-remove btn-sm'
= form_tag oauth_application_path(application) do = form_tag oauth_application_path(application) do
%input{:name => "_method", :type => "hidden", :value => "delete"}/ %input{:name => "_method", :type => "hidden", :value => "delete"}/
= submit_tag 'Destroy', onclick: "return confirm('Are you sure?')", class: submit_btn_css - if defined? small
\ No newline at end of file = button_tag type: "submit", class: "btn btn-transparent", data: { confirm: "Are you sure?" } do
%span.sr-only
Destroy
= icon('trash')
- else
= submit_tag 'Destroy', data: { confirm: "Are you sure?" }, class: submit_btn_css
= form_for application, url: doorkeeper_submit_path(application), html: {class: 'form-horizontal', role: 'form'} do |f| = form_for application, url: doorkeeper_submit_path(application), html: {role: 'form'} do |f|
- if application.errors.any? - if application.errors.any?
.alert.alert-danger .alert.alert-danger
%ul %ul
...@@ -6,25 +6,20 @@ ...@@ -6,25 +6,20 @@
%li= msg %li= msg
.form-group .form-group
= f.label :name, class: 'control-label' = f.label :name, class: 'label-light'
= f.text_field :name, class: 'form-control', required: true
.col-sm-10
= f.text_field :name, class: 'form-control', required: true
.form-group .form-group
= f.label :redirect_uri, class: 'control-label' = f.label :redirect_uri, class: 'label-light'
= f.text_area :redirect_uri, class: 'form-control', required: true
.col-sm-10
= f.text_area :redirect_uri, class: 'form-control', required: true
%span.help-block
Use one line per URI
- if Doorkeeper.configuration.native_redirect_uri
%span.help-block %span.help-block
Use one line per URI Use
- if Doorkeeper.configuration.native_redirect_uri %code= Doorkeeper.configuration.native_redirect_uri
%span.help-block for local tests
Use
%code= Doorkeeper.configuration.native_redirect_uri
for local tests
.form-actions .prepend-top-default
= f.submit 'Submit', class: "btn btn-create" = f.submit 'Save application', class: "btn btn-create"
= link_to "Cancel", applications_profile_path, class: "btn btn-cancel"
- page_title "Applications" - page_title "Applications"
%h3.page-title Your applications - header_title page_title, applications_profile_path
%p= link_to 'New Application', new_oauth_application_path, class: 'btn btn-success'
.table-holder .row.prepend-top-default
%table.table.table-striped .col-lg-3.profile-settings-sidebar
%thead %h4.prepend-top-0
%tr = page_title
%th Name %p
%th Callback URL - if user_oauth_applications?
%th Manage applications that can use GitLab as an OAuth provider,
%th and applications that you've authorized to use your account.
%tbody - else
- @applications.each do |application| Manage applications that you've authorized to use your account.
%tr{:id => "application_#{application.id}"} .col-lg-9
%td= link_to application.name, oauth_application_path(application) - if user_oauth_applications?
%td= application.redirect_uri %h5.prepend-top-0
%td= link_to 'Edit', edit_oauth_application_path(application), class: 'btn btn-link' Add new application
%td= render 'delete_form', application: application = render 'form', application: @application
%hr
- if user_oauth_applications?
.oauth-applications
%h5
Your applications (#{@applications.size})
- if @applications.any?
.table-responsive
%table.table
%thead
%tr
%th Name
%th Callback URL
%th Clients
%th.last-heading
%tbody
- @applications.each do |application|
%tr{id: "application_#{application.id}"}
%td= link_to application.name, oauth_application_path(application)
%td
- application.redirect_uri.split.each do |uri|
%div= uri
%td= application.access_tokens.count
%td
= link_to edit_oauth_application_path(application), class: "btn btn-transparent append-right-5" do
%span.sr-only
Edit
= icon('pencil')
= render 'delete_form', application: application, small: true
- else
.profile-settings-message.text-center
You don't have any applications
.oauth-authorized-applications.prepend-top-20.append-bottom-default
- if user_oauth_applications?
%h5
Authorized applications (#{@authorized_tokens.size})
- if @authorized_tokens.any?
.table-responsive
%table.table.table-striped
%thead
%tr
%th Name
%th Authorized At
%th Scope
%th
%tbody
- @authorized_apps.each do |app|
- token = app.authorized_tokens.order('created_at desc').first
%tr{id: "application_#{app.id}"}
%td= app.name
%td= token.created_at
%td= token.scopes
%td= render 'delete_form', application: app
- @authorized_anonymous_tokens.each do |token|
%tr
%td
Anonymous
%div.help-block
%em Authorization was granted by entering your username and password in the application.
%td= token.created_at
%td= token.scopes
%td= render 'delete_form', token: token
- else
.profile-settings-message.text-center
You don't have any authorized applications
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
= icon('gear fw') = icon('gear fw')
%span %span
Account Account
= nav_link(path: ['profiles#applications', 'applications#edit', 'applications#show', 'applications#new', 'applications#create']) do = nav_link(controller: 'oauth/applications') do
= link_to applications_profile_path, title: 'Applications' do = link_to applications_profile_path, title: 'Applications' do
= icon('cloud fw') = icon('cloud fw')
%span %span
......
- page_title "Applications"
- header_title page_title, applications_profile_path
.alert.alert-help.prepend-top-default
- if user_oauth_applications?
Manage applications that can use GitLab as an OAuth provider,
and applications that you've authorized to use your account.
- else
Manage applications that you've authorized to use your account.
- if user_oauth_applications?
.oauth-applications
%h3
Your applications
.pull-right
= link_to 'New Application', new_oauth_application_path, class: 'btn btn-success'
- if @applications.any?
.table-holder
%table.table.table-striped
%thead
%tr
%th Name
%th Callback URL
%th Clients
%th
%th
%tbody
- @applications.each do |application|
%tr{:id => "application_#{application.id}"}
%td= link_to application.name, oauth_application_path(application)
%td
- application.redirect_uri.split.each do |uri|
%div= uri
%td= application.access_tokens.count
%td= link_to 'Edit', edit_oauth_application_path(application), class: 'btn btn-link btn-sm'
%td= render 'doorkeeper/applications/delete_form', application: application
.oauth-authorized-applications.prepend-top-20
- if user_oauth_applications?
%h3
Authorized applications
- if @authorized_tokens.any?
.table-holder
%table.table.table-striped
%thead
%tr
%th Name
%th Authorized At
%th Scope
%th
%tbody
- @authorized_apps.each do |app|
- token = app.authorized_tokens.order('created_at desc').first
%tr{:id => "application_#{app.id}"}
%td= app.name
%td= token.created_at
%td= token.scopes
%td= render 'doorkeeper/authorized_applications/delete_form', application: app
- @authorized_anonymous_tokens.each do |token|
%tr
%td
Anonymous
%div.help-block
%em Authorization was granted by entering your username and password in the application.
%td= token.created_at
%td= token.scopes
%td= render 'doorkeeper/authorized_applications/delete_form', token: token
- else
%p.light You don't have any authorized applications
...@@ -295,7 +295,7 @@ Rails.application.routes.draw do ...@@ -295,7 +295,7 @@ Rails.application.routes.draw do
resource :profile, only: [:show, :update] do resource :profile, only: [:show, :update] do
member do member do
get :audit_log get :audit_log
get :applications get :applications, to: 'oauth/applications#index'
put :reset_private_token put :reset_private_token
put :update_username put :update_username
......
...@@ -76,8 +76,7 @@ Feature: Profile ...@@ -76,8 +76,7 @@ Feature: Profile
Scenario: I can manage application Scenario: I can manage application
Given I visit profile applications page Given I visit profile applications page
Then I click on new application button Then I should see application form
And I should see application form
Then I fill application form out and submit Then I fill application form out and submit
And I see application And I see application
Then I click edit Then I click edit
......
...@@ -180,18 +180,14 @@ class Spinach::Features::Profile < Spinach::FeatureSteps ...@@ -180,18 +180,14 @@ class Spinach::Features::Profile < Spinach::FeatureSteps
end end
end end
step 'I click on new application button' do
click_on 'New Application'
end
step 'I should see application form' do step 'I should see application form' do
expect(page).to have_content "New Application" expect(page).to have_content "Add new application"
end end
step 'I fill application form out and submit' do step 'I fill application form out and submit' do
fill_in :doorkeeper_application_name, with: 'test' fill_in :doorkeeper_application_name, with: 'test'
fill_in :doorkeeper_application_redirect_uri, with: 'https://test.com' fill_in :doorkeeper_application_redirect_uri, with: 'https://test.com'
click_on "Submit" click_on "Save application"
end end
step 'I see application' do step 'I see application' do
...@@ -211,7 +207,7 @@ class Spinach::Features::Profile < Spinach::FeatureSteps ...@@ -211,7 +207,7 @@ class Spinach::Features::Profile < Spinach::FeatureSteps
step 'I change name of application and submit' do step 'I change name of application and submit' do
expect(page).to have_content "Edit application" expect(page).to have_content "Edit application"
fill_in :doorkeeper_application_name, with: 'test_changed' fill_in :doorkeeper_application_name, with: 'test_changed'
click_on "Submit" click_on "Save application"
end end
step 'I see that application was changed' do step 'I see that application was changed' do
......
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