-
Notifications
You must be signed in to change notification settings - Fork 803
Implement all_objects manager class in FacilityUser #13433
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
Implement all_objects manager class in FacilityUser #13433
Conversation
Build Artifacts
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good so far although it may require some coordination with Alex's .objects PR.
password=make_password("password"), | ||
facility=self.facility, | ||
) | ||
deleted_user.delete() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.delete here will actually remove the user from the db rather than "soft-deleting" them. If you want to soft-delete the user you'll need to set its date_deleted field to a date.
) | ||
deleted_user.delete() | ||
|
||
self.assertEqual(FacilityUser.objects.count(), 1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line won't work until Alex's PR changing the .objects queryset is merged.
e9d5f4f
to
b553c3b
Compare
b553c3b
to
4c08b3e
Compare
Would need QA on this @pcenov @radinamatic specifically on bulkUserImport features and the feature that import from csv undeletes soft deleted_user. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The changes in the models file look good, I just had a few thoughts on the updated tests.
self.facility = Facility.objects.create(name="My Facility") | ||
|
||
def test_all_objects_manager_returns_all_users(self): | ||
deleted_user = FacilityUser.objects.create( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just noting that you can set the date_deleted
field when the user is initially created as well. Then you wouldn't have to set it below and save the change separately.
def test_all_objects_manager_returns_all_users(self): | ||
deleted_user = FacilityUser.objects.create( | ||
username="deleted_user", | ||
password=make_password("password"), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a particular reason to use Django's make_password
for password hashing here? Mostly wondering because the other passwords in this file are just set as "password".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ahh seems like this was a co-pilot tab complete that I overlooked.
@@ -662,6 +663,28 @@ def test_default_facility_returns_none_when_no_settings(self): | |||
|
|||
|
|||
class FacilityUserTestCase(TestCase): | |||
def setUp(self): | |||
self.facility = Facility.objects.create(name="My Facility") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it makes sense to create the facility in a setup function when that facility is expected to be reused, but in this case, it should be fine to follow the pattern of the other functions below and use the line self.facility = Facility.objects.create()
directly within test_all_objects_manager_returns_all_users()
Hi @ozer550 I am getting the following error when I try to start Kolibri after having replaced the db.sqlite3 file with the one provided in the PR:
Could you have a look and let me know how we can proceed? Thanks! |
@pcenov Could you try following these steps from our user docs, and see if with them you manage to fix the malformed DB? https://kolibri.readthedocs.io/en/latest/manage/get_support.html#malformed-database |
The steps in https://kolibri.readthedocs.io/en/latest/manage/get_support.html#malformed-database are not working for this case where we are intentionally replacing the DB with the one provided in the PR. |
|
Hi @pcenov and @radinamatic it seems like its a little more complicated then just sharing the database file to reciprocate the state of my kolibri. I synced up with @LianaHarris360 and specifically walked her thorough regression testing the restoration of soft deleted user. So I think if @pcenov can now regression test on other features related with bulk import, we would be quite sure that we have whats expected. |
To clarify more, the only way to currently soft delete the user is to log in thru shell and then run a query to soft delete the user. I thought that sharing the database file would actually replicate the soft deleted user for you and you would not need to run those queries, but seems like it doesn't work that way. If we would want to document exact steps on how I regression tested this, I could write some docs if that would be helpful. |
Thanks @ozer550 - no regressions observed while manually testing the bulk import. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be good to merge in now!
Summary
References
closes #13376
Reviewer guidance
Steps to Reciprocate:
db_with_deleted_users.zip
ozer_2420_users.csv