Skip to content

Commit

Permalink
Editor: allow editors (with feature enabled) to copy tokens
Browse files Browse the repository at this point in the history
  • Loading branch information
skelz0r committed Jan 10, 2025
1 parent 560e044 commit e726c68
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
8 changes: 8 additions & 0 deletions app/views/editor/authorization_requests/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,14 @@
<% if authorization_request.token %>
<%= render partial: 'shared/tokens/detail_short', locals: { token: authorization_request.token.decorate } %>
<% end %>
<% if current_editor.copy_token? %>
<div class="copy-token" data-controller="clipboard" data-clipboard-alert-message-value="Jeton copié">
<%= button_tag 'Copier le jeton', class: 'fr-btn fr-btn--sm fr-icon-window-fill fr-btn--icon-right', id: dom_id(authorization_request.token, :copy_token_button), data: { action: 'click->clipboard#copy' } %>

<% hashed_value = true_user == current_user ? authorization_request.token.rehash : 'NotAValidValue' %>
<input id="<%= dom_id(authorization_request.token, :token_hash) %>" class="fr-input" style="position: absolute; left: -9999px" type="text" data-clipboard-target="source" readonly value="<%= hashed_value %>" />
</div>
<% end %>
</td>
<td class="authorization_request-siret">
<a href="https://annuaire-entreprises.data.gouv.fr/etablissement/<%= authorization_request.siret %>" target="_blank">
Expand Down
27 changes: 26 additions & 1 deletion spec/features/editor/authorization_requests_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
RSpec.describe 'Editor: authorization requests', app: :api_entreprise do
let(:user) { create(:user, editor:) }
let(:editor) { create(:editor, form_uids: %w[form1 form2]) }
let(:editor) { create(:editor, copy_token:, form_uids: %w[form1 form2]) }
let(:copy_token) { false }

before do
login_as(user)
Expand Down Expand Up @@ -32,6 +33,30 @@

expect(page).to have_content('Nouveau jeton à utiliser')
end

describe 'copy token behaviour' do
context 'when editor has no copy token' do
let(:copy_token) { false }

it 'does not have copy token button' do
visit editor_authorization_requests_path

expect(page).to have_no_css('.copy-token')
expect(page.html).not_to include(valid_authorization_requests.first.token.rehash)
end
end

context 'when editor can copy token' do
let(:copy_token) { true }

it 'has a button to copy token' do
visit editor_authorization_requests_path

expect(page).to have_css('.copy-token', count: 2)
expect(page.html).to include(valid_authorization_requests.first.token.rehash)
end
end
end
end

describe 'search' do
Expand Down

0 comments on commit e726c68

Please sign in to comment.