func PropertyCreatePolicyRule() privacy.MutationRule {
	return privacy.PropertyMutationRuleFunc(func(ctx context.Context, m *ent.PropertyMutation) error {
		if !m.Op().Is(ent.OpCreate) {
			return privacy.Skip
		}
		p := FromContext(ctx)
		if locationID, exists := m.LocationID(); exists {
			locationTypeID, err := m.Client().LocationType.Query().
				Where(locationtype.HasLocationsWith(location.ID(locationID))).
				OnlyID(ctx)
			if err != nil {
				if ent.IsNotFound(err) {
					return privacy.Skip
				}
				return privacy.Denyf("failed to fetch location type id: %w", err)
			}
			return allowOrSkipLocations(p.InventoryPolicy.Location.Update, locationTypeID)
		}
		if _, exists := m.EquipmentID(); exists {
			return allowOrSkip(p.InventoryPolicy.Equipment.Update)
		}
		if _, exists := m.EquipmentPortID(); exists {
			return allowOrSkip(p.InventoryPolicy.Equipment.Update)
		}
		if _, exists := m.LinkID(); exists {
			return allowOrSkip(p.InventoryPolicy.Equipment.Update)
		}
		if _, exists := m.ServiceID(); exists {
			return allowOrSkip(p.InventoryPolicy.Equipment.Update)
		}
		if workOrderID, exists := m.WorkOrderID(); exists {
			workOrder, err := m.Client().WorkOrder.Get(ctx, workOrderID)
			if err != nil {
				if !ent.IsNotFound(err) {
					return privacy.Denyf("failed to fetch work order: %w", err)
				}
				return privacy.Skip
			}
			return allowOrSkipWorkOrder(ctx, p, workOrder)
		}
		if projectID, exists := m.ProjectID(); exists {
			proj, err := m.Client().Project.Get(ctx, projectID)
			if err != nil {
				if !ent.IsNotFound(err) {
					return privacy.Denyf("failed to fetch project: %w", err)
				}
				return privacy.Skip
			}
			return allowOrSkipProject(ctx, p, proj)
		}
		return privacy.Skip
	})
}
// PropertyCreatePolicyRule grants create permission to property based on policy.
// nolint: dupl
PropertyCreatePolicyRule grants create permission to property based on policy.
nolint: dupl
// PropertyCreatePolicyRule grants create permission to property based on policy . // nolint : dupl
func PropertyCreatePolicyRule() privacy.MutationRule {
	return privacy.PropertyMutationRuleFunc(func(ctx context.Context, m *ent.PropertyMutation) error {
		if !m.Op().Is(ent.OpCreate) {
			return privacy.Skip
		}
		p := FromContext(ctx)
		if locationID, exists := m.LocationID(); exists {
			locationTypeID, err := m.Client().LocationType.Query().
				Where(locationtype.HasLocationsWith(location.ID(locationID))).
				OnlyID(ctx)
			if err != nil {
				if ent.IsNotFound(err) {
					return privacy.Skip
				}
				return privacy.Denyf("failed to fetch location type id: %w", err)
			}
			return allowOrSkipLocations(p.InventoryPolicy.Location.Update, locationTypeID)
		}
		if _, exists := m.EquipmentID(); exists {
			return allowOrSkip(p.InventoryPolicy.Equipment.Update)
		}
		if _, exists := m.EquipmentPortID(); exists {
			return allowOrSkip(p.InventoryPolicy.Equipment.Update)
		}
		if _, exists := m.LinkID(); exists {
			return allowOrSkip(p.InventoryPolicy.Equipment.Update)
		}
		if _, exists := m.ServiceID(); exists {
			return allowOrSkip(p.InventoryPolicy.Equipment.Update)
		}
		if workOrderID, exists := m.WorkOrderID(); exists {
			workOrder, err := m.Client().WorkOrder.Get(ctx, workOrderID)
			if err != nil {
				if !ent.IsNotFound(err) {
					return privacy.Denyf("failed to fetch work order: %w", err)
				}
				return privacy.Skip
			}
			return allowOrSkipWorkOrder(ctx, p, workOrder)
		}
		if projectID, exists := m.ProjectID(); exists {
			proj, err := m.Client().Project.Get(ctx, projectID)
			if err != nil {
				if !ent.IsNotFound(err) {
					return privacy.Denyf("failed to fetch project: %w", err)
				}
				return privacy.Skip
			}
			return allowOrSkipProject(ctx, p, proj)
		}
		return privacy.Skip
	})
}
func PropertyCreatePolicyRule ( ) privacy . MutationRule { return privacy . PropertyMutationRuleFunc ( func ( ctx context . Context , m * ent . PropertyMutation ) error { if ! m . Op ( ) . Is ( ent . OpCreate ) { return privacy . Skip } p := FromContext ( ctx ) if locationID , exists := m . LocationID ( ) ; exists { locationTypeID , err := m . Client ( ) . LocationType . Query ( ) . Where ( locationtype . HasLocationsWith ( location . ID ( locationID ) ) ) . OnlyID ( ctx ) if err != nil { if ent . IsNotFound ( err ) { return privacy . Skip } return privacy . Denyf ( " " , err ) } return allowOrSkipLocations ( p . InventoryPolicy . Location . Update , locationTypeID ) } if _ , exists := m . EquipmentID ( ) ; exists { return allowOrSkip ( p . InventoryPolicy . Equipment . Update ) } if _ , exists := m . EquipmentPortID ( ) ; exists { return allowOrSkip ( p . InventoryPolicy . Equipment . Update ) } if _ , exists := m . LinkID ( ) ; exists { return allowOrSkip ( p . InventoryPolicy . Equipment . Update ) } if _ , exists := m . ServiceID ( ) ; exists { return allowOrSkip ( p . InventoryPolicy . Equipment . Update ) } if workOrderID , exists := m . WorkOrderID ( ) ; exists { workOrder , err := m . Client ( ) . WorkOrder . Get ( ctx , workOrderID ) if err != nil { if ! ent . IsNotFound ( err ) { return privacy . Denyf ( " " , err ) } return privacy . Skip } return allowOrSkipWorkOrder ( ctx , p , workOrder ) } if projectID , exists := m . ProjectID ( ) ; exists { proj , err := m . Client ( ) . Project . Get ( ctx , projectID ) if err != nil { if ! ent . IsNotFound ( err ) { return privacy . Denyf ( " " , err ) } return privacy . Skip } return allowOrSkipProject ( ctx , p , proj ) } return privacy . Skip } ) }
PropertyCreatePolicyRule grants create permission to property based on policy.
PropertyCreatePolicyRule grants create permission to property based on policy .