forked from cybrespace/mastodon
Use checkboxes for application scope setting (#4671)
This commit is contained in:
parent
8d23667536
commit
80393a23d0
|
@ -5,6 +5,7 @@ class Settings::ApplicationsController < ApplicationController
|
||||||
|
|
||||||
before_action :authenticate_user!
|
before_action :authenticate_user!
|
||||||
before_action :set_application, only: [:show, :update, :destroy, :regenerate]
|
before_action :set_application, only: [:show, :update, :destroy, :regenerate]
|
||||||
|
before_action :prepare_scopes, only: [:create, :update]
|
||||||
|
|
||||||
def index
|
def index
|
||||||
@applications = current_user.applications.page(params[:page])
|
@applications = current_user.applications.page(params[:page])
|
||||||
|
@ -63,4 +64,9 @@ class Settings::ApplicationsController < ApplicationController
|
||||||
:website
|
:website
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def prepare_scopes
|
||||||
|
scopes = params.fetch(:doorkeeper_application, {}).fetch(:scopes, nil)
|
||||||
|
params[:doorkeeper_application][:scopes] = scopes.join(' ') if scopes.is_a? Array
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -7,5 +7,15 @@
|
||||||
|
|
||||||
%p.hint= t('doorkeeper.applications.help.native_redirect_uri', native_redirect_uri: Doorkeeper.configuration.native_redirect_uri)
|
%p.hint= t('doorkeeper.applications.help.native_redirect_uri', native_redirect_uri: Doorkeeper.configuration.native_redirect_uri)
|
||||||
|
|
||||||
.fields-group
|
.field-group
|
||||||
= f.input :scopes, wrapper: :with_label, label: t('activerecord.attributes.doorkeeper/application.scopes'), hint: t('doorkeeper.applications.help.scopes')
|
= f.input :scopes,
|
||||||
|
label: t('activerecord.attributes.doorkeeper/application.scopes'),
|
||||||
|
collection: Doorkeeper.configuration.scopes,
|
||||||
|
wrapper: :with_label,
|
||||||
|
include_blank: false,
|
||||||
|
selected: f.object.scopes.all,
|
||||||
|
required: false,
|
||||||
|
as: :check_boxes,
|
||||||
|
collection_wrapper_tag: 'ul',
|
||||||
|
item_wrapper_tag: 'li'
|
||||||
|
|
||||||
|
|
|
@ -45,7 +45,7 @@ describe Settings::ApplicationsController do
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'POST #create' do
|
describe 'POST #create' do
|
||||||
context 'success' do
|
context 'success (passed scopes as a String)' do
|
||||||
def call_create
|
def call_create
|
||||||
post :create, params: {
|
post :create, params: {
|
||||||
doorkeeper_application: {
|
doorkeeper_application: {
|
||||||
|
@ -67,6 +67,28 @@ describe Settings::ApplicationsController do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context 'success (passed scopes as an Array)' do
|
||||||
|
def call_create
|
||||||
|
post :create, params: {
|
||||||
|
doorkeeper_application: {
|
||||||
|
name: 'My New App',
|
||||||
|
redirect_uri: 'urn:ietf:wg:oauth:2.0:oob',
|
||||||
|
website: 'http://google.com',
|
||||||
|
scopes: [ 'read', 'write', 'follow' ]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
response
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'creates an entry in the database' do
|
||||||
|
expect { call_create }.to change(Doorkeeper::Application, :count)
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'redirects back to applications page' do
|
||||||
|
expect(call_create).to redirect_to(settings_applications_path)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
context 'failure' do
|
context 'failure' do
|
||||||
before do
|
before do
|
||||||
post :create, params: {
|
post :create, params: {
|
||||||
|
@ -74,7 +96,7 @@ describe Settings::ApplicationsController do
|
||||||
name: '',
|
name: '',
|
||||||
redirect_uri: '',
|
redirect_uri: '',
|
||||||
website: '',
|
website: '',
|
||||||
scopes: ''
|
scopes: []
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
@ -123,7 +145,7 @@ describe Settings::ApplicationsController do
|
||||||
name: '',
|
name: '',
|
||||||
redirect_uri: '',
|
redirect_uri: '',
|
||||||
website: '',
|
website: '',
|
||||||
scopes: ''
|
scopes: []
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue