uprawnienia do stacji i usuwanie firm
This commit is contained in:
+7
-3
@@ -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}')
|
||||
|
||||
Reference in New Issue
Block a user