diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f33954ca61..9e2c14e703 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -134,7 +134,14 @@ jobs: path: node_modules - name: Install JS dependencies run: yarn install + - name: Cache precompiled assets + id: cache-precompiled-assets + uses: actions/cache@v4 + with: + key: assets-${{ hashFiles('yarn.lock', 'app/javascript/**') }} + path: app/assets/builds - name: Precompile assets + if: steps.cache-precompiled-assets.outputs.cache-hit != 'true' # Skip if cache was restored run: yarn run build - name: Prepare runtime log cache key run: ls spec/**/*.rb > tmp/spec_files.txt @@ -202,7 +209,14 @@ jobs: path: node_modules - name: Install JS dependencies run: yarn install + - name: Cache precompiled assets + id: cache-precompiled-assets + uses: actions/cache@v4 + with: + key: assets-${{ hashFiles('yarn.lock', 'app/javascript/**') }} + path: app/assets/builds - name: Precompile assets + if: steps.cache-precompiled-assets.outputs.cache-hit != 'true' # Skip if cache was restored run: yarn run build - name: Prepare runtime log cache key run: "ls spec/features/${{ matrix.dirname }}/**/*.rb > tmp/feature_spec_${{ matrix.dirname }}_files.txt" diff --git a/app/jobs/create_crisp_ticket_job.rb b/app/jobs/create_crisp_ticket_job.rb index 98f929730b..6f4ee8768f 100644 --- a/app/jobs/create_crisp_ticket_job.rb +++ b/app/jobs/create_crisp_ticket_job.rb @@ -32,6 +32,9 @@ def perform(nickname:, email:, phone:, subject:, message:, role:, domain:) domain, ], subject:, + device: { + locales: ["fr"], + }, } ) end diff --git a/app/services/merge_users_service.rb b/app/services/merge_users_service.rb index 71206fa72d..cc80a12fa0 100644 --- a/app/services/merge_users_service.rb +++ b/app/services/merge_users_service.rb @@ -25,8 +25,8 @@ def merge_annotations current_territory = @organisation.territory annotation_to_merge = @user_to_merge.annotations.find_by(territory: current_territory) - @user_target.annotate!(annotation_to_merge.content, territory: current_territory) - annotation_to_merge.destroy! + @user_target.annotate!(annotation_to_merge&.content, territory: current_territory) + annotation_to_merge&.destroy! end def merge_user_attributes diff --git a/config/anonymizer.yml b/config/anonymizer.yml index a09e2e740b..de20dd9005 100644 --- a/config/anonymizer.yml +++ b/config/anonymizer.yml @@ -49,7 +49,6 @@ tables: - city_name - case_number - logement - - notes - ants_pre_demande_number - franceconnect_openid_sub - encrypted_password diff --git a/db/migrate/20250303104258_remove_users_notes.rb b/db/migrate/20250303104258_remove_users_notes.rb new file mode 100644 index 0000000000..04d82b4054 --- /dev/null +++ b/db/migrate/20250303104258_remove_users_notes.rb @@ -0,0 +1,7 @@ +class RemoveUsersNotes < ActiveRecord::Migration[7.1] + def change + safety_assured do + remove_column :users, :notes, :text + end + end +end diff --git a/db/schema.rb b/db/schema.rb index 485ee60c67..19b00269b9 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[7.1].define(version: 2025_02_27_165927) do +ActiveRecord::Schema[7.1].define(version: 2025_03_03_104258) do # These are extensions that must be enabled in order to support this database enable_extension "pg_stat_statements" enable_extension "pgcrypto" @@ -795,7 +795,6 @@ t.string "case_number" t.string "address_details" t.integer "logement" - t.text "notes" t.string "ants_pre_demande_number" t.string "rdv_invitation_token" t.virtual "text_search_terms", type: :tsvector, as: "(((((setweight(to_tsvector('simple'::regconfig, translate(lower((COALESCE(last_name, ''::character varying))::text), 'àâäéèêëïîôöùûüÿç'::text, 'aaaeeeeiioouuuyc'::text)), 'A'::\"char\") || setweight(to_tsvector('simple'::regconfig, translate(lower((COALESCE(first_name, ''::character varying))::text), 'àâäéèêëïîôöùûüÿç'::text, 'aaaeeeeiioouuuyc'::text)), 'B'::\"char\")) || setweight(to_tsvector('simple'::regconfig, translate(lower((COALESCE(birth_name, ''::character varying))::text), 'àâäéèêëïîôöùûüÿç'::text, 'aaaeeeeiioouuuyc'::text)), 'C'::\"char\")) || setweight(to_tsvector('simple'::regconfig, (COALESCE(email, ''::character varying))::text), 'D'::\"char\")) || setweight(to_tsvector('simple'::regconfig, (COALESCE(phone_number_formatted, ''::character varying))::text), 'D'::\"char\")) || setweight(to_tsvector('simple'::regconfig, COALESCE((id)::text, ''::text)), 'D'::\"char\"))", stored: true diff --git a/spec/services/merge_users_service_spec.rb b/spec/services/merge_users_service_spec.rb index 444fed6f72..3d3f4947ae 100644 --- a/spec/services/merge_users_service_spec.rb +++ b/spec/services/merge_users_service_spec.rb @@ -4,8 +4,8 @@ # defaults let!(:organisation) { create(:organisation) } let(:attributes_to_merge) { [] } - let(:user_target) { create(:user, organisations: [organisation]) } - let(:user_to_merge) { create(:user, organisations: [organisation]) } + let!(:user_target) { create(:user, organisations: [organisation]) } + let!(:user_to_merge) { create(:user, organisations: [organisation]) } context "simply merge first_name" do let(:user_target) { create(:user, first_name: "Jean", last_name: "PAUL", email: "jean@paul.fr", organisations: [organisation]) } @@ -179,8 +179,8 @@ let!(:organisation2) { create(:organisation) } let!(:agent1) { create(:agent, basic_role_in_organisations: [organisation]) } let!(:agent2) { create(:agent, basic_role_in_organisations: [organisation2]) } - let(:user_target) { create(:user, referent_agents: [agent1], organisations: [organisation]) } - let(:user_to_merge) { create(:user, referent_agents: [agent2], organisations: [organisation, organisation2]) } + let!(:user_target) { create(:user, referent_agents: [agent1], organisations: [organisation]) } + let!(:user_to_merge) { create(:user, referent_agents: [agent2], organisations: [organisation, organisation2]) } it "does not move the agent from the other orga anything" do perform @@ -249,6 +249,46 @@ end end + context "only user to merge has an annotation" do + before do + user_to_merge.annotations.create!(territory: organisation.territory, content: "user to merge") + end + + it "deletes the annotation along with the merged user by default" do + expect { perform }.to change(Annotation, :count).by(-1).and(change(User, :count).by(-1)) + expect(user_target.annotations.find_by(territory: organisation.territory)).to be_nil + end + + context "when merging annotations" do + let(:attributes_to_merge) { [:annotation_content] } + + it "moves the annotation to the target user" do + perform + expect(user_target.annotation_for(organisation.territory)).to eq("user to merge") + end + end + end + + context "only target user has an annotation" do + before do + user_target.annotations.create!(territory: organisation.territory, content: "target user") + end + + it "keeps the annotation by default" do + expect { perform }.not_to change(Annotation, :count) + expect(user_target.annotation_for(organisation.territory)).to eq("target user") + end + + context "when merging annotations" do + let(:attributes_to_merge) { [:annotation_content] } + + it "deletes the annotation of the target user, to replace it with with the absence of annotation of the user to merge" do + expect { perform }.to change(Annotation, :count).by(-1) + expect(user_target.annotations.find_by(territory: organisation.territory)).to be_nil + end + end + end + context "when one user is connected by FranceConnect" do it "keep FranceConnect attributes when merged user logged once with franceconnect" do user_to_merge = create(:user, logged_once_with_franceconnect: true, franceconnect_openid_sub: "unechainedecharacteres", organisations: [organisation])