2017-12-04 12:15:47 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
#
|
2016-11-10 15:54:21 +00:00
|
|
|
|
|
|
|
from celery import shared_task
|
2018-11-22 10:02:12 +00:00
|
|
|
|
2019-01-15 02:23:30 +00:00
|
|
|
from ops.celery.utils import create_or_update_celery_periodic_tasks
|
2019-07-31 08:57:21 +00:00
|
|
|
from ops.celery.decorator import after_app_ready_start
|
2018-11-22 10:02:12 +00:00
|
|
|
from common.utils import get_logger
|
2019-03-04 03:36:10 +00:00
|
|
|
from .models import User
|
2019-07-31 08:57:21 +00:00
|
|
|
from .utils import (
|
|
|
|
send_password_expiration_reminder_mail, send_user_expiration_reminder_mail
|
|
|
|
)
|
2018-11-22 10:02:12 +00:00
|
|
|
|
|
|
|
|
|
|
|
logger = get_logger(__file__)
|
2016-11-10 15:54:21 +00:00
|
|
|
|
|
|
|
|
2018-11-22 10:02:12 +00:00
|
|
|
@shared_task
|
|
|
|
def check_password_expired():
|
|
|
|
users = User.objects.exclude(role=User.ROLE_APP)
|
|
|
|
for user in users:
|
2019-07-30 04:52:45 +00:00
|
|
|
if not user.is_valid:
|
|
|
|
continue
|
2018-11-22 10:02:12 +00:00
|
|
|
if not user.password_will_expired:
|
|
|
|
continue
|
|
|
|
send_password_expiration_reminder_mail(user)
|
2019-07-30 04:52:45 +00:00
|
|
|
msg = "The user {} password expires in {} days"
|
|
|
|
logger.info(msg.format(user, user.password_expired_remain_days))
|
2018-11-22 10:02:12 +00:00
|
|
|
|
|
|
|
|
|
|
|
@shared_task
|
|
|
|
@after_app_ready_start
|
|
|
|
def check_password_expired_periodic():
|
|
|
|
tasks = {
|
|
|
|
'check_password_expired_periodic': {
|
|
|
|
'task': check_password_expired.name,
|
|
|
|
'interval': None,
|
|
|
|
'crontab': '0 10 * * *',
|
|
|
|
'enabled': True,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
create_or_update_celery_periodic_tasks(tasks)
|
2019-03-04 02:39:44 +00:00
|
|
|
|
|
|
|
|
2019-07-31 08:57:21 +00:00
|
|
|
@shared_task
|
|
|
|
def check_user_expired():
|
|
|
|
users = User.objects.exclude(role=User.ROLE_APP)
|
|
|
|
for user in users:
|
|
|
|
if not user.is_valid:
|
|
|
|
continue
|
|
|
|
if not user.will_expired:
|
|
|
|
continue
|
|
|
|
send_user_expiration_reminder_mail(user)
|
|
|
|
|
|
|
|
|
|
|
|
@shared_task
|
|
|
|
@after_app_ready_start
|
|
|
|
def check_user_expired_periodic():
|
|
|
|
tasks = {
|
|
|
|
'check_user_expired_periodic': {
|
|
|
|
'task': check_user_expired.name,
|
|
|
|
'interval': None,
|
|
|
|
'crontab': '0 14 * * *',
|
|
|
|
'enabled': True,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
create_or_update_celery_periodic_tasks(tasks)
|
2019-03-04 03:36:10 +00:00
|
|
|
|