-
Notifications
You must be signed in to change notification settings - Fork 147
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
Delete participations of long inactive users #2329
base: main
Are you sure you want to change the base?
Conversation
…default of 18 months
…ing months to seconds
…or vote start/end date instead of flat value
…ed as "can_be_marked_inactive_by_manager"
…ed to add +1 to get above threshold
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.
Good work so far! Sorry, quite a few comments added up, this could be a bit overwhelming. We want to address everything so we don't get stuck in endless review loops. We're always happy to help out and answer any questions, so make sure to ask if anything is unclear.
Co-authored-by: Richard Ebeling <[email protected]>
Co-authored-by: Richard Ebeling <[email protected]>
Thanks for your time in reviewing this PR, especially for all the fixes and explanations. Much appreciated 👍. |
…r as participant and add beginning check for user.evaluations_participating_in.exists()
evaluation_count = user.evaluations_participating_in.count() | ||
if test_run: | ||
return [ | ||
_("{} will be removed from {} participation(s) due to inactivity.").format(user.full_name, evaluation_count) |
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.
_("{} will be removed from {} participation(s) due to inactivity.").format(user.full_name, evaluation_count) | |
ngettext( | |
"{} participation of {} would be removed due to inactivity.", | |
"{} participations of {} would be removed due to inactivity.", | |
evaluation_count, | |
).format(evaluation_count, user.full_name) |
_("{} will be removed from {} participation(s) due to inactivity.").format(user.full_name, evaluation_count) | ||
] | ||
user.evaluations_participating_in.clear() | ||
return [_("Removed {} from {} participation(s) due to inactivity.").format(user.full_name, evaluation_count)] |
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.
return [_("Removed {} from {} participation(s) due to inactivity.").format(user.full_name, evaluation_count)] | |
return [ | |
ngettext( | |
"{} participation of {} was removed due to inactivity.", | |
"{} participations of {} were removed due to inactivity.", | |
evaluation_count, | |
).format(evaluation_count, user.full_name) | |
] |
@Redflashx12 Do you want to keep working on this PR (this or next year), or should we take over? |
I'll be active in EvaP in January again, still busy with moving in rn.
Sorry 😐
…On Mon, 16 Dec 2024, 17:33 Niklas Mohrin, ***@***.***> wrote:
@Redflashx12 <https://github.com/Redflashx12> Do you want to keep working
on this PR (this or next year), or should we take over?
—
Reply to this email directly, view it on GitHub
<#2329 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AKLX2ZLRWBUPBCKUJTKOG6T2F36FLAVCNFSM6AAAAABRE6L5G2VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDKNBWGA4TSNBTGY>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
Great, good luck with that! No need to worry or hurry, we just want to track the status of the PR :) |
six_months_ago = datetime.today() - timedelta(days=6 * 30) | ||
cls.evaluation = baker.make( | ||
Evaluation, | ||
state=Evaluation.State.PUBLISHED, | ||
vote_start_datetime=six_months_ago - settings.PARTICIPATION_DELETION_AFTER_INACTIVE_TIME, | ||
vote_end_date=six_months_ago.date(), |
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 usage of PARTICIPATION_DELETION_AFTER_INACTIVE_TIME
is misleading here, we just need some earlier start date. I think we can just use hardcoded 180/200 for the test (or any other value that we consider memorable enough, I'd also be fine with vote_end_date
being 10 or 100 days ago)
six_months_ago = datetime.today() - timedelta(days=6 * 30) | |
cls.evaluation = baker.make( | |
Evaluation, | |
state=Evaluation.State.PUBLISHED, | |
vote_start_datetime=six_months_ago - settings.PARTICIPATION_DELETION_AFTER_INACTIVE_TIME, | |
vote_end_date=six_months_ago.date(), | |
cls.evaluation = baker.make( | |
Evaluation, | |
state=Evaluation.State.PUBLISHED, | |
vote_start_datetime=datetime.today() - timedelta(days=200), | |
vote_end_date=date.today() - timedelta(days=180), |
|
||
@patch("evap.evaluation.models.UserProfile.is_active", True) | ||
@patch("evap.evaluation.models.UserProfile.can_be_marked_inactive_by_manager", True) | ||
def test_do_not_remove_user_due_to_inactivity_with_recently_archived_evaluation(self): |
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 relies on the default setting value, but it would be nice if the test passed even if some developers locally changed the setting. Thus, we should also
def test_do_not_remove_user_due_to_inactivity_with_recently_archived_evaluation(self): | |
@override_settings(PARTICIPATION_DELETION_AFTER_INACTIVE_TIME=timedelta(360)) | |
def test_do_not_remove_user_due_to_inactivity_with_recently_archived_evaluation(self): |
|
||
@patch("evap.evaluation.models.UserProfile.is_active", True) | ||
@patch("evap.evaluation.models.UserProfile.can_be_marked_inactive_by_manager", False) | ||
def test_do_not_remove_user_due_to_inactivity_with_active_evaluation(self): |
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.
Needs an override on PARTICIPATION_DELETION_AFTER_INACTIVE_TIME to ensure we actually don't do anything because of can_be_marked_inactive_by_manager
, and not because the time simply hasn't passed.
messages = remove_inactive_participations(self.user, test_run=True) | ||
|
||
self.assertEqual( | ||
messages, [f"{self.user.full_name} will be removed from 1 participation(s) due to inactivity."] | ||
) | ||
|
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 is just the same assertion again, duplicated?
We should instead assert that the participations of the user haven't changed.
for user in UserProfile.objects.exclude(email__in=emails_of_non_obsolete_users): | ||
if user.can_be_deleted_by_manager: | ||
deletable_users.append(user) | ||
elif user.is_active and user.can_be_marked_inactive_by_manager: | ||
users_to_mark_inactive.append(user) | ||
elif not user.is_active: |
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 elif here seems suspicious to me. An inactive user that has can_be_marked_inactive_by_manager == False
wouldn't end up in inactive_users
, and thus we wouldn't call remove_inactive_participations
. I don't know whether such a user can exist, but I'd prefer to not have to think about this.
I think the loop here was meaningful and concise before, and just handled user deletion (or deactivation, if deletion isn't possible). I'd view removal of participations as orthogonal, and try to keep these as separate as possible, i.e., first just handle all deletion/marking inactive, and then handle participation archival on the remaining users. What do you think about that?
Fixes #2176.
Additionally added two test in class RemoveUserDueToInactivity. During test run of "Bulk update users" in the web with evap/staff/fixtures/test_user_bulk_update_file.txt, Lyndsey Lattimore should get removed from 1 participation(s) due to inactivity..