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

adds ability to self publish workbaskets via the django admin workbasket view #1292

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

TomMacca
Copy link
Contributor

@TomMacca TomMacca commented Sep 13, 2024

TP2000-1494

Adds ability to self publish workbaskets via the django admin workbasket view

Why

We need a method to self publish workbaskets (i.e. publish workbaskets only for TAP and not any downstream consumers like HMRC or the Channel Islands) via the UI. Currently it can only be done through scripts.

What

This PR adds a button to Django admin workbasket view to enable self publishing. It will only show to super users and it will only be clickable if the workbasket in question is in EDITING state and with all transactions having passed rules checks.

image image image image

@TomMacca TomMacca self-assigned this Sep 13, 2024
@TomMacca TomMacca requested a review from a team as a code owner September 13, 2024 18:48
@codecov-commenter
Copy link

Codecov Report

Attention: Patch coverage is 6.25000% with 15 lines in your changes missing coverage. Please review.

Project coverage is 93.08%. Comparing base (76b3df5) to head (6e19ef6).
Report is 24 commits behind head on master.

Files with missing lines Patch % Lines
workbaskets/admin.py 6.25% 14 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1292      +/-   ##
==========================================
- Coverage   93.11%   93.08%   -0.04%     
==========================================
  Files         620      642      +22     
  Lines       47329    48324     +995     
  Branches     3343     5201    +1858     
==========================================
+ Hits        44070    44980     +910     
- Misses       2619     2688      +69     
- Partials      640      656      +16     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Comment on lines +121 to +141
if "_self-publish" in request.POST:
# check if user is super user
if not request.user.is_superuser:
self.message_user(request, "You do not have permission to perform this action.", level=messages.ERROR)
return HttpResponseRedirect(request.get_full_path())

# check if workbasket status is 'editing'
if obj.status != 'EDITING':
messages.error(request, "The workbasket is not in EDITING status.")
return HttpResponseRedirect(request.get_full_path())

# check if rule checks have passed
if obj.unchecked_or_errored_transactions.exists():
messages.error(request, "Rule checks have not passed on the current contents of this workbasket.")
return HttpResponseRedirect(request.get_full_path())

obj.full_clean()
obj.approve(user=request.user.id, scheme_name=settings.TRANSACTION_SCHEMA)
obj.status = "PUBLISHED"
obj.save()
return HttpResponseRedirect(request.get_full_path())
Copy link
Collaborator

Choose a reason for hiding this comment

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

This has the potential to make important and far reaching changes to published data. I think it probably needs accompanying unit tests.

Copy link
Collaborator

Choose a reason for hiding this comment

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

This workbasket transition to PUBLISHED is probably better placed on the WorkBasket model to make it less of a back channel approach to workbasket state management and publishing. Probably a new transition (using the django_fsm.transition decorator), that more or less combines queue and cds_confirmed.

Copy link
Collaborator

@paulpepper-trade paulpepper-trade Sep 16, 2024

Choose a reason for hiding this comment

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

It also sounds as though these changes are to support a very specific quotas workflow. To reduce the chances of incorrectly publishing data, validation should ensure only specific data types are present in the workbasket. Were validation to fail, then that'd involve disabling the capability in the UI and preventing the publish transition when implemented on the workbasket.

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.

4 participants