Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add script to automatically disable accounts that are no longer valid #1042

Draft
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

loicguillois
Copy link
Collaborator

@loicguillois loicguillois commented Dec 11, 2024

Pour obtenir la liste des comptes supprimés / désactivés à l'aide de duckDB, voici la procédure:

Avant exécution:

CREATE TABLE users_duckdb AS
  SELECT *
  FROM postgres_scan(
      'postgresql://postgres:postgres@localhost:5432/test_cerema',
      'public',
      'users'
  );

Après exécution:

CREATE TABLE users_duckdb_after AS
  SELECT *
  FROM postgres_scan(
      'postgresql://postgres:postgres@localhost:5432/test_cerema',
      'public',
      'users'
  );

Puis:

COPY (
      SELECT
          a.id,
          a.email, 
          a.disabled AS old_disabled, 
          b.disabled AS new_disabled,
          b.deleted_at
      FROM 
          users_duckdb a
      INNER JOIN 
          users_duckdb_after b 
          ON a.id = b.id
      WHERE 
          (a.disabled IS DISTINCT FROM b.disabled) 
          OR 
          (b.deleted_at IS NOT NULL)
  ) TO 'fichier_modifications.csv' WITH (
      FORMAT csv,
      HEADER true,
      DELIMITER ',',
      ENCODING 'UTF8'
  );

Pour enrichir après coup le CSV des informations concernant l'établissement:

CREATE TABLE compte_supprime_desactive AS
SELECT *
FROM read_csv_auto('fichier_modifications.csv', 
                   header=True,
                   sep=',');

Puis:

CREATE TABLE establishments_duckdb AS
    SELECT *
    FROM postgres_scan(
        'postgresql://postgres:postgres@localhost:5432/test_cerema',
        'public',
        'establishments'
    );

Et enfin:

COPY (
    SELECT
        c.id,
        c.email,
        e.name,
        e.siren,
        c.old_disabled,
        c.new_disabled,
        c.deleted_at
    FROM compte_supprime_desactive AS c
    JOIN users_duckdb AS u
      ON c.email = u.email
    JOIN establishments_duckdb AS e
      ON u.establishment_id = e.id
)
TO 'fichier_modifications_enrichi.csv'
(
    FORMAT 'csv',
    HEADER TRUE,
    DELIMITER ',',
    ENCODING 'UTF8'
);

@loicguillois loicguillois requested a review from Falinor December 11, 2024 14:34
@loicguillois loicguillois force-pushed the disable-invalid-account branch from ddf24e6 to 621c72b Compare December 11, 2024 14:34
@loicguillois loicguillois marked this pull request as draft December 11, 2024 14:34
Copy link

@loicguillois loicguillois force-pushed the disable-invalid-account branch from 621c72b to c074416 Compare December 17, 2024 16:05
@loicguillois loicguillois marked this pull request as ready for review December 31, 2024 13:42
@loicguillois loicguillois force-pushed the disable-invalid-account branch from bd518ae to 80fc8e5 Compare December 31, 2024 13:50
@@ -39,9 +38,6 @@ async function create(request: Request, response: Response) {
await mailService.sendAccountActivationEmail(link.id, {
recipients: [email]
});
mailService.emit('prospect:initialized', email, {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Vérifier dans Brevo comment s'était utilisé et le cas échéant supprimer.


response.status(constants.HTTP_STATUS_CREATED).json(createdUser);
mailService.emit('user:created', prospect.email, {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Vérifier dans Brevo comment s'était utilisé et le cas échéant supprimer.

@@ -25,7 +25,7 @@ async function used(id: string): Promise<void> {
async function getByEmail(email: string): Promise<SignupLinkApi | null> {
logger.debug('Get signupLinkApi by prospect_email', email);

const link = await SignupLinks().select().where('prospect_email', email).first();
const link = await SignupLinks().select().where('prospect_email', email).orderBy('expires_at', 'desc').first();
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prévoir un script de nettoyage de cette table

}
}

await delay(100);
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

permet d'éviter un blocage par portailDF

frontend/src/services/portaildf.service.ts Outdated Show resolved Hide resolved
@loicguillois loicguillois force-pushed the disable-invalid-account branch from 2cbba6e to 90a8f09 Compare January 7, 2025 15:11
@loicguillois loicguillois marked this pull request as draft January 9, 2025 14:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants