mirror of
https://github.com/valitydev/redash.git
synced 2024-11-07 01:25:16 +00:00
Return 409 when dashboard can't be updated due to conflict
This commit is contained in:
parent
40cc592591
commit
f34471ec10
@ -1,13 +1,13 @@
|
||||
from flask import request, url_for
|
||||
from flask_restful import abort
|
||||
|
||||
from funcy import distinct, take
|
||||
from funcy import distinct, take, project
|
||||
from itertools import chain
|
||||
|
||||
from redash import models
|
||||
from redash.models import ConflictDetectedError
|
||||
from redash.permissions import require_permission, require_admin_or_owner, require_object_modify_permission
|
||||
from redash.handlers.base import BaseResource, get_object_or_404
|
||||
import redash.permissions
|
||||
|
||||
|
||||
class RecentDashboardsResource(BaseResource):
|
||||
@ -64,11 +64,14 @@ class DashboardResource(BaseResource):
|
||||
require_object_modify_permission(dashboard, self.current_user)
|
||||
|
||||
# old_dashboard = {'name': dashboard.name, 'layout': dashboard.layout}
|
||||
dashboard.layout = dashboard_properties['layout']
|
||||
dashboard.name = dashboard_properties['name']
|
||||
# new_change = dashboard.tracked_save(changing_user=self.current_user, old_object=old_dashboard)
|
||||
|
||||
dashboard.save()
|
||||
updates = project(dashboard_properties, ('name', 'layout', 'version'))
|
||||
|
||||
try:
|
||||
dashboard.update_instance(**updates)
|
||||
except ConflictDetectedError:
|
||||
abort(409)
|
||||
|
||||
result = dashboard.to_dict(with_widgets=True, user=self.current_user)
|
||||
return result
|
||||
|
@ -1,9 +1,10 @@
|
||||
import json
|
||||
from tests import BaseTestCase
|
||||
from redash.models import ApiKey, Dashboard ,AccessPermission
|
||||
from redash.models import ApiKey, Dashboard, AccessPermission
|
||||
from redash.permissions import ACCESS_TYPE_MODIFY
|
||||
|
||||
|
||||
class TestDasboardListResource(BaseTestCase):
|
||||
class TestDashboardListResource(BaseTestCase):
|
||||
def test_create_new_dashboard(self):
|
||||
dashboard_name = 'Test Dashboard'
|
||||
rv = self.make_request('post', '/api/dashboards', data={'name': dashboard_name})
|
||||
@ -87,10 +88,9 @@ class TestDashboardResourcePost(BaseTestCase):
|
||||
self.assertEqual(rv.status_code, 403)
|
||||
|
||||
AccessPermission.grant_permission(object_type='Dashboard',
|
||||
object_id=dashboard.id, access_type=ACCESS_TYPE_MODIFY,
|
||||
object_id=d.id, access_type=ACCESS_TYPE_MODIFY,
|
||||
grantee=user, grantor=d.user)
|
||||
|
||||
|
||||
rv = self.make_request('post', '/api/dashboards/{0}'.format(d.id),
|
||||
data={'name': new_name, 'layout': '[]', 'version': d.version}, user=user)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user