commit
15215c6454
|
@ -35,6 +35,15 @@ class DashboardResource(ProtectedResource):
|
||||||
if success:
|
if success:
|
||||||
return '', 204
|
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):
|
class DashboardListResource(ProtectedResource):
|
||||||
@use_args(DashboardSchema(), locations=('json',))
|
@use_args(DashboardSchema(), locations=('json',))
|
||||||
|
|
|
@ -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
|
|
@ -43,6 +43,17 @@ def update_dashboard(dashboard_id, dashboard_data):
|
||||||
dashboard.save()
|
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):
|
def get_dashboards(account_id):
|
||||||
"""
|
"""
|
||||||
Tries to fetch dashboards owned by account with given id
|
Tries to fetch dashboards owned by account with given id
|
||||||
|
|
|
@ -29,6 +29,13 @@ class Dashboard(db.Model):
|
||||||
db.session.add(self)
|
db.session.add(self)
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
|
|
||||||
|
def delete(self):
|
||||||
|
"""
|
||||||
|
Deletes this dashboard from database
|
||||||
|
"""
|
||||||
|
db.session.delete(self)
|
||||||
|
db.session.commit()
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def exists_with_any_of(**kwargs):
|
def exists_with_any_of(**kwargs):
|
||||||
"""
|
"""
|
||||||
|
|
Loading…
Reference in New Issue