mirror of https://github.com/jumpserver/jumpserver
				
				
				
			perf: 工单根据选择组织自动选择流
							parent
							
								
									c7f2afc3c1
								
							
						
					
					
						commit
						9b9e32d2f4
					
				| 
						 | 
				
			
			@ -7,7 +7,7 @@ from common.mixins.models import CommonModelMixin
 | 
			
		|||
from common.db.encoder import ModelJSONFieldEncoder
 | 
			
		||||
from orgs.mixins.models import OrgModelMixin
 | 
			
		||||
from orgs.models import Organization
 | 
			
		||||
from orgs.utils import tmp_to_root_org
 | 
			
		||||
from orgs.utils import tmp_to_root_org, tmp_to_org
 | 
			
		||||
from ..const import TicketType, TicketApprovalLevel, TicketApprovalStrategy
 | 
			
		||||
from ..signals import post_or_update_change_ticket_flow_approval
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -64,9 +64,13 @@ class TicketFlow(CommonModelMixin, OrgModelMixin):
 | 
			
		|||
        return '{}'.format(self.type)
 | 
			
		||||
 | 
			
		||||
    @classmethod
 | 
			
		||||
    def get_org_related_flows(cls):
 | 
			
		||||
        flows = cls.objects.all()
 | 
			
		||||
    def get_org_related_flows(cls, org_id=None):
 | 
			
		||||
        if org_id:
 | 
			
		||||
            with tmp_to_org(org_id):
 | 
			
		||||
                flows = cls.objects.all()
 | 
			
		||||
        else:
 | 
			
		||||
            flows = cls.objects.all()
 | 
			
		||||
        cur_flow_types = flows.values_list('type', flat=True)
 | 
			
		||||
        with tmp_to_root_org():
 | 
			
		||||
            diff_global_flows = cls.objects.exclude(type__in=cur_flow_types).filter(org_id=Organization.ROOT_ID)
 | 
			
		||||
            diff_global_flows = cls.objects.exclude(type__in=cur_flow_types)
 | 
			
		||||
        return flows | diff_global_flows
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -108,7 +108,8 @@ class TicketApplySerializer(TicketSerializer):
 | 
			
		|||
 | 
			
		||||
    def validate(self, attrs):
 | 
			
		||||
        ticket_type = attrs.get('type')
 | 
			
		||||
        flow = TicketFlow.get_org_related_flows().filter(type=ticket_type).first()
 | 
			
		||||
        org_id = attrs.get('org_id')
 | 
			
		||||
        flow = TicketFlow.get_org_related_flows(org_id=org_id).filter(type=ticket_type).first()
 | 
			
		||||
        if flow:
 | 
			
		||||
            attrs['flow'] = flow
 | 
			
		||||
        else:
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue