-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1486 from betagouv/feature/dat-352-changement-de-…
…droit-sous-instructeur Remove sub instructor to a user
- Loading branch information
Showing
3 changed files
with
42 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
g/Bqx3+hP7u6Pnqh/cnhpGp9pkvWdFiWA0WNenX1UabcU1z+zny8ujqYyo+M7QZUPqHfVfHpiX6HXARThf1hYbW/3UubkD9M4p856mkGi72XKnlHqJyy7PiiqoFKBccW8XHUMZCn3QILhiLSCm40xyTmYQksQxYQr68vZjOUEdiMPQyhyJfiJ3/poPXwDDVU0LlqUR3PP4aVO+Tw93qNJZkEbbIAgdlCSQCqniRHOmKeUt4rKksmlW/PV4bnY6u/eR8mK5rq9vyy1y4yjQSPaHhAXYhPQ0QlgRA00U4fhSEevX2sCZNuBR+sWGmw8VJylxjyhB4R0VPErZFW4q0L9l7b0QDQwVHoSryshywrb6ALp0zLH8pSVohO4kkNyzTqO6lT52xN1uSWOAlcD2sKcQ6+5PCVrxZ5+oGZlhcHkbQrx5UgnXe4h7OGIOQL1VV8G4AxBtWJkYDtCrRtFIJO/f54e+74Ee+pWtKUS7e6KrDlMkuMj1GHbthFnBFnzP3Vl0ojcywdUsfiFOMI5ihvxBIBMXvOKueHFZSeQlbL6lEfKOrnrItEhgcwQYYdsapsBXgJ7Wm+pNhGzUKnv0KTK96j0wdvC4w/fqnrZHn4j/c1aT/9Do/+v43Cm0vdAfyNKFvOm5byRJZxs+dKECHYDb2JaRanAEAN13uFEIXGtwcqF8cCLowo8+6sYZbtHlLeAKdgtAuxp5A5aBnfMwHpcXgTFBd3w8qgmJiHbnwggp+MlQ40JonlcKrCfbb1yLupXx3P7Be6aJ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tAMn4NdoXocjQkAFMdxMGk/vjsejBoRwmB/T5FFZuyCBu1hu77pTkl8u4FT4dtBAtEdI46Ec/oSafg5OCtDKCkyVsOe6sD7YmpB04fmBfjftYqPw0Nj1B2F9GMfjeKuqjn9Tg0OFYq3mSlKNd3c+qsPFEXQpPHWXZqY8HER6+vhLC48UzfdCJCgR4cACQoSYYuzbvJmJgGV2zFmsRBbUKpQJpz1/OwpOoS0YcLhk/EMqvNA7VQV40PYroruwe5WRGK3AW4V58ZkbNZekgXwQ2oLtmsybUOI445SpSH2KucZ25NlFi0eNr8hEVPlErCSQS75WiQ8N38cvBj9dk91MNh0D1LGPG/7nuywqHr2+AUC8motiY181sVkwJwaSrnf4WK7UvZl8Y9bGugKgYEw6xGGfvwU8mIWr634t1ddaVJMuFBFmj5SQVBBKAtyo3k=--ueMcJPtiNoZxMJGd--xKkKsq5nYP5KVgDP8Yvtpw== |
40 changes: 40 additions & 0 deletions
40
backend/db/migrate/20240515144839_remove_cnous_roles_to_sub_instructor_api_particulier.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
class RemoveCnousRolesToSubInstructorApiParticulier < ActiveRecord::Migration[7.0] | ||
def up | ||
return unless subinstructor_exists? | ||
|
||
remove_roles( | ||
[subinstructor_email], | ||
["api_particulier:cnous:subscriber", "api_particulier:cnous:reporter"] | ||
) | ||
end | ||
|
||
def down | ||
add_roles( | ||
[subinstructor_email], | ||
["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 | ||
|
||
def subinstructor_email = Rails.application.credentials.enseignementsup_subinstructor.email | ||
|
||
def subinstructor_exists? = Rails.application.credentials.enseignementsup_subinstructor.present? | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters