fix: 远程应用授权的一些问题

pull/5280/head
xinwen 2020-12-16 11:30:16 +08:00 committed by Jiangjie.Bai
parent 9a5f9a9c92
commit 3aed4955c8
1 changed files with 26 additions and 17 deletions

View File

@ -7,7 +7,7 @@ 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
from applications.models import Application, Category
from common.utils import get_logger
from common.exceptions import M2MReverseNotAllowed
from common.const.signals import POST_ADD, POST_REMOVE, POST_CLEAR
@ -248,7 +248,10 @@ def on_node_asset_change(action, instance, reverse, pk_set, **kwargs):
@receiver(m2m_changed, sender=ApplicationPermission.system_users.through)
def on_remote_app_permission_system_users_changed(sender, instance: ApplicationPermission, action, reverse, pk_set, **kwargs):
def on_application_permission_system_users_changed(sender, instance: ApplicationPermission, action, reverse, pk_set, **kwargs):
if instance.category != Category.remote_app:
return
if reverse:
raise M2MReverseNotAllowed
@ -258,23 +261,25 @@ def on_remote_app_permission_system_users_changed(sender, instance: ApplicationP
system_users = SystemUser.objects.filter(pk__in=pk_set)
logger.debug("Application permission system_users change signal received")
attrs = instance.applications.all().values_list('attrs', flat=True)
assets_id = []
for attr in attrs:
asset_id = attr.get('asset')
if asset_id:
assets_id.append(asset_id)
assets_id = [attr['asset'] for attr in attrs if attr.get('asset')]
if not assets_id:
return
for system_user in system_users:
system_user.assets.add(*assets_id)
if system_user.username_same_with_user:
users_id = instance.users.all().values_list('id', flat=True)
groups_id = instance.user_groups.all().values_list('id', flat=True)
system_user.groups.add(*users_id)
system_user.users.add(*groups_id)
system_user.groups.add(*groups_id)
system_user.users.add(*users_id)
@receiver(m2m_changed, sender=ApplicationPermission.users.through)
def on_remoteapps_permission_users_changed(sender, instance, action, reverse, pk_set, **kwargs):
def on_application_permission_users_changed(sender, instance, action, reverse, pk_set, **kwargs):
if instance.category != Category.remote_app:
return
if reverse:
raise M2MReverseNotAllowed
@ -291,7 +296,10 @@ def on_remoteapps_permission_users_changed(sender, instance, action, reverse, pk
@receiver(m2m_changed, sender=ApplicationPermission.user_groups.through)
def on_remoteapps_permission_user_groups_changed(sender, instance, action, reverse, pk_set, **kwargs):
def on_application_permission_user_groups_changed(sender, instance, action, reverse, pk_set, **kwargs):
if instance.category != Category.remote_app:
return
if reverse:
raise M2MReverseNotAllowed
@ -308,7 +316,10 @@ def on_remoteapps_permission_user_groups_changed(sender, instance, action, rever
@receiver(m2m_changed, sender=ApplicationPermission.applications.through)
def on_remoteapps_permission_user_groups_changed(sender, instance, action, reverse, pk_set, **kwargs):
def on_application_permission_user_groups_changed(sender, instance, action, reverse, pk_set, **kwargs):
if instance.category != Category.remote_app:
return
if reverse:
raise M2MReverseNotAllowed
@ -316,11 +327,9 @@ def on_remoteapps_permission_user_groups_changed(sender, instance, action, rever
return
attrs = Application.objects.filter(id__in=pk_set).values_list('attrs', flat=True)
assets_id = []
for attr in attrs:
asset_id = attr.get('asset')
if asset_id:
assets_id.append(asset_id)
assets_id = [attr['asset'] for attr in attrs if attr.get('asset')]
if not assets_id:
return
system_users = instance.system_users.all()