1
0

Clean up labels on development application form (#32116)

This commit is contained in:
Matt Jankowski 2024-10-02 10:45:12 -04:00 committed by GitHub
parent b7bb850efd
commit 36f9c96812
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 10 additions and 11 deletions

View File

@ -1,12 +1,6 @@
# frozen_string_literal: true # frozen_string_literal: true
module ApplicationHelper module ApplicationHelper
DANGEROUS_SCOPES = %w(
read
write
follow
).freeze
RTL_LOCALES = %i( RTL_LOCALES = %i(
ar ar
ckb ckb
@ -95,8 +89,11 @@ module ApplicationHelper
Rails.env.production? ? site_title : "#{site_title} (Dev)" Rails.env.production? ? site_title : "#{site_title} (Dev)"
end end
def class_for_scope(scope) def label_for_scope(scope)
'scope-danger' if DANGEROUS_SCOPES.include?(scope.to_s) safe_join [
tag.samp(scope, class: { 'scope-danger' => SessionActivation::DEFAULT_SCOPES.include?(scope.to_s) }),
tag.span(t("doorkeeper.scopes.#{scope}"), class: :hint),
]
end end
def can?(action, record) def can?(action, record)

View File

@ -28,6 +28,8 @@ class SessionActivation < ApplicationRecord
before_create :assign_access_token before_create :assign_access_token
DEFAULT_SCOPES = %w(read write follow).freeze
class << self class << self
def active?(id) def active?(id)
id && exists?(session_id: id) id && exists?(session_id: id)
@ -64,7 +66,7 @@ class SessionActivation < ApplicationRecord
{ {
application_id: Doorkeeper::Application.find_by(superapp: true)&.id, application_id: Doorkeeper::Application.find_by(superapp: true)&.id,
resource_owner_id: user_id, resource_owner_id: user_id,
scopes: 'read write follow', scopes: DEFAULT_SCOPES.join(' '),
expires_in: Doorkeeper.configuration.access_token_expires_in, expires_in: Doorkeeper.configuration.access_token_expires_in,
use_refresh_token: Doorkeeper.configuration.refresh_token_enabled?, use_refresh_token: Doorkeeper.configuration.refresh_token_enabled?,
} }

View File

@ -18,7 +18,7 @@
.field-group .field-group
.input.with_block_label .input.with_block_label
%label= t('activerecord.attributes.doorkeeper/application.scopes') = form.label t('activerecord.attributes.doorkeeper/application.scopes'), required: true
%span.hint= t('simple_form.hints.defaults.scopes') %span.hint= t('simple_form.hints.defaults.scopes')
- Doorkeeper.configuration.scopes.group_by { |s| s.split(':').first }.each_value do |value| - Doorkeeper.configuration.scopes.group_by { |s| s.split(':').first }.each_value do |value|
@ -29,7 +29,7 @@
hint: false, hint: false,
include_blank: false, include_blank: false,
item_wrapper_tag: 'li', item_wrapper_tag: 'li',
label_method: ->(scope) { safe_join([content_tag(:samp, scope, class: class_for_scope(scope)), content_tag(:span, t("doorkeeper.scopes.#{scope}"), class: 'hint')]) }, label_method: ->(scope) { label_for_scope(scope) },
label: false, label: false,
required: false, required: false,
selected: form.object.scopes.all, selected: form.object.scopes.all,