uprawnienia do stacji i usuwanie firm
This commit is contained in:
+33
@@ -303,6 +303,39 @@ def create_fuel_card():
|
||||
def update_fuel_card(card_id):
|
||||
card=FuelCard.query.get_or_404(card_id);d=payload();card.name=d.get('name',card.name).strip();card.provider=d.get('provider',card.provider).strip();card.description=(d.get('description') or '').strip() or None;card.active=boolv(d,'active');db.session.commit();return response(message='Zapisano kartę')
|
||||
|
||||
@api.delete('/fuel-cards/<int:card_id>')
|
||||
@role_required('boss','admin')
|
||||
def delete_fuel_card(card_id):
|
||||
card = FuelCard.query.get_or_404(card_id)
|
||||
if current_user.role == 'boss' and card.company_id != current_user.company_id:
|
||||
return fail('Brak uprawnień', 403)
|
||||
|
||||
users_count = User.query.filter_by(fuel_card_id=card.id).count()
|
||||
vehicles_count = Vehicle.query.filter_by(fuel_card_id=card.id).count()
|
||||
entries_count = FuelEntry.query.filter_by(fuel_card_id=card.id).count()
|
||||
blockers = []
|
||||
if users_count:
|
||||
blockers.append(f'{users_count} użytkowników')
|
||||
if vehicles_count:
|
||||
blockers.append(f'{vehicles_count} pojazdów')
|
||||
if entries_count:
|
||||
blockers.append(f'{entries_count} tankowań')
|
||||
if blockers:
|
||||
return fail(
|
||||
'Nie można usunąć karty, ponieważ jest przypisana do: ' + ', '.join(blockers) +
|
||||
'. Najpierw odłącz kartę od użytkowników i pojazdów. Karty użytej w tankowaniach nie można usunąć; możesz ją wyłączyć.',
|
||||
409,
|
||||
)
|
||||
|
||||
company_id = card.company_id
|
||||
db.session.delete(card)
|
||||
db.session.commit()
|
||||
socketio.emit('app_changed', {'resource':'fuel_cards', 'deleted_id':card_id})
|
||||
return response(
|
||||
{'redirect':url_for('main.admin_companies', company_id=company_id)},
|
||||
'Usunięto kartę flotową',
|
||||
)
|
||||
|
||||
@api.put('/fuel-cards/<int:card_id>/stations/<int:station_id>')
|
||||
@role_required('boss','admin')
|
||||
def update_card_station_rule(card_id,station_id):
|
||||
|
||||
Reference in New Issue
Block a user