-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3895 from 3scale/THREESCALE-11178_new_edit_token
🦋 Update New/Edit Access Token page
- Loading branch information
Showing
14 changed files
with
265 additions
and
35 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
# frozen_string_literal: true | ||
|
||
class PatternflyCheckBoxesInput < Formtastic::Inputs::CheckBoxesInput | ||
delegate :tag, to: :template | ||
|
||
def to_html | ||
tag.div(class: 'pf-c-form__group') do | ||
label + control | ||
end | ||
end | ||
|
||
def label | ||
tag.div(class: 'pf-c-form__group-label') do | ||
tag.label(class: 'pf-c-form__label', for: input_html_options[:id]) do | ||
tag.span(label_text, class: 'pf-c-form__label-text') | ||
end | ||
end | ||
end | ||
|
||
def control | ||
tag.div(class: 'pf-c-form__group-control') do | ||
collection.map { |item| choice_html(item) }.reduce(&:concat) << | ||
helper_text_invalid | ||
end | ||
end | ||
|
||
def choice_html(choice) | ||
tag.div(class: 'pf-c-check') do | ||
checkbox_input(choice) + choice_label(choice) | ||
end | ||
end | ||
|
||
def checkbox_input(choice) | ||
value = choice_value(choice) | ||
template.check_box_tag( | ||
input_name, | ||
value, | ||
checked?(value), | ||
extra_html_options(choice).merge(id: choice_input_dom_id(choice), | ||
class: 'pf-c-check__input', | ||
required: false) | ||
) | ||
end | ||
|
||
def choice_label(choice) | ||
label_text = choice[0] | ||
tag.label(label_text, class: 'pf-c-check__label', | ||
for: choice_input_dom_id(choice)) | ||
end | ||
|
||
def helper_text_invalid | ||
return if errors.empty? | ||
|
||
template.render partial: 'shared/pf_error_helper_text', locals: { error: errors.first } | ||
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
22 changes: 7 additions & 15 deletions
22
app/views/provider/admin/user/access_tokens/_form.html.slim
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,17 +1,9 @@ | ||
= semantic_form_for access_token, url: [:provider, :admin, :user, access_token] do |f| | ||
= form.input :name, as: :patternfly_input, | ||
input_html: { autofocus: true } | ||
|
||
= f.inputs do | ||
= f.input :name, input_html: { autofocus: true } | ||
= f.input :scopes, | ||
as: :check_boxes, | ||
collection: access_token.available_scopes.to_a | ||
= form.input :scopes, as: :patternfly_check_boxes, | ||
collection: @access_token.available_scopes.to_collection_for_check_boxes | ||
|
||
= f.input :permission, as: :select, collection: access_token.available_permissions, include_blank: false | ||
|
||
|
||
= f.actions | ||
= f.commit_button | ||
- unless access_token.new_record? | ||
= link_to 'Delete', provider_admin_user_access_token_path(@access_token), | ||
data: {confirm: 'Are you sure?'}, method: :delete, | ||
title: 'Delete Access Token', class: 'action delete' | ||
= form.input :permission, as: :patternfly_select, | ||
collection: @access_token.available_permissions, | ||
include_blank: false |
19 changes: 17 additions & 2 deletions
19
app/views/provider/admin/user/access_tokens/edit.html.slim
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,3 +1,18 @@ | ||
- content_for :page_header_title, 'Edit Access Token' | ||
- content_for :page_header_title, t('.page_header_title') | ||
|
||
- content_for :javascripts do | ||
= javascript_packs_with_chunks_tag 'pf_form' | ||
|
||
div class="pf-c-card" | ||
div class="pf-c-card__body" | ||
= semantic_form_for @access_token, builder: Fields::PatternflyFormBuilder, | ||
url: [:provider, :admin, :user, @access_token], | ||
html: { class: 'pf-c-form pf-m-limit-width' } do |f| | ||
= render 'form', form: f | ||
|
||
= f.actions do | ||
= f.commit_button t('.submit_button_label') | ||
= f.delete_button 'Delete', provider_admin_user_access_token_path(@access_token), | ||
data: { confirm: 'Are you sure?' }, | ||
title: 'Delete Access Token' | ||
|
||
= render 'form', access_token: @access_token |
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,3 +1,22 @@ | ||
- content_for :page_header_title, 'New Access Token' | ||
- content_for :page_header_title, t('.page_header_title') | ||
|
||
= render 'form', access_token: @access_token | ||
- content_for :javascripts do | ||
= javascript_packs_with_chunks_tag 'pf_form' | ||
|
||
div class="pf-c-card" | ||
div class="pf-c-card__body" | ||
= semantic_form_for @access_token, builder: Fields::PatternflyFormBuilder, | ||
url: [:provider, :admin, :user, @access_token], | ||
html: { class: 'pf-c-form pf-m-limit-width' } do |f| | ||
= f.input :name, as: :patternfly_input, | ||
input_html: { autofocus: true } | ||
|
||
= f.input :scopes, as: :patternfly_check_boxes, | ||
collection: @access_token.available_scopes.to_collection_for_check_boxes | ||
|
||
= f.input :permission, as: :patternfly_select, | ||
collection: @access_token.available_permissions, | ||
include_blank: false | ||
|
||
= f.actions do | ||
= f.commit_button t('.submit_button_label') |
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 was deleted.
Oops, something went wrong.
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,100 @@ | ||
@javascript | ||
Feature: Provider Admin Access tokens | ||
|
||
As an admin I want to be able to read, create and edit access tokens | ||
|
||
Background: | ||
Given a provider is logged in | ||
And they go to the provider personal page | ||
|
||
Rule: Index page | ||
Background: | ||
Given the provider has the following access tokens: | ||
| Name | Scopes | Permission | | ||
| Potato | Analytics API | Read Only | | ||
| Banana | Billing API | Read & Write | | ||
And they go to the personal tokens page | ||
|
||
Scenario: Navigation to index page | ||
Given they go to the provider dashboard | ||
When they select "Account Settings" from the context selector | ||
And press "Personal" within the main menu | ||
And follow "Tokens" within the main menu's section Personal | ||
Then the current page is the personal tokens page | ||
|
||
Scenario: Tokens are listed in a table | ||
Then the table should contain the following: | ||
| Name | Scopes | Permission | | ||
| Potato | Analytics API | Read Only | | ||
| Banana | Billing API | Read & Write | | ||
|
||
Rule: New page | ||
Background: | ||
Given they go to the new access token page | ||
|
||
Scenario: Navigation to the new page | ||
Given they go to the personal tokens page | ||
When they follow "Add Access Token" | ||
Then the current page is the new access token page | ||
|
||
Scenario: New access token required fields | ||
When the current page is the new access token page | ||
Then there is a required field "Name" | ||
And there is a required field "Scopes" | ||
And there is a required field "Permission" | ||
And the submit button is enabled | ||
|
||
Scenario: Create access tokens without required fields | ||
When they press "Create Access Token" | ||
Then field "Name" has inline error "can't be blank" | ||
And field "Scopes" has inline error "select at least one scope" | ||
And field "Permission" has no inline error | ||
|
||
Scenario: Create access token | ||
When they press "Create Access Token" | ||
And the form is submitted with: | ||
| Name | LeToken | | ||
| Analytics API | Yes | | ||
| Permission | Read & Write | | ||
Then the current page is the personal tokens page | ||
And they should see the flash message "Access token was successfully created" | ||
And should see the following details: | ||
| Name | LeToken | | ||
| Scopes | Analytics API | | ||
| Permission | Read & Write | | ||
And there should be a link to "I have copied the token" | ||
|
||
Rule: Edit page | ||
Background: | ||
Given the provider has the following access tokens: | ||
| Name | Scopes | Permission | | ||
| LeToken | Billing API, Analytics API | Read Only | | ||
And they go to the access token's edit page | ||
|
||
Scenario: Navigation to edit page | ||
Given they go to the personal tokens page | ||
When they follow "Edit" in the 1st row within the access tokens table | ||
Then the current page is the access token's edit page | ||
|
||
Scenario: Edit access token | ||
When the form is submitted with: | ||
| Name | New Token Name | | ||
| Billing API | No | | ||
| Permission | Read & Write | | ||
Then they should see the flash message "Access Token was successfully updated." | ||
Then the table should contain the following: | ||
| Name | Scopes | Permission | | ||
| New Token Name | Analytics API | Read & Write | | ||
|
||
Scenario: Edit access tokens without required fields | ||
When the form is submitted with: | ||
| Name | | | ||
Then field "Name" has inline error "can't be blank" | ||
|
||
Scenario: Delete access token | ||
Given the current page is access token "LeToken" edit page | ||
When they follow "Delete" | ||
And confirm the dialog | ||
Then the current page is the personal tokens page | ||
And they should see the flash message "Access token was successfully deleted" | ||
But should not see "LeToken" |
16 changes: 16 additions & 0 deletions
16
features/step_definitions/provider/admin/user/access_tokens_steps.rb
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,16 @@ | ||
# frozen_string_literal: true | ||
|
||
# Example: | ||
# | ||
# Given a provider | ||
# And the provider has the following access tokens: | ||
# | Name | Scopes | Permission | | ||
# | LeToken | Billing API, Analytics API | Read Only | | ||
# | ||
Given "{provider} has the following access tokens:" do |provider, table| | ||
transform_access_tokens_table(table) | ||
|
||
table.hashes.each do |options| | ||
@access_token = FactoryBot.create(:access_token, owner: @provider.admin_users.first!, **options) | ||
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