Skip to content

🚧 🦋 Updates Tokens page#4254

Open
josemigallas wants to merge 17 commits into
masterfrom
THREESCALE-9869_tokens_page
Open

🚧 🦋 Updates Tokens page#4254
josemigallas wants to merge 17 commits into
masterfrom
THREESCALE-9869_tokens_page

Conversation

@josemigallas
Copy link
Copy Markdown
Contributor

THREESCALE-9869: Tokens index page

😄 Improved tokens index page
😅 Slight change to edit token page
😓 Needed to change users page for consistency with table actions (see image below).

Before:

Screenshot 2026-03-19 at 11 31 22 Screenshot 2026-03-19 at 11 31 49 Screenshot 2026-03-19 at 11 30 31 Screenshot 2026-03-19 at 11 30 41

After

  • Empty states:
Screenshot 2026-03-18 at 10 30 35
  • Create button transformed into Card action. Edit button replaced with name link. Delete button transformed into icon button:
Screenshot 2026-03-18 at 10 32 20
  • Confirmation message improved:
Screenshot 2026-03-18 at 10 36 03
  • "new token" page is improved by adding a proper alert message:
Screenshot 2026-03-18 at 10 57 19

User index page

For consistency and since both tables use the same button icon component, this page has also been updated (edit and delete links):
Screenshot 2026-03-18 at 12 18 05

Edit page action buttons

Added cancel button (goes back to index) and moved delete to the right for better UX:
Screenshot 2026-03-18 at 10 35 53

@josemigallas josemigallas requested a review from a team March 19, 2026 10:33
@josemigallas josemigallas self-assigned this Mar 19, 2026
Comment on lines +17 to +18
if (id = flash[:token]) && (token = current_user.access_tokens.find_by(id:))
render 'access_token_created', locals: { token: }
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Used to be handled in the template, I think it's the controller's responsibility and it renders now a completely different template without instantiating the presenter or fetching any tokens.

@qltysh
Copy link
Copy Markdown

qltysh Bot commented Mar 19, 2026

❌ 61 blocking issues (61 total)

Tool Category Rule Count
reek Lint AccessToken#generate_if_missing calls 'self.class' 2 times 49
reek Lint ApiDocs::ProviderUserData#service_tokens refers to 'service' more than self (maybe move it to another class?) 2
rubocop Lint Block has too many lines. [44/25] 2
reek Lint Provider::Admin::User::AccessTokensControllerTest assumes too much for instance variable '@admin' 2
rubocop Lint Avoid using update\_columns because it skips validations. 2
rubocop Lint Class has too many lines. [354/200] 2
reek Lint AccessToken#self.find_from_value has approx 8 statements 1
rubocop Lint Use ActionDispatch::IntegrationTest instead. 1

Comment thread app/controllers/provider/admin/user/access_tokens_controller.rb
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed this component to be an icon button (much better looking) and that's why users page needed to be updated.

}

