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

Use the Notification model when viewing a single notification #5318

Open
wants to merge 14 commits into
base: main
Choose a base branch
from

Conversation

quis
Copy link
Member

@quis quis commented Dec 5, 2024

This continues the work done in #5232

Notifications are one of the last database objects in the admin app that we are still passing around as raw JSON, rather than wrapping them in a proper Python object.

@quis quis changed the title Using the Notification model when viewing a single notification Use the Notification model when viewing a single notification Dec 5, 2024
@quis quis force-pushed the refactor-single-notification-into-model branch from b7ae5de to 2d0f5bb Compare December 5, 2024 16:31
quis added 14 commits December 11, 2024 16:48
This continues the work done in
https://github.com/alphagov/notifications-admin/pull/5232/files

Notifications are one of the last database objects in the admin app that
we are still passing around as raw JSON, rather than wrapping them in a
proper Python object.
Generally it’s a clearer separation of concerns if the view doesn’t talk
to the raw API client method, but instead uses a method or property on
the model.

This also reduces the number of branches directly in the view method.
By moving this into the model we move a bunch of branching logic out of
the view layer and make it easier to potentially reuse.
By moving this into the model we move a bunch of branching logic out of
the view layer and make it easier to potentially reuse.
By moving this into the model we move a bunch of branching logic out of
the view layer and make it easier to potentially reuse.

Displayed postage is what we use to decide what to show in the corner of
the envelope.

If the letter can’t be posted (because validation failed) we don’t want
to show any postage, becuase the letter will not be sent.

Other parts of the code still need access to `.postage` to calculate
delivery times etc.
By moving this into the model we can avoid defining another temporary
variable that is just used to move data from the model to the template.
This is just bit nicer to read than digging into the JSON of a template.
A lot of the code in the view layer is now just passing data from the
model to the template.

If we give the template direct access to the model then we can:
- remove some lines of code
- remove a layer of indirection that needs following when reading the
  code
This variable was just passing data from the model to the template.

The template has direct access to the model now so we can:
- make the template refer to this data directly
- encapsulate it into a method because it’s used more than once
Yet another bit of branching we can move out of the view layer
This function is now straightforward enough that it passes the
complexity check.
The template always has access to `current_service` so there’s no need
to pass it through from the view layer.
This wasn’t used anywhere in the template.

In fact it was never used even when it was added 7 years ago:
c5f92ea#diff-a44631c6318085fe6e2da66059480f9d62cd1d0aa75f41c8802f2fdb95b2c9c5R50
The code that uses this object gets the reply to text from the
notification itself, not the template.

So I don’t think this overriding is used.
@quis quis force-pushed the refactor-single-notification-into-model branch from 2d0f5bb to 7ed9b48 Compare December 11, 2024 16:51
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.

1 participant