uprawnienia do stacji i usuwanie firm

This commit is contained in:
Mateusz Gruszczyński
2026-07-13 16:12:06 +02:00
parent 3b2effbe05
commit 85e7537c10
2 changed files with 8 additions and 4 deletions
+7 -3
View File
@@ -371,15 +371,19 @@ def stations_sync():
@api.put('/stations/<int:station_id>')
@role_required('boss','admin')
def update_station(station_id):
s=FuelStationCompany.query.get_or_404(station_id);d=payload();region=(d.get('selected_region') or '').strip().lower()
if region and region not in s.region_list:return fail('Wybrane województwo nie występuje w danych tej firmy')
s=FuelStationCompany.query.get_or_404(station_id);d=payload()
region=None
if 'selected_region' in d:
region=(d.get('selected_region') or '').strip().lower()
if region and region not in s.region_list:return fail('Wybrane województwo nie występuje w danych tej firmy')
try:
company_id=int(d.get('company_id') or current_user.company_id or 0)
except (TypeError,ValueError):
return fail('Nieprawidłowa firma')
settings=CompanySettings.query.get_or_404(company_id)
if current_user.role=='boss' and current_user.company_id!=settings.id:return fail('Brak uprawnień',403)
s.selected_region=region;s.active=boolv(d,'active');allowed=boolv(d,'allowed')
if region is not None: s.selected_region=region
s.active=boolv(d,'active');allowed=boolv(d,'allowed')
if allowed and s not in settings.allowed_stations: settings.allowed_stations.append(s)
if not allowed and s in settings.allowed_stations: settings.allowed_stations.remove(s)
db.session.commit();socketio.emit('app_changed',{'resource':'stations','company_id':settings.id});return response(station_dict(s),f'Zapisano ustawienia stacji dla firmy {settings.name}')