This repository has been archived by the owner on Dec 21, 2023. It is now read-only.
forked from mastodon/mastodon
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Change authorized applications page (mastodon#17656)
* Change authorized applications page * Hide revoke button for superapps and suspended accounts * Clean up db/schema.rb
- Loading branch information
Showing
20 changed files
with
393 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# frozen_string_literal: true | ||
|
||
module AccessTokenTrackingConcern | ||
extend ActiveSupport::Concern | ||
|
||
ACCESS_TOKEN_UPDATE_FREQUENCY = 24.hours.freeze | ||
|
||
included do | ||
before_action :update_access_token_last_used | ||
end | ||
|
||
private | ||
|
||
def update_access_token_last_used | ||
doorkeeper_token.update_last_used(request) if access_token_needs_update? | ||
end | ||
|
||
def access_token_needs_update? | ||
doorkeeper_token.present? && (doorkeeper_token.last_used_at.nil? || doorkeeper_token.last_used_at < ACCESS_TOKEN_UPDATE_FREQUENCY.ago) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# frozen_string_literal: true | ||
|
||
class ScopeParser < Parslet::Parser | ||
rule(:term) { match('[a-z]').repeat(1).as(:term) } | ||
rule(:colon) { str(':') } | ||
rule(:access) { (str('write') | str('read')).as(:access) } | ||
rule(:namespace) { str('admin').as(:namespace) } | ||
rule(:scope) { ((namespace >> colon).maybe >> ((access >> colon >> term) | access | term)).as(:scope) } | ||
root(:scope) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# frozen_string_literal: true | ||
|
||
class ScopeTransformer < Parslet::Transform | ||
class Scope | ||
DEFAULT_TERM = 'all' | ||
DEFAULT_ACCESS = %w(read write).freeze | ||
|
||
attr_reader :namespace, :term | ||
|
||
def initialize(scope) | ||
@namespace = scope[:namespace]&.to_s | ||
@access = scope[:access] ? [scope[:access].to_s] : DEFAULT_ACCESS.dup | ||
@term = scope[:term]&.to_s || DEFAULT_TERM | ||
end | ||
|
||
def key | ||
@key ||= [@namespace, @term].compact.join('/') | ||
end | ||
|
||
def access | ||
@access.join('/') | ||
end | ||
|
||
def merge(other_scope) | ||
clone.merge!(other_scope) | ||
end | ||
|
||
def merge!(other_scope) | ||
raise ArgumentError unless other_scope.namespace == namespace && other_scope.term == term | ||
|
||
@access.concat(other_scope.instance_variable_get('@access')) | ||
@access.uniq! | ||
@access.sort! | ||
|
||
self | ||
end | ||
end | ||
|
||
rule(scope: subtree(:scope)) { Scope.new(scope) } | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,38 @@ | ||
- content_for :page_title do | ||
= t('doorkeeper.authorizations.new.title') | ||
|
||
.form-container | ||
.form-container.simple_form | ||
.oauth-prompt | ||
%h2= t('doorkeeper.authorizations.new.prompt', client_name: @pre_auth.client.name) | ||
%h3= t('doorkeeper.authorizations.new.title') | ||
|
||
%p | ||
= t('doorkeeper.authorizations.new.able_to') | ||
!= @pre_auth.scopes.map { |scope| t(scope, scope: [:doorkeeper, :scopes]) }.map { |s| "<strong>#{s}</strong>" }.to_sentence | ||
%p= t('doorkeeper.authorizations.new.prompt_html', client_name: content_tag(:strong, @pre_auth.client.name)) | ||
|
||
= form_tag oauth_authorization_path, method: :post, class: 'simple_form' do | ||
= hidden_field_tag :client_id, @pre_auth.client.uid | ||
= hidden_field_tag :redirect_uri, @pre_auth.redirect_uri | ||
= hidden_field_tag :state, @pre_auth.state | ||
= hidden_field_tag :response_type, @pre_auth.response_type | ||
= hidden_field_tag :scope, @pre_auth.scope | ||
= button_tag t('doorkeeper.authorizations.buttons.authorize'), type: :submit | ||
%h3= t('doorkeeper.authorizations.new.review_permissions') | ||
|
||
= form_tag oauth_authorization_path, method: :delete, class: 'simple_form' do | ||
= hidden_field_tag :client_id, @pre_auth.client.uid | ||
= hidden_field_tag :redirect_uri, @pre_auth.redirect_uri | ||
= hidden_field_tag :state, @pre_auth.state | ||
= hidden_field_tag :response_type, @pre_auth.response_type | ||
= hidden_field_tag :scope, @pre_auth.scope | ||
= button_tag t('doorkeeper.authorizations.buttons.deny'), type: :submit, class: 'negative' | ||
%ul.permissions-list | ||
- grouped_scopes(@pre_auth.scopes).each do |scope| | ||
%li.permissions-list__item | ||
.permissions-list__item__icon | ||
= fa_icon('check') | ||
.permissions-list__item__text | ||
.permissions-list__item__text__title | ||
= t(scope.key, scope: [:doorkeeper, :grouped_scopes, :title]) | ||
.permissions-list__item__text__type | ||
= t(scope.access, scope: [:doorkeeper, :grouped_scopes, :access]) | ||
|
||
.actions | ||
= form_tag oauth_authorization_path, method: :post do | ||
= hidden_field_tag :client_id, @pre_auth.client.uid | ||
= hidden_field_tag :redirect_uri, @pre_auth.redirect_uri | ||
= hidden_field_tag :state, @pre_auth.state | ||
= hidden_field_tag :response_type, @pre_auth.response_type | ||
= hidden_field_tag :scope, @pre_auth.scope | ||
= button_tag t('doorkeeper.authorizations.buttons.authorize'), type: :submit | ||
|
||
= form_tag oauth_authorization_path, method: :delete do | ||
= hidden_field_tag :client_id, @pre_auth.client.uid | ||
= hidden_field_tag :redirect_uri, @pre_auth.redirect_uri | ||
= hidden_field_tag :state, @pre_auth.state | ||
= hidden_field_tag :response_type, @pre_auth.response_type | ||
= hidden_field_tag :scope, @pre_auth.scope | ||
= button_tag t('doorkeeper.authorizations.buttons.deny'), type: :submit, class: 'negative' |
Oops, something went wrong.