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',
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 %>
|
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|
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
|