Merged in feature/dashboard-deletion (pull request #9)

Add delete dashboard route
develop
Ensar Sarajcic 2018-10-10 20:20:00 +00:00
commit 15215c6454
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):
"""