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

Delete participations of long inactive users #2329

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

Conversation

Redflashx12
Copy link
Collaborator

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..

Copy link
Member

@richardebeling richardebeling left a 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.

evap/settings.py Outdated Show resolved Hide resolved
evap/staff/tests/test_tools.py Outdated Show resolved Hide resolved
evap/staff/tests/test_tools.py Outdated Show resolved Hide resolved
evap/staff/tests/test_tools.py Outdated Show resolved Hide resolved
evap/staff/tests/test_tools.py Outdated Show resolved Hide resolved
evap/staff/tests/test_tools.py Outdated Show resolved Hide resolved
evap/staff/tools.py Outdated Show resolved Hide resolved
evap/staff/tools.py Outdated Show resolved Hide resolved
evap/staff/tools.py Outdated Show resolved Hide resolved
evap/staff/tools.py Outdated Show resolved Hide resolved
@Redflashx12
Copy link
Collaborator Author

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.

Thanks for your time in reviewing this PR, especially for all the fixes and explanations. Much appreciated 👍.

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)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
_("{} 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)]
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
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)
]

@niklasmohrin
Copy link
Member

@Redflashx12 Do you want to keep working on this PR (this or next year), or should we take over?

@Redflashx12
Copy link
Collaborator Author

Redflashx12 commented Dec 16, 2024 via email

@niklasmohrin
Copy link
Member

Great, good luck with that! No need to worry or hurry, we just want to track the status of the PR :)

Comment on lines +228 to +233
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(),
Copy link
Member

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)

Suggested change
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):
Copy link
Member

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

Suggested change
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):
Copy link
Member

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.

Comment on lines +284 to +289
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."]
)

Copy link
Member

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:
Copy link
Member

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

Delete participations of long inactive users
4 participants