Skip to content

Commit 28894a3

Browse files
authored
Merge pull request #4254 from 3scale/THREESCALE-9869_tokens_page
🦋 Updates Tokens page
2 parents 0a34a66 + 5671b77 commit 28894a3

29 files changed

Lines changed: 313 additions & 208 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, :services_with_token
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 services_with_token
64+
@services_with_token ||= 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
@@ -14,4 +14,11 @@ def display_name
1414
def informal_name
1515
first_name.presence || last_name.presence || username
1616
end
17+
18+
def accessible_services_with_token
19+
return Service.none unless has_permission?(:plans)
20+
21+
accessible_services.joins(:service_tokens)
22+
.includes(:service_tokens)
23+
end
1724
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 & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -78,27 +78,20 @@ def pf_toast_alert(title, **options)
7878
end
7979
end
8080

81-
# TODO: this action button is used only in app/views/provider/admin/account/users/index.html.slim
82-
# right now, but could be used in other tables. Eliminate existing repetition by using this helper
8381
def pf_delete_table_action(url, button_options = {})
84-
form_attributes = { method: :delete }
85-
86-
button_class = 'pf-c-button pf-m-link pf-m-danger'
87-
88-
confirm = button_options.delete(:confirm) || 'It will be permanently delete. Are you sure?'
82+
confirm = button_options.delete(:confirm) || I18n.t('shared.delete_button_confirm')
83+
title = button_options.delete(:title) || I18n.t('shared.delete_button_title')
8984

9085
button_attributes = { type: :submit,
91-
class: button_class.strip,
86+
class: 'pf-c-button pf-m-link pf-m-danger',
87+
title:,
9288
'data-confirm': confirm }.merge(button_options)
9389

94-
span = tag.span class: 'pf-c-button__icon pf-m-start' do
95-
tag.i class: "fas fa-trash", 'aria-hidden': 'true'
96-
end
97-
label = 'Delete'
98-
99-
form_tag(url, form_attributes) do
90+
form_tag(url, method: :delete) do
10091
tag.button(**button_attributes) do
101-
span + label
92+
tag.span class: 'pf-c-button__icon pf-m-start' do
93+
tag.i class: 'fas fa-trash', 'aria-hidden': 'true'
94+
end
10295
end
10396
end
10497
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+
}

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

app/models/user.rb

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -191,15 +191,6 @@ def allowed_access_token_scopes
191191
AccessToken.scopes.allowed_for(self)
192192
end
193193

194-
def accessible_service_tokens
195-
if has_permission?(:plans)
196-
accessible_services.joins(:service_tokens)
197-
.includes(:service_tokens).map(&:active_service_token)
198-
else
199-
[]
200-
end
201-
end
202-
203194
def accessible_cinstances
204195
account.provided_cinstances.permitted_for(self)
205196

0 commit comments

Comments
 (0)