Add delete dashboard route

develop
esensar 2018-10-10 22:19:13 +02:00
parent 1a9cb3f973
commit d22c8a8ef4
4 changed files with 40 additions and 0 deletions

View File

@ -35,6 +35,15 @@ class DashboardResource(ProtectedResource):
if success:
return '', 204
@swag_from('swagger/delete_dashboard_spec.yaml')
def delete(self, dashboard_id):
requested_dashboard = dashboard.get_dashboard(dashboard_id)
if requested_dashboard.account_id != g.current_account.id:
abort(403, message='You are not allowed to access this dashboard',
status='error')
dashboard.delete_dashboard(dashboard_id)
return '', 204
class DashboardListResource(ProtectedResource):
@use_args(DashboardSchema(), locations=('json',))

View File

@ -0,0 +1,13 @@
Deletes a dashboard
---
tags:
- Dashboard
parameters:
- in: path
name: dashboard_id
required: true
type: integer
description: Id of the dashboard
responses:
204:
description: Success

View File

@ -43,6 +43,17 @@ def update_dashboard(dashboard_id, dashboard_data):
dashboard.save()
def delete_dashboard(dashboard_id):
"""
Tries to delete dashboard with given id
:param dashboard_id: Id of requested dashboard
:type name: int
"""
dashboard = Dashboard.get(id=dashboard_id)
dashboard.delete()
def get_dashboards(account_id):
"""
Tries to fetch dashboards owned by account with given id

View File

@ -29,6 +29,13 @@ class Dashboard(db.Model):
db.session.add(self)
db.session.commit()
def delete(self):
"""
Deletes this dashboard from database
"""
db.session.delete(self)
db.session.commit()
@staticmethod
def exists_with_any_of(**kwargs):
"""