-
-
Notifications
You must be signed in to change notification settings - Fork 404
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: migration script to batch import existing orgs in CRM (#10683)
<!-- IMPORTANT CHECKLIST Make sure you've done all the following (You can delete the checklist before submitting) - [ ] PR title is prefixed by one of the following: feat, fix, docs, style, refactor, test, build, ci, chore, revert, l10n, taxonomy - [ ] Code is well documented - [ ] Include unit tests for new functionality - [ ] Code passes GitHub workflow checks in your branch - [ ] If you have multiple commits please combine them into one commit by squashing them. - [ ] Read and understood the [contribution guidelines](https://github.com/openfoodfacts/openfoodfacts-server/blob/main/CONTRIBUTING.md) --> ### What Existing orgs have been manually reviewed by @manon-corneille, using a dump generated by this script #10507. This PR provides a migration script (`scripts/migration/2024_08_validate_and_sync_crm_existing_orgs.pl`) to accept the selected orgs. The others are rejected and receive a rejection email notification. - added sync of org's country - few fixes in CRM.pm - [x] Awaiting email's wording. ### Screenshot <!-- Optional, you can delete if not relevant --> ### Related issue(s) and discussion - Fixes #7355 - Fixes #7359
- Loading branch information
Showing
8 changed files
with
204 additions
and
26 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
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
94 changes: 94 additions & 0 deletions
94
scripts/migrations/2024_08_validate_and_sync_crm_existing_orgs.pl
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,94 @@ | ||
#!/usr/bin/perl -w | ||
|
||
# This file is part of Product Opener. | ||
# | ||
# Product Opener | ||
# Copyright (C) 2011-2023 Association Open Food Facts | ||
# Contact: contact@openfoodfacts.org | ||
# Address: 21 rue des Iles, 94100 Saint-Maur des Fossés, France | ||
# | ||
# Product Opener is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU Affero General Public License as | ||
# published by the Free Software Foundation, either version 3 of the | ||
# License, or (at your option) any later version. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU Affero General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU Affero General Public License | ||
# along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
|
||
use ProductOpener::PerlStandards; | ||
use Modern::Perl '2017'; | ||
use utf8; | ||
|
||
use ProductOpener::Config qw( $data_root ); | ||
use ProductOpener::Paths qw( %BASE_DIRS ); | ||
use ProductOpener::Users qw( $User_id retrieve_user ); | ||
use ProductOpener::Orgs qw( list_org_ids retrieve_org store_org send_rejection_email); | ||
use Encode; | ||
|
||
binmode(STDOUT, ":encoding(UTF-8)"); | ||
binmode(STDERR, ":encoding(UTF-8)"); | ||
|
||
# This file is used to: | ||
# Set the validation status of existing orgs to 'accepted' for the ones in the list, and sync with the CRM. | ||
# Reject all the others and send a rejection email notification to them. | ||
# Set the org name if it is missing. | ||
|
||
# Set Manon as the salesperson for the orgs | ||
$User_id = 'manoncorneille'; | ||
|
||
# read the list of orgs to sync, one per line | ||
my %orgs_to_accept = map {chomp; $_ => 1} <>; | ||
|
||
# load checkpoint | ||
my $checkpoint_file = "$BASE_DIRS{CACHE_TMP}/orgs_synced.checkpoint"; | ||
my $checkpoint; | ||
if (!-e $checkpoint_file) { | ||
`touch $checkpoint_file`; | ||
} | ||
open($checkpoint, '+<:encoding(UTF-8)', $checkpoint_file) or die "Could not open file: $!"; | ||
foreach my $org_id (<$checkpoint>) { | ||
chomp $org_id; | ||
delete $orgs_to_accept{$org_id}; | ||
} | ||
|
||
# if all orgs have been synced, exit | ||
if (scalar keys %orgs_to_accept == 0) { | ||
print "All orgs have been synced\n"; | ||
close $checkpoint; | ||
exit; | ||
} | ||
|
||
foreach my $org_id (list_org_ids()) { | ||
$org_id = decode utf8 => $org_id; | ||
my $org_ref = retrieve_org($org_id); | ||
|
||
my $org_name = $org_ref->{name}; | ||
if (not defined $org_name) { | ||
$org_ref->{name} = $org_id =~ s/-/ /gr; | ||
} | ||
|
||
if (not exists $org_ref->{country} and exists $org_ref->{main_contact}) { | ||
my $user_ref = retrieve_user($org_ref->{main_contact}); | ||
$org_ref->{country} = $user_ref->{country} if $user_ref; | ||
} | ||
|
||
my $org_is_valid = exists $orgs_to_accept{$org_id}; | ||
if ($org_is_valid) { | ||
$org_ref->{valid_org} = 'accepted'; | ||
} | ||
else { | ||
$org_ref->{valid_org} = 'rejected'; | ||
send_rejection_email($org_ref); | ||
} | ||
|
||
store_org($org_ref); | ||
if ($org_is_valid) { | ||
print "$org_id\n"; | ||
print $checkpoint "$org_id\n"; | ||
} | ||
} |
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
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,13 @@ | ||
Subject: Account deactivation notification | ||
|
||
<!-- start templates/[% template.name %] --> | ||
|
||
Hello,<br><br> | ||
As part of our ongoing efforts to improve and maintain the quality of our platform, we recently conducted a review of all Open Food Facts Pro accounts. During this review, we identified certain accounts that either had not yet imported any product data or appeared to be registered with personal email addresses rather than professional ones.<br><br> | ||
Based on these criteria, <b>we have made the decision to deactivate your account</b>. However, if you believe this action was taken in error or if you are still interested in using the platform, we are more than happy to assist you in getting started with the Open Food Facts Pro platform.<br><br> | ||
If you would like to reactivate your account, please respond to this email, and we will guide you through the next steps. We want to ensure that everyone who wishes to contribute to our collaborative database has the opportunity to do so.<br><br> | ||
Thank you for your understanding, and we apologize for any inconvenience this may have caused.<br><br> | ||
Best,<br><br> | ||
The Open Food Facts team<br><br> | ||
|
||
<!-- end templates/[% template.name %] --> |
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,12 @@ | ||
Subject: Désactivation de votre compte | ||
|
||
<!-- start templates/[% template.name %] --> | ||
|
||
Bonjour,<br><br> | ||
Dans le cadre de nos efforts continus pour améliorer la plateforme Pro, nous avons récemment passé en revue tous les comptes Open Food Facts Pro. Plusieurs comptes n'ont encore jamais importé de données produits ou semblent être enregistrés avec des adresses mail personnelles plutôt que professionnelles.<br><br> | ||
Sur la base de ces critères, nous avons pris la décision de désactiver votre compte. Toutefois, si vous pensez que cette mesure a été prise par erreur ou si vous êtes toujours intéressés par l'utilisation de la plateforme, nous serions ravis de vous aider à ajouter vos produits sur la plateforme Pro d'Open Food Facts.<br><br> | ||
Si vous souhaitez réactiver votre compte, merci de répondre à cet e-mail.<br><br> | ||
Nous vous remercions de votre compréhension,<br><br> | ||
L’équipe d’Open Food Facts<br><br> | ||
|
||
<!-- end templates/[% template.name %] --> |
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
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