Skip to content

Commit cdec879

Browse files
committed
🦋 updates account access tokens page (also account users)
1 parent 9e216ee commit cdec879

30 files changed

Lines changed: 366 additions & 204 deletions

File tree

‎app/controllers/provider/admin/user/access_tokens_controller.rb‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ class AccessTokensController < BaseController
1111
before_action :disable_client_cache
1212
before_action :load_access_token, only: %i[edit update destroy]
1313

14-
def index
15-
@access_tokens = access_tokens
16-
end
14+
helper_method :access_tokens, :service_tokens
15+
16+
def index; end
1717

1818
def new
1919
@presenter = AccessTokensNewPresenter.new(current_account)
@@ -60,6 +60,10 @@ def access_tokens
6060
@access_tokens ||= current_user.access_tokens
6161
end
6262

63+
def service_tokens
64+
@service_tokens ||= current_user.decorate.accessible_services_with_token
65+
end
66+
6367
def load_access_token
6468
@access_token = access_tokens.find(params[:id])
6569
end

‎app/decorators/user_decorator.rb‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,11 @@ def display_name
1212
def informal_name
1313
first_name.presence || last_name.presence || username
1414
end
15+
16+
def accessible_services_with_token
17+
return Service.none unless has_permission?(:plans)
18+
19+
accessible_services.joins(:service_tokens)
20+
.includes(:service_tokens)
21+
end
1522
end

‎app/helpers/buttons_helper.rb‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ def action_button_to(action, url, options = {})
8383
fancy_button_to(label, url, options)
8484
end
8585

86+
# DEPRECATED: Replace with form to be independent of rails-ujs (data-method: 'delete')
8687
# Button for deleting stuff.
8788
#
8889
# This is a shortcut for

‎app/helpers/patternfly_components_helper.rb‎

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -65,24 +65,19 @@ def pf_toast_alert(title, **options)
6565
# TODO: this action button is used only in app/views/provider/admin/account/users/index.html.slim
6666
# right now, but could be used in other tables. Eliminate existing repetition by using this helper
6767
def pf_delete_table_action(url, button_options = {})
68-
form_attributes = { method: :delete }
69-
70-
button_class = 'pf-c-button pf-m-link pf-m-danger'
71-
72-
confirm = button_options.delete(:confirm) || 'It will be permanently delete. Are you sure?'
68+
confirm = button_options.delete(:confirm) || I18n.t('shared.delete_button_confirm')
69+
title = button_options.delete(:title) || I18n.t('shared.delete_button_title')
7370

7471
button_attributes = { type: :submit,
75-
class: button_class.strip,
72+
class: 'pf-c-button pf-m-link pf-m-danger',
73+
title:,
7674
'data-confirm': confirm }.merge(button_options)
7775

78-
span = tag.span class: 'pf-c-button__icon pf-m-start' do
79-
tag.i class: "fas fa-trash", 'aria-hidden': 'true'
80-
end
81-
label = 'Delete'
82-
83-
form_tag(url, form_attributes) do
76+
form_tag(url, method: :delete) do
8477
tag.button(**button_attributes) do
85-
span + label
78+
tag.span class: 'pf-c-button__icon pf-m-start' do
79+
tag.i class: 'fas fa-trash', 'aria-hidden': 'true'
80+
end
8681
end
8782
end
8883
end

‎app/javascript/packs/access_tokens.scss‎

Lines changed: 0 additions & 2 deletions
This file was deleted.

‎app/javascript/packs/pf_form.scss‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
@import '~@patternfly/patternfly/components/ActionList/action-list.css';
12
@import '~@patternfly/patternfly/components/Button/button.css';
23
@import '~@patternfly/patternfly/components/Check/check.css';
34
@import '~@patternfly/patternfly/components/Form/form.css';
@@ -8,3 +9,9 @@
89
margin-top: var(--pf-c-check__body--MarginTop);
910
}
1011
}
12+
13+
.pf-c-form__actions {
14+
.pf-c-button.pf-m-danger {
15+
margin-left: auto;
16+
}
17+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
@import '@patternfly/patternfly/utilities/Text/text.css';

‎app/lib/api_docs/provider_user_data.rb‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ def access_token
1414
end
1515

1616
def service_tokens
17-
tokens = @user.accessible_service_tokens.map do |service_token|
18-
{ name: service_token.service.name, value: service_token.value }
17+
tokens = @user.decorate.accessible_services_with_token.map do |service|
18+
{ name: service.name, value: service.active_service_token.value }
1919
end
2020
tokens.presence || [{ name: "You don't have access to any services, contact an administrator of this account.", value: '' }]
2121
end

‎app/lib/fields/patternfly_form_builder.rb‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ def output_html(field, options = {})
1919
typed_input_field.input(self, builder_options)
2020
end
2121

22+
def cancel_link(href, opts = {})
23+
opts.reverse_merge!(class: 'pf-c-button pf-m-link', type: :button)
24+
template.link_to(I18n.t('shared.cancel_button'), href, **opts)
25+
end
26+
2227
def commit_button(title, opts = {})
2328
raise ArgumentError, 'button_html prop will be ignored, use standard html attributes' if opts.key?(:button_html)
2429

‎app/models/access_token.rb‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def permission_name
4545
class Scopes
4646
extend Forwardable
4747

48-
delegate %i(each count select any? map) => :scopes
48+
delegate %i[each empty? count select any? map] => :scopes
4949

5050
def initialize(scopes)
5151
@scopes = scopes

0 commit comments

Comments
 (0)