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

Facility deletion management command #7033

Merged
merged 5 commits into from
Jun 16, 2020

Conversation

bjester
Copy link
Member

@bjester bjester commented Jun 11, 2020

Summary

  • Adds a management command for facility deletion to remove a facility entirely from the device
  • Adds a facilitytask endpoint for initiating a facility deletion task
  • Explicitly added the on_delete=CASCADE to the models since it in future versions of Django, it requires an explicit action it instead of assuming cascade
  • Updated @action decorators with preferred alternative since it is deprecated

Reviewer guidance

A nice to have feature was to have the command report progress. Relying on CASCADE deletions works just fine for most of the models, but also doesn't give much insight into that progress, as far as I know. This currently goes through all the models, counts them, and then deletes them; through this procedure it can report progress since it's handling the models individually.

Some feedback on whether we care about any of that would be great. It was a nice to have that didn't seem too difficult, but could get stale in the future if adding more related models, although still completely deleting the facility because of the cascade.

References

Notion page


Contributor Checklist

PR process:

  • PR has the correct target branch and milestone
  • PR has 'needs review' or 'work-in-progress' label
  • If PR is ready for review, a reviewer has been added. (Don't use 'Assignees')
  • If this is an important user-facing change, PR or related issue has a 'changelog' label
  • If this includes an internal dependency change, a link to the diff is provided

Testing:

  • Contributor has fully tested the PR manually
  • If there are any front-end changes, before/after screenshots are included
  • Critical user journeys are covered by Gherkin stories
  • Critical and brittle code paths are covered by unit tests

Reviewer Checklist

  • Automated test coverage is satisfactory
  • PR is fully functional
  • PR has been tested for accessibility regressions
  • External dependency files were updated if necessary (yarn and pip)
  • Documentation is updated
  • Contributor is in AUTHORS.md

@bjester bjester added this to the 0.14.0 milestone Jun 11, 2020
@bjester bjester added the work-in-progress Not ready for review label Jun 11, 2020
@bjester bjester changed the title Facility deletion Facility deletion management command Jun 11, 2020
@bjester bjester marked this pull request as ready for review June 11, 2020 17:19
@bjester bjester added changelog Important user-facing changes python labels Jun 11, 2020
@codecov
Copy link

codecov bot commented Jun 11, 2020

Codecov Report

Merging #7033 into release-v0.14.x will decrease coverage by 0.27%.
The diff coverage is 25.22%.

Impacted Files Coverage Δ
...ibri/core/assets/src/api-resources/facilityTask.js 0.00% <0.00%> (ø)
...ri/core/auth/management/commands/deletefacility.py 0.00% <0.00%> (ø)
.../core/auth/management/commands/fullfacilitysync.py 0.00% <0.00%> (ø)
kolibri/core/auth/management/commands/sync.py 0.00% <0.00%> (ø)
kolibri/core/device/permissions.py 80.76% <66.66%> (-1.84%) ⬇️
kolibri/core/tasks/api.py 43.60% <86.95%> (+1.06%) ⬆️
kolibri/core/auth/constants/morango_sync.py 100.00% <100.00%> (ø)
...libri/core/auth/management/commands/deprovision.py 91.89% <100.00%> (-1.29%) ⬇️
kolibri/core/auth/management/utils.py 48.14% <100.00%> (+3.26%) ⬆️
kolibri/core/auth/models.py 91.46% <100.00%> (+0.01%) ⬆️
... and 6 more

@bjester bjester requested review from jonboiser, jamalex and rtibbles and removed request for jonboiser June 11, 2020 19:27
@bjester bjester added TODO: needs review Waiting for review and removed work-in-progress Not ready for review labels Jun 11, 2020
@jonboiser jonboiser removed the TODO: needs review Waiting for review label Jun 16, 2020
@jonboiser jonboiser merged commit 121c220 into learningequality:release-v0.14.x Jun 16, 2020
post_delete.receivers = self.receivers
self.receivers = None


def _interactive_client_facility_selection():
facilities = Facility.objects.all().order_by("name")
message = "Please choose a facility to sync:\n"
Copy link
Member

Choose a reason for hiding this comment

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

@bjester Is the use of sync here intentional? This command should delete the facility, so why sync...? 🤔

Copy link
Member Author

Choose a reason for hiding this comment

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

@radinamatic Oh good catch! I didn't notice it said "sync". I'll make that dynamic

Copy link
Member Author

Choose a reason for hiding this comment

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

Updated here a41de91

Copy link
Member

@jamalex jamalex left a comment

Choose a reason for hiding this comment

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

Sorry for not reviewing before -- looks great! Just added a couple comment typo notes and a random comment. Nothing needing action.



class Command(AsyncCommand):
help = "This command initiates the deletion process for a facility and all of it's related data."
Copy link
Member

Choose a reason for hiding this comment

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

*its

"ARE YOU SURE? If you do this, there is no way to recover the facility data on this device."
)

# everything should get cascade deleted from the facility, but we'll check anyway
Copy link
Member

Choose a reason for hiding this comment

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

Sounds good. The main thing that I could imagine might be less likely to cascade delete would be anonymous ContentSessionLogs, which don't FK onto a user. But they would still have an FK onto the FacilityDataset (as would all of these), so it should all get cascade deleted, yeah.

update_progress(increment=0, message="Counting database objects")
total_count = delete_group.count(update_progress)

# no the deleting step
Copy link
Member

Choose a reason for hiding this comment

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

*now?

@bjester bjester deleted the facility-deletion branch July 15, 2021 17:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
changelog Important user-facing changes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants