From 32f176acfbc07e32ca3f66dfe851b22ac7079dc4 Mon Sep 17 00:00:00 2001 From: Isabelle Lafont Date: Wed, 15 May 2024 16:51:40 +0200 Subject: [PATCH 1/5] Remove sub instructor to a user --- ...roles_to_sub_instructor_api_particulier.rb | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 backend/db/migrate/20240515144839_remove_cnous_roles_to_sub_instructor_api_particulier.rb diff --git a/backend/db/migrate/20240515144839_remove_cnous_roles_to_sub_instructor_api_particulier.rb b/backend/db/migrate/20240515144839_remove_cnous_roles_to_sub_instructor_api_particulier.rb new file mode 100644 index 000000000..7fbd5d021 --- /dev/null +++ b/backend/db/migrate/20240515144839_remove_cnous_roles_to_sub_instructor_api_particulier.rb @@ -0,0 +1,34 @@ +class RemoveCnousRolesToSubInstructorApiParticulier < ActiveRecord::Migration[7.0] + def up + remove_roles( + ["carine.burricand@enseignementsup.gouv.fr"], + ["api_particulier:cnous:subscriber","api_particulier:cnous:reporter"] + ) + end + + def down + add_roles( + ["carine.burricand@enseignementsup.gouv.fr"], + ["api_particulier:cnous:subscriber","api_particulier:cnous:reporter"] + ) + end + + private + + def add_roles(emails, roles_to_add) + users = User.where(email: emails) + users.each do |user| + current_roles = user.roles || [] + user.update(roles: current_roles + roles_to_add) + end + end + + def remove_roles(emails, roles_to_remove) + users = User.where(email: emails) + users.each do |user| + current_roles = user.roles || [] + updated_roles = current_roles - roles_to_remove + user.update(roles: updated_roles) + end + end +end From 40e79333be8822d74eac4336b014b534dd9349fe Mon Sep 17 00:00:00 2001 From: Mehdi Farsi Date: Fri, 17 May 2024 14:10:47 +0200 Subject: [PATCH 2/5] store subinstructor email in credentials --- backend/config/credentials/production.yml.enc | 2 +- ..._remove_cnous_roles_to_sub_instructor_api_particulier.rb | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/backend/config/credentials/production.yml.enc b/backend/config/credentials/production.yml.enc index dade264aa..ebadd0c12 100644 --- a/backend/config/credentials/production.yml.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40PYroruwe5WRGK3AW4V58ZkbNZekgXwQ2oLtmsybUOI445SpSH2KucZ25NlFi0eNr8hEVPlErCSQS75WiQ8N38cvBj9dk91MNh0D1LGPG/7nuywqHr2+AUC8motiY181sVkwJwaSrnf4WK7UvZl8Y9bGugKgYEw6xGGfvwU8mIWr634t1ddaVJMuFBFmj5SQVBBKAtyo3k=--ueMcJPtiNoZxMJGd--xKkKsq5nYP5KVgDP8Yvtpw== \ No newline at end of file diff --git a/backend/db/migrate/20240515144839_remove_cnous_roles_to_sub_instructor_api_particulier.rb b/backend/db/migrate/20240515144839_remove_cnous_roles_to_sub_instructor_api_particulier.rb index 7fbd5d021..a52a2648d 100644 --- a/backend/db/migrate/20240515144839_remove_cnous_roles_to_sub_instructor_api_particulier.rb +++ b/backend/db/migrate/20240515144839_remove_cnous_roles_to_sub_instructor_api_particulier.rb @@ -1,14 +1,14 @@ class RemoveCnousRolesToSubInstructorApiParticulier < ActiveRecord::Migration[7.0] def up remove_roles( - ["carine.burricand@enseignementsup.gouv.fr"], + [subinstructor_email], ["api_particulier:cnous:subscriber","api_particulier:cnous:reporter"] ) end def down add_roles( - ["carine.burricand@enseignementsup.gouv.fr"], + [subinstructor_email], ["api_particulier:cnous:subscriber","api_particulier:cnous:reporter"] ) end @@ -31,4 +31,6 @@ def remove_roles(emails, roles_to_remove) user.update(roles: updated_roles) end end + + def subinstructor_email = Rails.application.credentials.enseignementsup_subinstructor.email end From b9a0d3419f1eaefc7bceef88a96dadd53bf6ce4c Mon Sep 17 00:00:00 2001 From: Mehdi Farsi Date: Fri, 17 May 2024 14:21:33 +0200 Subject: [PATCH 3/5] fix linter --- ...39_remove_cnous_roles_to_sub_instructor_api_particulier.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/backend/db/migrate/20240515144839_remove_cnous_roles_to_sub_instructor_api_particulier.rb b/backend/db/migrate/20240515144839_remove_cnous_roles_to_sub_instructor_api_particulier.rb index a52a2648d..a68a87808 100644 --- a/backend/db/migrate/20240515144839_remove_cnous_roles_to_sub_instructor_api_particulier.rb +++ b/backend/db/migrate/20240515144839_remove_cnous_roles_to_sub_instructor_api_particulier.rb @@ -2,14 +2,14 @@ class RemoveCnousRolesToSubInstructorApiParticulier < ActiveRecord::Migration[7. def up remove_roles( [subinstructor_email], - ["api_particulier:cnous:subscriber","api_particulier:cnous:reporter"] + ["api_particulier:cnous:subscriber", "api_particulier:cnous:reporter"] ) end def down add_roles( [subinstructor_email], - ["api_particulier:cnous:subscriber","api_particulier:cnous:reporter"] + ["api_particulier:cnous:subscriber", "api_particulier:cnous:reporter"] ) end From aa8d6b8a9f4ef65529a17bcccbdeecc89d0da97d Mon Sep 17 00:00:00 2001 From: Mehdi Farsi Date: Tue, 21 May 2024 09:44:15 +0200 Subject: [PATCH 4/5] make instructor email optional --- ...39_remove_cnous_roles_to_sub_instructor_api_particulier.rb | 4 ++++ backend/db/schema.rb | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/backend/db/migrate/20240515144839_remove_cnous_roles_to_sub_instructor_api_particulier.rb b/backend/db/migrate/20240515144839_remove_cnous_roles_to_sub_instructor_api_particulier.rb index a68a87808..64548d9f4 100644 --- a/backend/db/migrate/20240515144839_remove_cnous_roles_to_sub_instructor_api_particulier.rb +++ b/backend/db/migrate/20240515144839_remove_cnous_roles_to_sub_instructor_api_particulier.rb @@ -1,5 +1,8 @@ class RemoveCnousRolesToSubInstructorApiParticulier < ActiveRecord::Migration[7.0] def up + + return unless subinstructor_exists? + remove_roles( [subinstructor_email], ["api_particulier:cnous:subscriber", "api_particulier:cnous:reporter"] @@ -33,4 +36,5 @@ def remove_roles(emails, roles_to_remove) end def subinstructor_email = Rails.application.credentials.enseignementsup_subinstructor.email + def subinstructor_exists? = Rails.application.credentials.enseignementsup_subinstructor.present? end diff --git a/backend/db/schema.rb b/backend/db/schema.rb index a9fb2bfd1..e3d9e681e 100644 --- a/backend/db/schema.rb +++ b/backend/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[7.0].define(version: 2024_04_22_141145) do +ActiveRecord::Schema[7.0].define(version: 2024_05_15_144839) do # These are extensions that must be enabled in order to support this database enable_extension "fuzzystrmatch" enable_extension "plpgsql" From a9cc3f49e849569ac499af5e0b2c1ee7ce56855a Mon Sep 17 00:00:00 2001 From: Mehdi Farsi Date: Tue, 21 May 2024 09:53:43 +0200 Subject: [PATCH 5/5] fix offenses --- ...4839_remove_cnous_roles_to_sub_instructor_api_particulier.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/db/migrate/20240515144839_remove_cnous_roles_to_sub_instructor_api_particulier.rb b/backend/db/migrate/20240515144839_remove_cnous_roles_to_sub_instructor_api_particulier.rb index 64548d9f4..3f70a9a12 100644 --- a/backend/db/migrate/20240515144839_remove_cnous_roles_to_sub_instructor_api_particulier.rb +++ b/backend/db/migrate/20240515144839_remove_cnous_roles_to_sub_instructor_api_particulier.rb @@ -1,6 +1,5 @@ class RemoveCnousRolesToSubInstructorApiParticulier < ActiveRecord::Migration[7.0] def up - return unless subinstructor_exists? remove_roles( @@ -36,5 +35,6 @@ def remove_roles(emails, roles_to_remove) end def subinstructor_email = Rails.application.credentials.enseignementsup_subinstructor.email + def subinstructor_exists? = Rails.application.credentials.enseignementsup_subinstructor.present? end