From 3543a798385b1b1751c6d920816566089d3bf6d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Loi=CC=88c=20Delmaire?= Date: Fri, 10 Jan 2025 10:08:27 +0100 Subject: [PATCH 1/4] Editor: add copy_token boolean --- db/migrate/20250110090753_add_can_copy_token_to_editors.rb | 5 +++++ db/schema.rb | 5 +++-- 2 files changed, 8 insertions(+), 2 deletions(-) create mode 100644 db/migrate/20250110090753_add_can_copy_token_to_editors.rb diff --git a/db/migrate/20250110090753_add_can_copy_token_to_editors.rb b/db/migrate/20250110090753_add_can_copy_token_to_editors.rb new file mode 100644 index 000000000..c19a6ff07 --- /dev/null +++ b/db/migrate/20250110090753_add_can_copy_token_to_editors.rb @@ -0,0 +1,5 @@ +class AddCanCopyTokenToEditors < ActiveRecord::Migration[8.0] + def change + add_column :editors, :copy_token, :boolean, default: false, null: false + end +end diff --git a/db/schema.rb b/db/schema.rb index 0d941be29..4d14b4b45 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,13 +10,13 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[8.0].define(version: 2024_12_07_111810) do +ActiveRecord::Schema[8.0].define(version: 2025_01_10_090753) do # These are extensions that must be enabled in order to support this database enable_extension "btree_gin" enable_extension "pg_catalog.plpgsql" enable_extension "pgcrypto" - create_table "access_logs", id: false, force: false, if_not_exists: true do |t| + create_table "access_logs", id: false, force: :cascade do |t| t.timestamptz "timestamp" t.uuid "token_id" end @@ -44,6 +44,7 @@ t.string "form_uids", default: [], array: true t.datetime "created_at", null: false t.datetime "updated_at", null: false + t.boolean "copy_token", default: false, null: false end create_table "good_job_batches", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| From 560e044e8f191daa9ed1d65ce6838c5cbd1b122a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Loi=CC=88c=20Delmaire?= Date: Fri, 10 Jan 2025 10:16:54 +0100 Subject: [PATCH 2/4] Enhance seeds --- app/lib/seeds.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/lib/seeds.rb b/app/lib/seeds.rb index 6ee5fbfd8..2924eb6a8 100644 --- a/app/lib/seeds.rb +++ b/app/lib/seeds.rb @@ -69,7 +69,8 @@ def create_contact def create_editor editor = Editor.create!( name: 'UMAD Corp', - form_uids: %w[umadcorp-form-api-entreprise umadcorp-form-api-particulier] + form_uids: %w[umadcorp-form-api-entreprise umadcorp-form-api-particulier], + copy_token: true ) create_user( email: 'editeur@yopmail.com', From e726c686c374780013eab99f5c7e3cee8bbc0a45 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Loi=CC=88c=20Delmaire?= Date: Fri, 10 Jan 2025 10:20:46 +0100 Subject: [PATCH 3/4] Editor: allow editors (with feature enabled) to copy tokens --- .../authorization_requests/index.html.erb | 8 ++++++ .../editor/authorization_requests_spec.rb | 27 ++++++++++++++++++- 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/app/views/editor/authorization_requests/index.html.erb b/app/views/editor/authorization_requests/index.html.erb index f649b130f..6374b0577 100644 --- a/app/views/editor/authorization_requests/index.html.erb +++ b/app/views/editor/authorization_requests/index.html.erb @@ -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? %> +
+ <%= 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' %> + +
+ <% end %> diff --git a/spec/features/editor/authorization_requests_spec.rb b/spec/features/editor/authorization_requests_spec.rb index f5ae20753..e25a46130 100644 --- a/spec/features/editor/authorization_requests_spec.rb +++ b/spec/features/editor/authorization_requests_spec.rb @@ -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) @@ -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 From 689a03000478981f345f0df87dff71bf4398694f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Loi=CC=88c=20Delmaire?= Date: Fri, 10 Jan 2025 10:39:16 +0100 Subject: [PATCH 4/4] Admin: displays editors enabled features --- app/views/admin/editors/index.html.erb | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/app/views/admin/editors/index.html.erb b/app/views/admin/editors/index.html.erb index 599618e5e..cbf4a8567 100644 --- a/app/views/admin/editors/index.html.erb +++ b/app/views/admin/editors/index.html.erb @@ -10,6 +10,7 @@ 'ID', 'Nom', 'Formulaires', + 'Features', 'Emails', ].each do |attr| %> @@ -39,6 +40,11 @@ <% end %> + +
    +
  • Copier jeton : <%= editor.copy_token? ? '✅' : '❌' %>
  • +
+ <% if editor.users %>