mirror of
https://github.com/jumpserver/jumpserver.git
synced 2026-08-09 08:03:53 +00:00
feat:simple
This commit is contained in:
@@ -16,20 +16,6 @@ def local_now():
|
||||
return dj_timezone.localtime(dj_timezone.now())
|
||||
|
||||
|
||||
def expiration_remain_days(date_expired, today=None):
|
||||
if today is None:
|
||||
today = local_now().date()
|
||||
date_expired = dj_timezone.localtime(date_expired).date()
|
||||
return (date_expired - today).days
|
||||
|
||||
|
||||
def should_notify_expiration(remain_days, first_notice_days, daily_notice_days):
|
||||
return (
|
||||
remain_days == first_notice_days
|
||||
or 0 <= remain_days <= daily_notice_days
|
||||
)
|
||||
|
||||
|
||||
def local_now_display(fmt='%Y-%m-%d %H:%M:%S'):
|
||||
return local_now().strftime(fmt)
|
||||
|
||||
|
||||
@@ -11,9 +11,7 @@ from django.utils.translation import gettext_lazy as _
|
||||
|
||||
from common.const.crontab import CRONTAB_AT_AM_TEN
|
||||
from common.utils import get_logger
|
||||
from common.utils.timezone import (
|
||||
dt_parser, expiration_remain_days, local_now, should_notify_expiration,
|
||||
)
|
||||
from common.utils.timezone import dt_parser, local_now
|
||||
from ops.celery.decorator import register_as_period_task
|
||||
from orgs.utils import tmp_to_root_org
|
||||
from perms.models import AssetPermission
|
||||
@@ -62,8 +60,8 @@ def check_asset_permission_expired():
|
||||
def check_asset_permission_will_expired():
|
||||
first_notice_days = settings.PERM_EXPIRED_FIRST_NOTICE_DAYS
|
||||
daily_notice_days = settings.PERM_EXPIRED_DAILY_NOTICE_DAYS
|
||||
start = local_now().replace(hour=0, minute=0, second=0, microsecond=0)
|
||||
end = start + timedelta(days=max(first_notice_days, daily_notice_days) + 1)
|
||||
start = local_now()
|
||||
end = start + timedelta(days=first_notice_days + 1)
|
||||
|
||||
user_asset_remain_day_mapper = defaultdict(dict)
|
||||
org_perm_remain_day_mapper = defaultdict(dict)
|
||||
@@ -76,9 +74,12 @@ def check_asset_permission_will_expired():
|
||||
|
||||
for asset_perm in asset_perms:
|
||||
date_expired = dt_parser(asset_perm.date_expired)
|
||||
remain_days = expiration_remain_days(date_expired, start.date())
|
||||
if not should_notify_expiration(
|
||||
remain_days, first_notice_days, daily_notice_days):
|
||||
remain_days = (date_expired - start).days
|
||||
should_notify = (
|
||||
remain_days == first_notice_days
|
||||
or 0 <= remain_days <= daily_notice_days
|
||||
)
|
||||
if not should_notify:
|
||||
continue
|
||||
|
||||
org = asset_perm.org
|
||||
|
||||
@@ -12,9 +12,6 @@ from django.utils.translation import gettext_lazy as _, gettext_noop
|
||||
from audits.const import ActivityChoices
|
||||
from common.const.crontab import CRONTAB_AT_AM_TEN, CRONTAB_AT_PM_TWO
|
||||
from common.utils import get_logger
|
||||
from common.utils.timezone import (
|
||||
expiration_remain_days, local_now, should_notify_expiration,
|
||||
)
|
||||
from ops.celery.decorator import after_app_ready_start, register_as_period_task
|
||||
from ops.celery.utils import create_or_update_celery_periodic_tasks
|
||||
from orgs.utils import tmp_to_root_org
|
||||
@@ -76,18 +73,20 @@ def check_password_expired_periodic():
|
||||
def check_user_expired():
|
||||
first_notice_days = settings.USER_EXPIRED_FIRST_NOTICE_DAYS
|
||||
daily_notice_days = settings.USER_EXPIRED_DAILY_NOTICE_DAYS
|
||||
start = local_now().replace(hour=0, minute=0, second=0, microsecond=0)
|
||||
end = start + timedelta(days=max(first_notice_days, daily_notice_days) + 1)
|
||||
date_expired_lt = timezone.now() + timezone.timedelta(days=first_notice_days + 1)
|
||||
users = User.get_nature_users() \
|
||||
.filter(source=User.Source.local) \
|
||||
.filter(date_expired__gte=start, date_expired__lt=end)
|
||||
.filter(date_expired__lt=date_expired_lt)
|
||||
|
||||
for user in users:
|
||||
if not user.is_active:
|
||||
if not user.is_valid:
|
||||
continue
|
||||
remain_days = expiration_remain_days(user.date_expired, start.date())
|
||||
if not should_notify_expiration(
|
||||
remain_days, first_notice_days, daily_notice_days):
|
||||
remain_days = user.expired_remain_days
|
||||
should_notify = (
|
||||
remain_days == first_notice_days
|
||||
or 0 <= remain_days <= daily_notice_days
|
||||
)
|
||||
if not should_notify:
|
||||
continue
|
||||
msg = "The user {} will expires in {} days"
|
||||
logger.info(msg.format(user, remain_days))
|
||||
|
||||
Reference in New Issue
Block a user