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

Update Template and TemplateCategory models #2212

Merged
merged 5 commits into from
Jul 9, 2024

Conversation

whabanks
Copy link
Contributor

@whabanks whabanks commented Jul 9, 2024

Summary | Résumé

  • Template.category is now Template.template_category
  • In Template and TemplateHistory, the template_category attribute now leverage a primary join to:
    1. Allow the full TemplateCategory model to be loaded when fetching Template or TemplateHistory
    2. Prevent a full list of associated templates from being populated on a TemplateCategory model
  • Updated the Template and TemplateHistory schemas to include the TemplateCategory when returning data to API callers

Related Issues | Cartes liées

Test instructions | Instructions pour tester la modification

TODO: Fill in test instructions for the reviewer.

Release Instructions | Instructions pour le déploiement

None.

Reviewer checklist | Liste de vérification du réviseur

  • This PR does not break existing functionality.
  • This PR does not violate GCNotify's privacy policies.
  • This PR does not raise new security concerns. Refer to our GC Notify Risk Register document on our Google drive.
  • This PR does not significantly alter performance.
  • Additional required documentation resulting of these changes is covered (such as the README, setup instructions, a related ADR or the technical documentation).

⚠ If boxes cannot be checked off before merging the PR, they should be moved to the "Release Instructions" section with appropriate steps required to verify before release. For example, changes to celery code may require tests on staging to verify that performance has not been affected.

whabanks added 2 commits July 9, 2024 14:57
- Template.category is now Template.template_category
- In Template and TemplateHistory, template_category now leverage a primary join to both allow the full TemplateCategory model to be loaded when fetching either, and to prevent a list of associated templates from being populated on a TemplateCategory model
- Updated the Template and TemplateHistory schemas to include the TemplateCategory when returning data to API callers

db.session.delete(template_category)
db.session.commit()
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why did you move the commit?

Copy link
Contributor Author

@whabanks whabanks Jul 9, 2024

Choose a reason for hiding this comment

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

I removed it because with @transactional we auto commit after the method executes. Buuuut in testing I had removed @transactional. I'll add it back in - nice catch

def category(cls):
return db.relationship("TemplateCategory")
def template_category(cls):
return db.relationship("TemplateCategory", primaryjoin="Template.template_category_id == TemplateCategory.id")
Copy link
Collaborator

Choose a reason for hiding this comment

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

nice

@@ -396,6 +396,7 @@ class TemplateSchema(BaseTemplateSchema):
created_by = field_for(models.Template, "created_by", required=True)
is_precompiled_letter = fields.Method("get_is_precompiled_letter")
process_type = field_for(models.Template, "process_type")
template_category = fields.Nested(TemplateCategorySchema, dump_only=True)
Copy link
Collaborator

Choose a reason for hiding this comment

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

ah I missed adding the sms_sending_vehicle can we add it in this PR

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's a simple type and the TemplateCategorySchema references our model. Since you updated it there it picks it up okay in the front end. Here's what it looks like locally in Redis:

{
  "id": "d59f9609-b965-4836-bb51-904ee9f3c2b7",
  "name_en": "hmm",
  "name_fr": "hmm",
  "description_en": "hmm",
  "description_fr": "hmm",
  "sms_process_type": "normal",
  "email_process_type": "priority",
  "hidden": false,
  "created_at": "2024-07-08T19:05:13.129712",
  "updated_at": null,
  "sms_sending_vehicle": "long_code"
}

template_categories:

{
    "id": "b6c42a7e-2a26-4a07-802b-123a5c3198a9",
    "name_en": "Authentication",
    "name_fr": "Authentification",
    "description_en": "Password resets and two factor verification",
    "description_fr": "R\u00e9initialisations de mots de passe et v\u00e9rification \u00e0 deux facteurs",
    "sms_process_type": "priority",
    "email_process_type": "priority",
    "hidden": false,
    "created_at": "2024-07-08T17:03:08.501236",
    "updated_at": "2024-07-08T17:03:08.501236",
    "sms_sending_vehicle": "short_code"
  },
  {
    "id": "977e2a00-f957-4ff0-92f2-ca3286b24786",
    "name_en": "Automatic reply",
    "name_fr": "R\u00e9ponse automatique",
    "description_en": "No-reply and confirmation messages",
    "description_fr": "Messages auxquels il est impossible de r\u00e9pondre et messages de confirmation",
    "sms_process_type": "priority",
    "email_process_type": "priority",
    "hidden": false,
    "created_at": "2024-07-08T17:03:08.501236",
    "updated_at": "2024-07-08T17:03:08.501236",
    "sms_sending_vehicle": "short_code"
  },
....

Copy link
Collaborator

Choose a reason for hiding this comment

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

thanks!

whabanks and others added 2 commits July 9, 2024 15:43
- Restored @transactional decorator
- Simplified setting the default template categories during a delete
@whabanks whabanks merged commit 4ef95ad into main Jul 9, 2024
4 checks passed
@whabanks whabanks deleted the fix/template-category-model branch July 9, 2024 20:01
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