mirror of https://github.com/jumpserver/jumpserver
perf: 授权过期通知
parent
556ce0a146
commit
f91bfedc50
|
@ -1,3 +1,3 @@
|
||||||
version https://git-lfs.github.com/spec/v1
|
version https://git-lfs.github.com/spec/v1
|
||||||
oid sha256:82cdb805f6d681577806fb6fc41178b5dd28eafc68b1348f433ba7f7f5ce9920
|
oid sha256:8a0e0ef94fd1cf5b3d41c378b54e8af2fb502c7f1e9d6a3e54084e8113978561
|
||||||
size 127478
|
size 127495
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -1,3 +1,3 @@
|
||||||
version https://git-lfs.github.com/spec/v1
|
version https://git-lfs.github.com/spec/v1
|
||||||
oid sha256:b03f7f9c1d450f8a3012330c00d084c88465d99e355c42ec10f568a8ffa7611c
|
oid sha256:1ab23fa4d87b928318281150ff64d9c2e3782a9169a3c3e6907808b1be63dbc3
|
||||||
size 105357
|
size 105365
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -3,7 +3,6 @@
|
||||||
# This file is distributed under the same license as the PACKAGE package.
|
# This file is distributed under the same license as the PACKAGE package.
|
||||||
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
|
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
|
||||||
#
|
#
|
||||||
#, fuzzy
|
|
||||||
msgid ""
|
msgid ""
|
||||||
msgstr ""
|
msgstr ""
|
||||||
"Project-Id-Version: PACKAGE VERSION\n"
|
"Project-Id-Version: PACKAGE VERSION\n"
|
||||||
|
|
|
@ -9,14 +9,16 @@ from notifications.notifications import UserMessage
|
||||||
|
|
||||||
|
|
||||||
class PermedAssetsWillExpireUserMsg(UserMessage):
|
class PermedAssetsWillExpireUserMsg(UserMessage):
|
||||||
def __init__(self, user, assets):
|
def __init__(self, user, assets, day_count=0):
|
||||||
super().__init__(user)
|
super().__init__(user)
|
||||||
self.assets = assets
|
self.assets = assets
|
||||||
|
self.count = day_count
|
||||||
|
|
||||||
def get_html_msg(self) -> dict:
|
def get_html_msg(self) -> dict:
|
||||||
subject = _("You permed assets is about to expire")
|
subject = _("You permed assets is about to expire")
|
||||||
context = {
|
context = {
|
||||||
'name': self.user.name,
|
'name': self.user.name,
|
||||||
|
'day_count': self.day_count,
|
||||||
'items': [str(asset) for asset in self.assets],
|
'items': [str(asset) for asset in self.assets],
|
||||||
'item_type': _("permed assets"),
|
'item_type': _("permed assets"),
|
||||||
'show_help': True
|
'show_help': True
|
||||||
|
@ -38,10 +40,11 @@ class PermedAssetsWillExpireUserMsg(UserMessage):
|
||||||
|
|
||||||
class AssetPermsWillExpireForOrgAdminMsg(UserMessage):
|
class AssetPermsWillExpireForOrgAdminMsg(UserMessage):
|
||||||
|
|
||||||
def __init__(self, user, perms, org):
|
def __init__(self, user, perms, org, day_count=0):
|
||||||
super().__init__(user)
|
super().__init__(user)
|
||||||
self.perms = perms
|
self.perms = perms
|
||||||
self.org = org
|
self.org = org
|
||||||
|
self.count = day_count
|
||||||
|
|
||||||
def get_items_with_url(self):
|
def get_items_with_url(self):
|
||||||
items_with_url = []
|
items_with_url = []
|
||||||
|
@ -59,6 +62,7 @@ class AssetPermsWillExpireForOrgAdminMsg(UserMessage):
|
||||||
subject = _("Asset permissions is about to expire")
|
subject = _("Asset permissions is about to expire")
|
||||||
context = {
|
context = {
|
||||||
'name': self.user.name,
|
'name': self.user.name,
|
||||||
|
'day_count': self.day_count,
|
||||||
'items_with_url': items_with_url,
|
'items_with_url': items_with_url,
|
||||||
'item_type': _('asset permissions of organization {}').format(self.org)
|
'item_type': _('asset permissions of organization {}').format(self.org)
|
||||||
}
|
}
|
||||||
|
@ -81,14 +85,16 @@ class AssetPermsWillExpireForOrgAdminMsg(UserMessage):
|
||||||
|
|
||||||
|
|
||||||
class PermedAppsWillExpireUserMsg(UserMessage):
|
class PermedAppsWillExpireUserMsg(UserMessage):
|
||||||
def __init__(self, user, apps):
|
def __init__(self, user, apps, day_count=0):
|
||||||
super().__init__(user)
|
super().__init__(user)
|
||||||
self.apps = apps
|
self.apps = apps
|
||||||
|
self.count = day_count
|
||||||
|
|
||||||
def get_html_msg(self) -> dict:
|
def get_html_msg(self) -> dict:
|
||||||
subject = _("Your permed applications is about to expire")
|
subject = _("Your permed applications is about to expire")
|
||||||
context = {
|
context = {
|
||||||
'name': self.user.name,
|
'name': self.user.name,
|
||||||
|
'day_count': self.day_count,
|
||||||
'item_type': _('permed applications'),
|
'item_type': _('permed applications'),
|
||||||
'items': [str(app) for app in self.apps]
|
'items': [str(app) for app in self.apps]
|
||||||
}
|
}
|
||||||
|
@ -109,10 +115,11 @@ class PermedAppsWillExpireUserMsg(UserMessage):
|
||||||
|
|
||||||
|
|
||||||
class AppPermsWillExpireForOrgAdminMsg(UserMessage):
|
class AppPermsWillExpireForOrgAdminMsg(UserMessage):
|
||||||
def __init__(self, user, perms, org):
|
def __init__(self, user, perms, org, day_count=0):
|
||||||
super().__init__(user)
|
super().__init__(user)
|
||||||
self.perms = perms
|
self.perms = perms
|
||||||
self.org = org
|
self.org = org
|
||||||
|
self.count = day_count
|
||||||
|
|
||||||
def get_items_with_url(self):
|
def get_items_with_url(self):
|
||||||
items_with_url = []
|
items_with_url = []
|
||||||
|
|
|
@ -63,8 +63,8 @@ def check_asset_permission_will_expired():
|
||||||
start = local_now()
|
start = local_now()
|
||||||
end = start + timedelta(days=3)
|
end = start + timedelta(days=3)
|
||||||
|
|
||||||
user_asset_mapper = defaultdict(set)
|
user_asset_remain_day_mapper = defaultdict(dict)
|
||||||
org_perm_mapper = defaultdict(set)
|
org_perm_remain_day_mapper = defaultdict(dict)
|
||||||
|
|
||||||
asset_perms = AssetPermission.objects.filter(
|
asset_perms = AssetPermission.objects.filter(
|
||||||
date_expired__gte=start,
|
date_expired__gte=start,
|
||||||
|
@ -72,23 +72,35 @@ def check_asset_permission_will_expired():
|
||||||
).distinct()
|
).distinct()
|
||||||
|
|
||||||
for asset_perm in asset_perms:
|
for asset_perm in asset_perms:
|
||||||
|
date_expired = dt_parser(asset_perm.date_expired)
|
||||||
|
remain_days = (end - date_expired).days
|
||||||
|
|
||||||
|
org = asset_perm.org
|
||||||
# 资产授权按照组织分类
|
# 资产授权按照组织分类
|
||||||
org_perm_mapper[asset_perm.org].add(asset_perm)
|
if org in org_perm_remain_day_mapper[remain_days]:
|
||||||
|
org_perm_remain_day_mapper[remain_days][org].add(asset_perm)
|
||||||
|
else:
|
||||||
|
org_perm_remain_day_mapper[remain_days][org] = set()
|
||||||
|
|
||||||
# 计算每个用户即将过期的资产
|
# 计算每个用户即将过期的资产
|
||||||
users = asset_perm.get_all_users()
|
users = asset_perm.get_all_users()
|
||||||
assets = asset_perm.get_all_assets()
|
assets = asset_perm.get_all_assets()
|
||||||
|
|
||||||
for u in users:
|
for u in users:
|
||||||
user_asset_mapper[u].update(assets)
|
if u in user_asset_remain_day_mapper[remain_days]:
|
||||||
|
user_asset_remain_day_mapper[remain_days][u].update(assets)
|
||||||
|
else:
|
||||||
|
user_asset_remain_day_mapper[remain_days][u] = set()
|
||||||
|
|
||||||
|
for day_count, user_asset_mapper in user_asset_remain_day_mapper.items():
|
||||||
for user, assets in user_asset_mapper.items():
|
for user, assets in user_asset_mapper.items():
|
||||||
PermedAssetsWillExpireUserMsg(user, assets).publish_async()
|
PermedAssetsWillExpireUserMsg(user, assets, day_count).publish_async()
|
||||||
|
|
||||||
|
for day_count, org_perm_mapper in org_perm_remain_day_mapper.items():
|
||||||
for org, perms in org_perm_mapper.items():
|
for org, perms in org_perm_mapper.items():
|
||||||
org_admins = org.admins.all()
|
org_admins = org.admins.all()
|
||||||
for org_admin in org_admins:
|
for org_admin in org_admins:
|
||||||
AssetPermsWillExpireForOrgAdminMsg(org_admin, perms, org).publish_async()
|
AssetPermsWillExpireForOrgAdminMsg(org_admin, perms, org, day_count).publish_async()
|
||||||
|
|
||||||
|
|
||||||
@register_as_period_task(crontab='0 10 * * *')
|
@register_as_period_task(crontab='0 10 * * *')
|
||||||
|
@ -104,21 +116,33 @@ def check_app_permission_will_expired():
|
||||||
date_expired__lte=end
|
date_expired__lte=end
|
||||||
).distinct()
|
).distinct()
|
||||||
|
|
||||||
user_app_mapper = defaultdict(set)
|
user_app_remain_day_mapper = defaultdict(dict)
|
||||||
org_perm_mapper = defaultdict(set)
|
org_perm_remain_day_mapper = defaultdict(dict)
|
||||||
|
|
||||||
for app_perm in app_perms:
|
for app_perm in app_perms:
|
||||||
org_perm_mapper[app_perm.org].add(app_perm)
|
date_expired = dt_parser(app_perm.date_expired)
|
||||||
|
remain_days = (end - date_expired).days
|
||||||
|
|
||||||
|
org = app_perm.org
|
||||||
|
if org in org_perm_remain_day_mapper[remain_days]:
|
||||||
|
org_perm_remain_day_mapper[remain_days][org].add(app_perm)
|
||||||
|
else:
|
||||||
|
org_perm_remain_day_mapper[remain_days][org] = set()
|
||||||
|
|
||||||
users = app_perm.get_all_users()
|
users = app_perm.get_all_users()
|
||||||
apps = app_perm.applications.all()
|
apps = app_perm.applications.all()
|
||||||
for u in users:
|
for u in users:
|
||||||
user_app_mapper[u].update(apps)
|
if u in user_app_remain_day_mapper[remain_days]:
|
||||||
|
user_app_remain_day_mapper[remain_days][u].update(apps)
|
||||||
|
else:
|
||||||
|
user_app_remain_day_mapper[remain_days][u] = set()
|
||||||
|
|
||||||
|
for day_count, user_app_mapper in user_app_remain_day_mapper.items():
|
||||||
for user, apps in user_app_mapper.items():
|
for user, apps in user_app_mapper.items():
|
||||||
PermedAppsWillExpireUserMsg(user, apps).publish_async()
|
PermedAppsWillExpireUserMsg(user, apps, day_count).publish_async()
|
||||||
|
|
||||||
|
for day_count, org_perm_mapper in org_perm_remain_day_mapper.items():
|
||||||
for org, perms in org_perm_mapper.items():
|
for org, perms in org_perm_mapper.items():
|
||||||
org_admins = org.admins.all()
|
org_admins = org.admins.all()
|
||||||
for org_admin in org_admins:
|
for org_admin in org_admins:
|
||||||
AppPermsWillExpireForOrgAdminMsg(org_admin, perms, org).publish_async()
|
AppPermsWillExpireForOrgAdminMsg(org_admin, perms, org, day_count).publish_async()
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
{% blocktranslate %}
|
{% blocktranslate %}
|
||||||
The following {{ item_type }} will expire in 3 days
|
The following {{ item_type }} will expire in %(count)s days
|
||||||
{% endblocktranslate %}
|
{% endblocktranslate %}
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
{% blocktranslate %}
|
{% blocktranslate %}
|
||||||
The following {{ item_type }} will expire in 3 days
|
The following {{ item_type }} will expire in %(count)s days
|
||||||
{% endblocktranslate %}
|
{% endblocktranslate %}
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue