Skip to content

Commit ea17e4b

Browse files
Enhance API token management by adding source filtering options in the index view
- Implemented filtering of API tokens by source (CLI, Web) in the `ApiTokensController#index` action. - Updated the index view to include links for filtering tokens based on their source, improving user experience.
1 parent 15cd364 commit ea17e4b

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

app/controllers/api_tokens_controller.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,18 @@ class ApiTokensController < ApplicationController
66
# GET /api_tokens or /api_tokens.json
77
def index
88
@api_tokens = policy_scope(ApiToken).order(last_used: :desc)
9+
10+
# Filter by source if provided
11+
case params[:source]
12+
when 'cli'
13+
@api_tokens = @api_tokens.cli_tokens
14+
when 'web'
15+
@api_tokens = @api_tokens.web_tokens
16+
# when 'mobile'
17+
# @api_tokens = @api_tokens.where(source: 'mobile')
18+
# 'all' or nil shows all tokens
19+
end
20+
921
authorize ApiToken
1022
end
1123

app/views/api_tokens/index.html.erb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,14 @@
66
<%= render partial: 'shared/button_group', locals: { buttons: { "New" => new_api_token_path } } %>
77
<% end %>
88
</div>
9+
<div class="flex justify-start items-center mb-3">
10+
<div class="flex items-center">
11+
<% source_filter = params[:source] %>
12+
<%= link_to 'All', api_tokens_path, class: "p-3 mr-4 pb-1 border-b-2 hover:border-sky-500 #{'border-sky-500' if source_filter.blank?}" %>
13+
<%= link_to 'CLI', api_tokens_path(source: 'cli'), class: "p-3 mr-4 pb-1 border-b-2 hover:border-sky-500 #{'border-sky-500' if source_filter == 'cli'}" %>
14+
<%= link_to 'Web', api_tokens_path(source: 'web'), class: "p-3 mr-4 pb-1 border-b-2 hover:border-sky-500 #{'border-sky-500' if source_filter == 'web'}" %>
15+
</div>
16+
</div>
917
<ul id="api_tokens" class="min-w-full list-none p-0">
1018
<li class="font-bold grid grid-cols-1 sm:grid-cols-5 text-xs text-stone-800 bg-stone-200 py-2 rounded-t-lg">
1119
<div class="p-2">

0 commit comments

Comments
 (0)