Show endpoint profile checkboxes and enforce exclusive image selection
This commit is contained in:
+9
-2
@@ -23,6 +23,10 @@ class Endpoint:
|
||||
self.config=dict(port=self.allowed_ports[0] if self.allowed_ports else 8120,enabled_profiles=[],autostart=False)
|
||||
path=self.root/'endpoint.json'
|
||||
if path.exists():self.config.update(json.loads(path.read_text()))
|
||||
image_ids={p['id'] for p in self.profiles.status()['profiles'] if p['kind']=='image'}
|
||||
selected=[i for i in self.config['enabled_profiles'] if i in image_ids]
|
||||
if len(selected)>1:
|
||||
self.config['enabled_profiles']=[i for i in self.config['enabled_profiles'] if i not in image_ids or i==selected[0]];self.persist()
|
||||
def persist(self):
|
||||
self.root.mkdir(parents=True,exist_ok=True,mode=0o700)
|
||||
path=self.root/'endpoint.tmp';path.write_text(json.dumps(self.config));path.replace(self.root/'endpoint.json')
|
||||
@@ -51,12 +55,15 @@ class Endpoint:
|
||||
return self.status()
|
||||
def enable(self,data):
|
||||
if set(data)!={'id','enabled'} or type(data['enabled']) is not bool:raise ValueError('Profil-ID und Aktivierung erforderlich.')
|
||||
row=next((p for p in self.rows() if p['id']==data['id']),None)
|
||||
rows=self.rows()
|
||||
row=next((p for p in rows if p['id']==data['id']),None)
|
||||
if not row:raise ValueError('Profil nicht gefunden.')
|
||||
if data['enabled'] and not row['runnable']:raise ValueError('Profil nicht ausführbar: '+' '.join(row['blockers']))
|
||||
with self.lock:
|
||||
enabled=set(self.config['enabled_profiles'])
|
||||
if data['enabled']:enabled.add(data['id'])
|
||||
if data['enabled']:
|
||||
if row['kind']=='image':enabled.difference_update(p['id'] for p in rows if p['kind']=='image')
|
||||
enabled.add(data['id'])
|
||||
else:enabled.discard(data['id'])
|
||||
self.config['enabled_profiles']=sorted(enabled);self.persist()
|
||||
return self.status()
|
||||
|
||||
Reference in New Issue
Block a user