mirror of
https://github.com/jumpserver/jumpserver.git
synced 2025-09-06 18:00:57 +00:00
reactor&remove: 重构applications模块 & 移除applications、perms中已不再使用的模块 (#5374)
* reactor: 重构applications模块 & 删除applications、perms中已不再使用的模块 * reactor: 1. 针对application.attrs字段的view-serializer映射逻辑,采用DynamicMapping的方案重写; * reactor: 2. 删除applications和perms模块中已不再使用的database-app/k8s-app/remote-app模块; * reactor: 添加迁移文件(删除perms/databaseperrmission/remoteapppermission/k8sapppermission) * reactor: 修改细节 Co-authored-by: Bai <bugatti_it@163.com>
This commit is contained in:
@@ -7,11 +7,11 @@ from perms.tasks import create_rebuild_user_tree_task, \
|
||||
create_rebuild_user_tree_task_by_related_nodes_or_assets
|
||||
from users.models import User, UserGroup
|
||||
from assets.models import Asset, SystemUser
|
||||
from applications.models import Application, Category
|
||||
from applications.models import Application
|
||||
from common.utils import get_logger
|
||||
from common.exceptions import M2MReverseNotAllowed
|
||||
from common.const.signals import POST_ADD, POST_REMOVE, POST_CLEAR
|
||||
from .models import AssetPermission, RemoteAppPermission, ApplicationPermission
|
||||
from .models import AssetPermission, ApplicationPermission
|
||||
|
||||
|
||||
logger = get_logger(__file__)
|
||||
@@ -187,51 +187,6 @@ def on_asset_permission_user_groups_changed(instance, action, pk_set, model,
|
||||
system_user.groups.add(*tuple(groups))
|
||||
|
||||
|
||||
@receiver(m2m_changed, sender=RemoteAppPermission.system_users.through)
|
||||
def on_remote_app_permission_system_users_changed(sender, instance=None,
|
||||
action='', reverse=False, **kwargs):
|
||||
if action != POST_ADD or reverse:
|
||||
return
|
||||
system_users = kwargs['model'].objects.filter(pk__in=kwargs['pk_set'])
|
||||
logger.debug("Remote app permission system_users change signal received")
|
||||
assets = instance.remote_apps.all().values_list('asset__id', flat=True)
|
||||
users = instance.users.all().values_list('id', flat=True)
|
||||
groups = instance.user_groups.all().values_list('id', flat=True)
|
||||
for system_user in system_users:
|
||||
system_user.assets.add(*tuple(assets))
|
||||
if system_user.username_same_with_user:
|
||||
system_user.groups.add(*tuple(groups))
|
||||
system_user.users.add(*tuple(users))
|
||||
|
||||
|
||||
@receiver(m2m_changed, sender=RemoteAppPermission.users.through)
|
||||
def on_remoteapps_permission_users_changed(sender, instance=None, action='',
|
||||
reverse=False, **kwargs):
|
||||
if action != POST_ADD and reverse:
|
||||
return
|
||||
logger.debug("Asset permission users change signal received")
|
||||
users = kwargs['model'].objects.filter(pk__in=kwargs['pk_set'])
|
||||
system_users = instance.system_users.all()
|
||||
|
||||
for system_user in system_users:
|
||||
if system_user.username_same_with_user:
|
||||
system_user.users.add(*tuple(users))
|
||||
|
||||
|
||||
@receiver(m2m_changed, sender=RemoteAppPermission.user_groups.through)
|
||||
def on_remoteapps_permission_user_groups_changed(sender, instance=None, action='',
|
||||
reverse=False, **kwargs):
|
||||
if action != POST_ADD and reverse:
|
||||
return
|
||||
logger.debug("Asset permission user groups change signal received")
|
||||
groups = kwargs['model'].objects.filter(pk__in=kwargs['pk_set'])
|
||||
system_users = instance.system_users.all()
|
||||
|
||||
for system_user in system_users:
|
||||
if system_user.username_same_with_user:
|
||||
system_user.groups.add(*tuple(groups))
|
||||
|
||||
|
||||
@receiver(m2m_changed, sender=Asset.nodes.through)
|
||||
def on_node_asset_change(action, instance, reverse, pk_set, **kwargs):
|
||||
if not need_rebuild_mapping_node(action):
|
||||
@@ -249,7 +204,7 @@ def on_node_asset_change(action, instance, reverse, pk_set, **kwargs):
|
||||
|
||||
@receiver(m2m_changed, sender=ApplicationPermission.system_users.through)
|
||||
def on_application_permission_system_users_changed(sender, instance: ApplicationPermission, action, reverse, pk_set, **kwargs):
|
||||
if instance.category != Category.remote_app:
|
||||
if not instance.category_remote_app:
|
||||
return
|
||||
|
||||
if reverse:
|
||||
@@ -277,7 +232,7 @@ def on_application_permission_system_users_changed(sender, instance: Application
|
||||
|
||||
@receiver(m2m_changed, sender=ApplicationPermission.users.through)
|
||||
def on_application_permission_users_changed(sender, instance, action, reverse, pk_set, **kwargs):
|
||||
if instance.category != Category.remote_app:
|
||||
if not instance.category_remote_app:
|
||||
return
|
||||
|
||||
if reverse:
|
||||
@@ -297,7 +252,7 @@ def on_application_permission_users_changed(sender, instance, action, reverse, p
|
||||
|
||||
@receiver(m2m_changed, sender=ApplicationPermission.user_groups.through)
|
||||
def on_application_permission_user_groups_changed(sender, instance, action, reverse, pk_set, **kwargs):
|
||||
if instance.category != Category.remote_app:
|
||||
if not instance.category_remote_app:
|
||||
return
|
||||
|
||||
if reverse:
|
||||
@@ -317,7 +272,7 @@ def on_application_permission_user_groups_changed(sender, instance, action, reve
|
||||
|
||||
@receiver(m2m_changed, sender=ApplicationPermission.applications.through)
|
||||
def on_application_permission_applications_changed(sender, instance, action, reverse, pk_set, **kwargs):
|
||||
if instance.category != Category.remote_app:
|
||||
if not instance.category_remote_app:
|
||||
return
|
||||
|
||||
if reverse:
|
||||
|
Reference in New Issue
Block a user