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

Group expire #111

Merged
merged 14 commits into from
Jan 29, 2025
Merged

Group expire #111

merged 14 commits into from
Jan 29, 2025

Conversation

jamesturner246
Copy link
Contributor

@jamesturner246 jamesturner246 commented Jan 23, 2025

Description

Automatically prune old expired group memberships.

This change adds an expiry datetime field to group membership relations. From here, we can use a django management command, scheduled as a Q task, to prune all instances of GroupMembership with expiration earlier than the current UTC time.

expiration currently default NULL, so it doesn't break stuff, and NULL means no expiration. You'll need to manually set an expiry time manually in the admin page to test.

Currently set to daily expiration checking -- modify your 0007 migration file with something shorter like the following to test it:

    Schedule.objects.update_or_create(
        name="Prune Expired Group Memberships",
        func="django.core.management.call_command",
        args=["prune_groups"],
        schedule_type="I",  # for m(I)nutes
        minutes=1,  # for one minute
    )

Also you'll need to run qcluster manually:

docker compose exec app coldfront qcluster

Tests are added, but I had to add django_q to installed apps in conftest.py, else temp db creation fails. Not sure if that's the right way.

Dunno who else to add as reviewer.

Fixes #80
Fixes #81
Fixes #91

Type of change

  • Documentation (non-breaking change that adds or improves the documentation)
  • New feature (non-breaking change which adds functionality)
  • Optimization (non-breaking, back-end change that speeds up the code)
  • Bug fix (non-breaking change which fixes an issue)
  • Breaking change (whatever its nature)

Key checklist

  • All tests pass (eg. python -m pytest)
  • The documentation builds and looks OK (eg. python -m sphinx -b html docs docs/build)
  • Pre-commit hooks run successfully (eg. pre-commit run --all-files)

Further checks

  • Code is commented, particularly in hard-to-understand areas
  • Tests added or an issue has been opened to tackle that in the future. (Indicate issue here: # (issue))

@jamesturner246 jamesturner246 marked this pull request as ready for review January 23, 2025 19:28
Copy link
Contributor

@Sahil590 Sahil590 left a comment

Choose a reason for hiding this comment

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

Overall, the code looks fine and I have tested the expiry.

Copy link
Collaborator

@cc-a cc-a left a comment

Choose a reason for hiding this comment

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

Thanks @jamesturner246. Looks nice. Just need to make the field required which will probably have a few knock-on effects.

imperial_coldfront_plugin/models.py Outdated Show resolved Hide resolved
@jamesturner246 jamesturner246 requested a review from cc-a January 28, 2025 23:29
Copy link
Collaborator

@cc-a cc-a left a comment

Choose a reason for hiding this comment

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

Grand. Thanks @jamesturner246

@cc-a cc-a merged commit 3eedded into main Jan 29, 2025
4 checks passed
@cc-a cc-a deleted the group_expire branch January 29, 2025 21:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants