clean unaccepted invites task
This commit is contained in:
parent
eb8ee67f06
commit
d2440f5bf1
|
|
@ -1,11 +1,14 @@
|
||||||
"""Account app celery tasks."""
|
"""Account app celery tasks."""
|
||||||
|
import datetime
|
||||||
import inspect
|
import inspect
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from celery import shared_task
|
from celery import shared_task
|
||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
|
from celery.schedules import crontab
|
||||||
|
from celery.task import periodic_task
|
||||||
|
|
||||||
from account.models import User
|
from account.models import User, UserRole, Role
|
||||||
|
|
||||||
logging.basicConfig(format='[%(levelname)s] %(message)s', level=logging.INFO)
|
logging.basicConfig(format='[%(levelname)s] %(message)s', level=logging.INFO)
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
@ -46,3 +49,17 @@ def change_email_address(user_id, country_code, emails=None):
|
||||||
def send_password_changed_email(user_id, country_code):
|
def send_password_changed_email(user_id, country_code):
|
||||||
"""Send email which notifies user that his password had changed"""
|
"""Send email which notifies user that his password had changed"""
|
||||||
send_email(user_id, 'Notify password changed', 'notify_password_changed_template', country_code)
|
send_email(user_id, 'Notify password changed', 'notify_password_changed_template', country_code)
|
||||||
|
|
||||||
|
|
||||||
|
@periodic_task(run_every=crontab(hour='*/3'))
|
||||||
|
def clean_unaccepted_establishment_team_invites():
|
||||||
|
"""This task cleans unaccepted (for 7 days) establishment team membership invites."""
|
||||||
|
week_ago = datetime.datetime.now() - datetime.timedelta(days=7)
|
||||||
|
roles_to_remove = UserRole.objects.filter(role__role=Role.ESTABLISHMENT_ADMINISTRATOR,
|
||||||
|
for_team=True, created__lte=week_ago)\
|
||||||
|
.exclude(state=UserRole.VALIDATED).prefetch_related('user', 'role')
|
||||||
|
for user_role in roles_to_remove:
|
||||||
|
user = user_role.user
|
||||||
|
user_role.delete()
|
||||||
|
if user.last_login is None:
|
||||||
|
user.delete()
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user