.pf-c-form__actions {
.pf-c-button.pf-m-danger {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will include action-list styles to every form and move Delete buttons to the far right (if the form implements action-list, which only CMS ones do and they already are in the right).

Comment thread app/models/user.rb Outdated
[]
end
def accessible_services_with_token
return Service.none unless has_permission?(:plans) # TODO: is this permission check handled by accessible_services already?
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible for an user not to have plans permission AND have accessible services?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it is possible. There are four permission types (including :plans) that make accessible_services return a non-empty array (of course, given that some - or ALL - services are enabled).

>> u.accessible_services.count
=> 27

>> u.has_permission?(:plans)
~> admin25 has_permission?(plans) => false
=> false

>> u.admin_sections
=> #<Set: {:partners, :monitoring, :policy_registry}>

However, indeed, at the moment the page only shows service tokens to those users that have :plans permission explicitly.

@user.allowed_access_token_scopes.empty?
end

def service_tokens
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Confusing name, I know.


- content_for :javascripts do
= javascript_packs_with_chunks_tag 'empty_state'
= stylesheet_packs_chunks_tag 'empty_state'
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not related to this PR actually, but a minor typo. empty_state is a SCSS file, not TS.

@josemigallas josemigallas force-pushed the THREESCALE-9869_tokens_page branch 2 times, most recently from dc78ed8 to 4c4cbc1 Compare March 19, 2026 14:59
Comment thread app/helpers/patternfly_components_helper.rb
Comment thread features/provider/admin/user/access_tokens.feature Outdated
* New token are generated already hashed
* Old tokens are hashed first time they are used

Co-Authored-By: Claude <noreply@anthropic.com>
Comment thread config/locales/en.yml Outdated
jlledom and others added 8 commits March 20, 2026 14:56
* Remove dead code
* Render on create instead of redirecting, so the user can see the token
  while still in memory
* New template to show the generated token. It was embedded in the index
  template before
* Add I18N, by Claude

Co-authored-by: Claude <no-reply@anthropic.com>
Co-Authored-By: Claude <noreply@anthropic.com>
mayorova
mayorova previously approved these changes Mar 20, 2026
Copy link
Copy Markdown
Contributor

@mayorova mayorova left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's hard to review the template changes, but the views look good to me.

@mayorova
Copy link
Copy Markdown
Contributor

mayorova commented Mar 20, 2026

Careful though, I think this will conflict with #4236 ...

UPDATE: I don't think, I am sure 😅 huge conflict incoming...

@jlledom
Copy link
Copy Markdown
Contributor

jlledom commented Mar 23, 2026

Careful though, I think this will conflict with #4236 ...

UPDATE: I don't think, I am sure 😅 huge conflict incoming...

Worst timing ever!

It's fine, just merge this first and I'll manage the conflicts

Comment thread app/models/user.rb Outdated
[]
end
def accessible_services_with_token
return Service.none unless has_permission?(:plans) # TODO: is this permission check handled by accessible_services already?
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please don't add TODOs to the code. In this case, this is not even something to do, it's a question.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is my way of attacting reviewers' attention when I have doubts. Not a real TODO as you pointer out.

On a side note I used to hate TODOs as well, but honestly it's the only way to register small future tasks/improvements rather than opening a whole new task in JIRA. Also I hate JIRA even more than TODOs 😄.

Comment thread app/models/user.rb Outdated
else
[]
end
def accessible_services_with_token
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why this change? what was wrong with the previous method?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

empty array was simply not proper. Other than that, the implementation looked ugly.

end

def service_tokens
@service_tokens ||= @user.accessible_services_with_token
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If accessible_services_with_token is now returning services instead of tokens, shouldn't the instance variable here be called @services instead of @service_tokens?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, I left it half baked I guess. It's better now.

@josemigallas josemigallas force-pushed the THREESCALE-9869_tokens_page branch from 4c4cbc1 to ddb14dd Compare April 1, 2026 08:27
@josemigallas josemigallas changed the base branch from master to THREESCALE-12408-acess-tokens-protection April 1, 2026 08:29
@josemigallas josemigallas force-pushed the THREESCALE-9869_tokens_page branch from ddb14dd to cdec879 Compare April 1, 2026 12:11
Comment thread test/factories/access_token.rb Outdated
scopes { ['stats'] }
permission { 'rw' }
sequence(:name) { |n| "Alaska_#{n}" }
sequence(:name) { |n| "token_#{n}" }
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was suggested by our beloved AI colleague to make it more generic.

@josemigallas josemigallas requested review from jlledom and mayorova April 1, 2026 12:27
@josemigallas
Copy link
Copy Markdown
Contributor Author

@damianpm @jlledom
I fixed all the typos pointed out and rebased this branch on top of the migration to avoid problems. Worth mentioning it only generated 1 conflict but after that I have to go double check all the changes. Anyway I like it more now so it's a win-win situation.

Now the review is on top of Joan's changes.

@josemigallas josemigallas changed the title 🦋 Updates Tokens page 🚧 🦋 Updates Tokens page Apr 1, 2026
dd class="pf-c-description-list__description"
div class="pf-c-description-list__text"
= token.plaintext_value
= token.value
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should how the plain text value. This is now showing the token hash in DB, which is meaningless for the user.

Suggested change
= token.value
= token.plaintext_value

Comment on lines 80 to 81
| Expires at | Never expires |
And there should be a link to "I have copied the token"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it should assert the plain text token is shown here. That would have caught the error in the show template.

Comment on lines +39 to +45
test 'show is rendered when a token is created' do
expires_at = 1.week.from_now.utc.iso8601
post :create, params: { access_token: { name: 'Le Token', scopes: ['account_management'], permission: 'ro', expires_at: } }

assert_response :success
assert_template :show
end
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Beside from the cuke, this is another place where we could assert the plain token presence in the show template. Either of both is fine for me.

@github-actions
Copy link
Copy Markdown

This PR is stale because it has not received activity for more than 30 days. Remove stale label or comment or this will be closed in 15 days.

@github-actions github-actions Bot added the Stale label May 11, 2026
@jlledom jlledom removed the Stale label May 11, 2026
@jlledom jlledom force-pushed the THREESCALE-12408-acess-tokens-protection branch 3 times, most recently from 43c3ab6 to 4865027 Compare May 13, 2026 14:32
Base automatically changed from THREESCALE-12408-acess-tokens-protection to master May 13, 2026 15:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants