File tree Expand file tree Collapse file tree
src/uds/core/services/generics/fixed Expand file tree Collapse file tree Original file line number Diff line number Diff line change 2828"""
2929Author: Adolfo Gómez, dkmaster at dkmon dot com
3030"""
31+
3132import random # Not for cryptographic purposes, just to randomize the assignation of machines
3233import abc
3334import contextlib
@@ -147,9 +148,16 @@ def initialize(self, values: 'types.core.ValuesType') -> None:
147148 if not self .machines .value :
148149 raise exceptions .ui .ValidationError (gettext ('We need at least a machine' ))
149150
150- # Remove machines not in values from "assigned" set
151+ # Do not allow removing machines that still have assigned user services.
152+ # (their UserService rows would linger, counting against userservices_limit)
151153 with self ._assigned_access () as assigned_vms :
152- assigned_vms &= set (self .machines .as_list ())
154+ removed_assigned = assigned_vms - set (self .machines .as_list ())
155+ if removed_assigned :
156+ raise exceptions .ui .ValidationError (
157+ gettext ('Cannot remove machines with assigned services: {}' ).format (
158+ ', ' .join (self .get_name (m ) or m for m in sorted (removed_assigned ))
159+ )
160+ )
153161 self .token .value = self .token .value .strip ()
154162
155163 @contextlib .contextmanager
You can’t perform that action at this time.
0 commit comments