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

(unsigned) feat: delete overdue draft form responses and dont nag #444

Closed
wants to merge 9 commits into from

Conversation

daine
Copy link
Contributor

@daine daine commented Jul 21, 2023

Summary | Résumé

Fix for cds-snc/platform-forms-client#2338

Updates the nagware to check if the detected overdue responses are for an unpublished form, and deletes them accordingly.

Test instructions | Instructions pour tester la modification

  1. Create overdue test responses on an unpublished form. On localhost, update
// vaultProcessing.js line 21
  try {
    fileInputPaths = extractFileInputResponses(formSubmission);

    const fiftyDaysAgo = "4320000000"; // Create overdue responses
    const createdAt = Date.now() - fiftyDaysAgo; // Create overdue responses

    await copyFilesFromReliabilityToVaultStorage(fileInputPaths);
    await saveToVault(
      submissionID,
      formSubmission.responses,
      formID,
      language,
      createdAt,
      securityAttribute
    );
  } catch (error) {
  1. Run ./invoke_nagware.js
  2. All test responses, overdue or not, should have been deleted

Tested with:

  • Overdue draft form responses (deletes form responses, skips nag)
  • Overdue published form responses (does not delete, nags instead)

@daine daine marked this pull request as ready for review July 21, 2023 20:05
@daine daine enabled auto-merge (squash) July 21, 2023 20:08
@craigzour
Copy link
Contributor

@daine Now that you have implemented a mechanism to delete responses before publishing forms I am not quite sure why we have to handle any deletion on the Nagware infra side.
I thought the work was just about skipping form owners nagging if there was overdue responses on a form that was still in draft mode.
To me it makes more sense to do it this way but maybe I am missing something?

cc @timarney @falila

@daine
Copy link
Contributor Author

daine commented Jul 24, 2023

@daine Now that you have implemented a mechanism to delete responses before publishing forms I am not quite sure why we have to handle any deletion on the Nagware infra side. I thought the work was just about skipping form owners nagging if there was overdue responses on a form that was still in draft mode. To me it makes more sense to do it this way but maybe I am missing something?

cc @timarney @falila

The use case here I believe is to handle people who never publish the form (as per Brian's design and response on this issue). It's the second scenario

@falila
Copy link
Contributor

falila commented Jul 24, 2023

@daine Now that you have implemented a mechanism to delete responses before publishing forms I am not quite sure why we have to handle any deletion on the Nagware infra side. I thought the work was just about skipping form owners nagging if there was overdue responses on a form that was still in draft mode. To me it makes more sense to do it this way but maybe I am missing something?
cc @timarney @falila

The use case here I believe is to handle people who never publish the form (as per Brian's design and response on this issue). It's the second scenario

The propose solution appears satisfactory concerning the deletion of test responses for drafted forms. It avoids introducing any unnecessary attributes and instead utilizes the existing template property, which is more appropriate.
Nice work!

aws/app/lambda/nagware/nagware.js Show resolved Hide resolved
aws/app/lambda/nagware/nagware.js Show resolved Hide resolved

if (!process.env.AWS_SAM_LOCAL) {
const jsonConfig = JSON.parse(firstRecord[2].stringValue.trim(1, -1)) || undefined;
formName = firstRecord[1].stringValue !== "" ? firstRecord[1].stringValue : `${jsonConfig.titleEn} - ${jsonConfig.titleFr}`;
// TODO: Not sure what field the isPublished value is in, but based on the SQL query, it should be in the 4th index
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@craigzour this is a guess for me right now, I could use your guidance since I'm unable to test it

Copy link
Contributor

Choose a reason for hiding this comment

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

firstRecord[3] sounds about right.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yep I agree. You can delete the comment ;)

Copy link
Contributor

@craigzour craigzour left a comment

Choose a reason for hiding this comment

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

We are almost good to go :)

aws/app/lambda/nagware/nagware.js Outdated Show resolved Hide resolved

if (!process.env.AWS_SAM_LOCAL) {
const jsonConfig = JSON.parse(firstRecord[2].stringValue.trim(1, -1)) || undefined;
formName = firstRecord[1].stringValue !== "" ? firstRecord[1].stringValue : `${jsonConfig.titleEn} - ${jsonConfig.titleFr}`;
// TODO: Not sure what field the isPublished value is in, but based on the SQL query, it should be in the 4th index
Copy link
Contributor

Choose a reason for hiding this comment

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

Yep I agree. You can delete the comment ;)

Copy link
Contributor

@craigzour craigzour left a comment

Choose a reason for hiding this comment

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

LGTM :) Thank you!

Copy link
Contributor

@falila falila left a comment

Choose a reason for hiding this comment

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

🌮

@daine daine force-pushed the feat/delete-overdue-draft-form-responses branch from be381d1 to d1704c7 Compare July 24, 2023 22:48
@github-actions
Copy link

⚠ Terrform update available

Terraform: 1.5.3 (using 1.4.2)
Terragrunt: 0.48.4 (using 0.46.3)

@github-actions
Copy link

Staging: app

✅   Terraform Init: success
✅   Terraform Validate: success
✅   Terraform Format: success
✅   Terraform Plan: success
✅   Conftest: success

⚠️   Warning: resources will be destroyed by this change!

Plan: 2 to add, 1 to change, 2 to destroy
Show summary
CHANGE NAME
update aws_lambda_function.nagware
recreate aws_lambda_layer_version.nagware_lib
aws_lambda_layer_version.nagware_nodejs
Show plan
Resource actions are indicated with the following symbols:
  ~ update in-place
-/+ destroy and then create replacement

Terraform will perform the following actions:

  # aws_lambda_function.nagware will be updated in-place
  ~ resource "aws_lambda_function" "nagware" {
        id                             = "Nagware"
      ~ last_modified                  = "2023-07-21T12:42:28.000+0000" -> (known after apply)
      ~ layers                         = [
          - "arn:aws:lambda:ca-central-1:687401027353:layer:nagware_lib_packages:8",
          - "arn:aws:lambda:ca-central-1:687401027353:layer:nagware_node_packages:15",
        ] -> (known after apply)
      ~ source_code_hash               = "y34UuQHJpw45wPAaGnYetfK3Np4OClJnnkY9F5bpN7I=" -> "iEcgvvidpFH4l1y2zkp2weM9newMLuhW5SACT1opKjk="
        tags                           = {
            "CostCentre" = "forms-platform-staging"
            "Terraform"  = "true"
        }
        # (17 unchanged attributes hidden)

        # (2 unchanged blocks hidden)
    }

  # aws_lambda_layer_version.nagware_lib must be replaced
-/+ resource "aws_lambda_layer_version" "nagware_lib" {
      ~ arn                         = "arn:aws:lambda:ca-central-1:687401027353:layer:nagware_lib_packages:8" -> (known after apply)
      - compatible_architectures    = [] -> null
      ~ created_date                = "2023-07-21T12:42:08.652+0000" -> (known after apply)
      ~ id                          = "arn:aws:lambda:ca-central-1:687401027353:layer:nagware_lib_packages:8" -> (known after apply)
      ~ layer_arn                   = "arn:aws:lambda:ca-central-1:687401027353:layer:nagware_lib_packages" -> (known after apply)
      + signing_job_arn             = (known after apply)
      + signing_profile_version_arn = (known after apply)
      ~ source_code_hash            = "Yt+PCj+su2PKY5jmYB/8Klpw1hhZMhvzkQjhfplPFSk=" -> "aMoOyf/2lLfJkqzVR1L+oPscSFKywcFmQTPl1evU0IY=" # forces replacement
      ~ source_code_size            = 3814 -> (known after apply)
      ~ version                     = "8" -> (known after apply)
        # (4 unchanged attributes hidden)
    }

  # aws_lambda_layer_version.nagware_nodejs must be replaced
-/+ resource "aws_lambda_layer_version" "nagware_nodejs" {
      ~ arn                         = "arn:aws:lambda:ca-central-1:687401027353:layer:nagware_node_packages:15" -> (known after apply)
      - compatible_architectures    = [] -> null
      ~ created_date                = "2023-07-21T12:42:15.055+0000" -> (known after apply)
      ~ id                          = "arn:aws:lambda:ca-central-1:687401027353:layer:nagware_node_packages:15" -> (known after apply)
      ~ layer_arn                   = "arn:aws:lambda:ca-central-1:687401027353:layer:nagware_node_packages" -> (known after apply)
      + signing_job_arn             = (known after apply)
      + signing_profile_version_arn = (known after apply)
      ~ source_code_hash            = "gqUAucq28GdqL2sbVq4aA+ZEnm+/oXU6jRvkkBKRx4o=" -> "Ggli/WoTw6SVanhWXvhR4WQDQ7Mv+fS3slM292yTyXo=" # forces replacement
      ~ source_code_size            = 3676202 -> (known after apply)
      ~ version                     = "15" -> (known after apply)
        # (4 unchanged attributes hidden)
    }

Plan: 2 to add, 1 to change, 2 to destroy.

Warning: Argument is deprecated

  with aws_s3_bucket.reliability_file_storage,
  on s3.tf line 4, in resource "aws_s3_bucket" "reliability_file_storage":
   4: resource "aws_s3_bucket" "reliability_file_storage" {

Use the aws_s3_bucket_lifecycle_configuration resource instead

(and 17 more similar warnings elsewhere)

─────────────────────────────────────────────────────────────────────────────

Saved the plan to: plan.tfplan

To perform exactly these actions, run the following command to apply:
    terraform apply "plan.tfplan"
Releasing state lock. This may take a few moments...
Show Conftest results
WARN - plan.json - main - Missing Common Tags: ["aws_cloudwatch_event_rule.cron_2am_every_day"]
WARN - plan.json - main - Missing Common Tags: ["aws_cloudwatch_event_rule.cron_3am_every_day"]
WARN - plan.json - main - Missing Common Tags: ["aws_cloudwatch_event_rule.cron_4am_every_day"]
WARN - plan.json - main - Missing Common Tags: ["aws_cloudwatch_event_rule.cron_5am_every_business_day"]
WARN - plan.json - main - Missing Common Tags: ["aws_cloudwatch_log_group.archive_form_templates"]
WARN - plan.json - main - Missing Common Tags: ["aws_cloudwatch_log_group.archiver"]
WARN - plan.json - main - Missing Common Tags: ["aws_cloudwatch_log_group.audit_logs"]
WARN - plan.json - main - Missing Common Tags: ["aws_cloudwatch_log_group.dead_letter_queue_consumer"]
WARN - plan.json - main - Missing Common Tags: ["aws_cloudwatch_log_group.nagware"]
WARN - plan.json - main - Missing Common Tags: ["aws_cloudwatch_log_group.reliability"]
WARN - plan.json - main - Missing Common Tags: ["aws_cloudwatch_log_group.submission"]

28 tests, 17 passed, 11 warnings, 0 failures, 0 exceptions

@daine daine changed the title feat: delete overdue draft form responses and dont nag (unsigned) feat: delete overdue draft form responses and dont nag Jul 26, 2023
@daine
Copy link
Contributor Author

daine commented Jul 26, 2023

Note: I opened a new PR (#448) instead with signed commits. I signed the commits by doing a rebase since I added my new GPG key after already doing the commit
git rebase --exec 'git commit --amend --no-edit -n -S' -i develop

@daine daine closed this Jul 26, 2023
auto-merge was automatically disabled July 26, 2023 17:02

Pull request was closed

@daine daine mentioned this pull request Jul 26, 2023
@daine daine deleted the feat/delete-overdue-draft-form-responses branch July 26, 2023 17:13
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.

3 participants