mirror of
https://github.com/valitydev/redash.git
synced 2024-11-08 09:53:59 +00:00
Merge pull request #1493 from washort/more-commits
Fix: more `db.commit()` calls
This commit is contained in:
commit
7d8b8a16fd
@ -21,6 +21,7 @@ class AlertResource(BaseResource):
|
||||
require_admin_or_owner(alert.user.id)
|
||||
|
||||
self.update_model(alert, params)
|
||||
models.db.session.commit()
|
||||
|
||||
self.record_event({
|
||||
'action': 'edit',
|
||||
@ -57,6 +58,8 @@ class AlertListResource(BaseResource):
|
||||
|
||||
models.db.session.add(alert)
|
||||
models.db.session.flush()
|
||||
models.db.session.commit()
|
||||
|
||||
self.record_event({
|
||||
'action': 'create',
|
||||
'timestamp': int(time.time()),
|
||||
@ -64,9 +67,7 @@ class AlertListResource(BaseResource):
|
||||
'object_type': 'alert'
|
||||
})
|
||||
|
||||
a = alert.to_dict()
|
||||
models.db.session.commit()
|
||||
return a
|
||||
return alert.to_dict()
|
||||
|
||||
@require_permission('list_alerts')
|
||||
def get(self):
|
||||
@ -87,6 +88,8 @@ class AlertSubscriptionListResource(BaseResource):
|
||||
|
||||
subscription = models.AlertSubscription(**kwargs)
|
||||
models.db.session.add(subscription)
|
||||
models.db.session.commit()
|
||||
|
||||
self.record_event({
|
||||
'action': 'subscribe',
|
||||
'timestamp': int(time.time()),
|
||||
@ -96,7 +99,6 @@ class AlertSubscriptionListResource(BaseResource):
|
||||
})
|
||||
|
||||
d = subscription.to_dict()
|
||||
models.db.session.commit()
|
||||
return d
|
||||
|
||||
def get(self, alert_id):
|
||||
@ -113,10 +115,11 @@ class AlertSubscriptionResource(BaseResource):
|
||||
subscription = models.AlertSubscription.query.get_or_404(subscriber_id)
|
||||
require_admin_or_owner(subscription.user.id)
|
||||
models.db.session.delete(subscription)
|
||||
models.db.session.commit()
|
||||
|
||||
self.record_event({
|
||||
'action': 'unsubscribe',
|
||||
'timestamp': int(time.time()),
|
||||
'object_id': alert_id,
|
||||
'object_type': 'alert'
|
||||
})
|
||||
models.db.session.commit()
|
||||
|
@ -66,7 +66,6 @@ class DashboardResource(BaseResource):
|
||||
|
||||
require_object_modify_permission(dashboard, self.current_user)
|
||||
|
||||
|
||||
updates = project(dashboard_properties, ('name', 'layout', 'version',
|
||||
'is_draft'))
|
||||
|
||||
@ -116,6 +115,8 @@ class DashboardShareResource(BaseResource):
|
||||
require_admin_or_owner(dashboard.user_id)
|
||||
api_key = models.ApiKey.create_for_object(dashboard, self.current_user)
|
||||
models.db.session.flush()
|
||||
models.db.session.commit()
|
||||
|
||||
public_url = url_for('redash.public_dashboard', token=api_key.api_key, org_slug=self.current_org.slug, _external=True)
|
||||
|
||||
self.record_event({
|
||||
@ -134,10 +135,10 @@ class DashboardShareResource(BaseResource):
|
||||
if api_key:
|
||||
api_key.active = False
|
||||
models.db.session.add(api_key)
|
||||
models.db.session.commit()
|
||||
|
||||
self.record_event({
|
||||
'action': 'deactivate_api_key',
|
||||
'object_id': dashboard.id,
|
||||
'object_type': 'dashboard',
|
||||
})
|
||||
models.db.session.commit()
|
||||
|
@ -127,30 +127,24 @@ class DataSourcePauseResource(BaseResource):
|
||||
reason = request.args.get('reason')
|
||||
|
||||
data_source.pause(reason)
|
||||
models.db.session.add(data_source)
|
||||
models.db.session.commit()
|
||||
|
||||
self.record_event({
|
||||
'action': 'pause',
|
||||
'object_id': data_source.id,
|
||||
'object_type': 'datasource'
|
||||
})
|
||||
|
||||
return data_source.to_dict()
|
||||
|
||||
@require_admin
|
||||
def delete(self, data_source_id):
|
||||
data_source = get_object_or_404(models.DataSource.get_by_id_and_org, data_source_id, self.current_org)
|
||||
data_source.resume()
|
||||
models.db.session.add(data_source)
|
||||
models.db.session.commit()
|
||||
|
||||
self.record_event({
|
||||
'action': 'resume',
|
||||
'object_id': data_source.id,
|
||||
'object_type': 'datasource'
|
||||
})
|
||||
|
||||
return data_source.to_dict()
|
||||
|
||||
|
||||
|
@ -32,14 +32,14 @@ class DestinationResource(BaseResource):
|
||||
try:
|
||||
destination.options.set_schema(schema)
|
||||
destination.options.update(req['options'])
|
||||
models.db.session.add(destination)
|
||||
models.db.session.commit()
|
||||
except ValidationError:
|
||||
abort(400)
|
||||
|
||||
destination.type = req['type']
|
||||
destination.name = req['name']
|
||||
|
||||
models.db.session.add(destination)
|
||||
|
||||
return destination.to_dict(all=True)
|
||||
|
||||
@require_admin
|
||||
@ -88,5 +88,5 @@ class DestinationListResource(BaseResource):
|
||||
user=self.current_user)
|
||||
|
||||
models.db.session.add(destination)
|
||||
|
||||
models.db.session.commit()
|
||||
return destination.to_dict(all=True)
|
||||
|
@ -57,6 +57,7 @@ def run_query_sync(data_source, parameter_values, query_text, max_age=0):
|
||||
query_hash, query_text, data,
|
||||
run_time, utils.utcnow())
|
||||
|
||||
models.db.session.commit()
|
||||
return data
|
||||
except Exception, e:
|
||||
if max_age > 0:
|
||||
@ -79,6 +80,7 @@ def embed(query_id, visualization_id, org_slug=None):
|
||||
})
|
||||
|
||||
full_path = safe_join(settings.STATIC_ASSETS_PATHS[-2], 'index.html')
|
||||
models.db.session.commit()
|
||||
return send_file(full_path, **dict(cache_timeout=0, conditional=True))
|
||||
|
||||
|
||||
@ -94,6 +96,6 @@ def public_dashboard(token, org_slug=None):
|
||||
# 'headless': 'embed' in request.args,
|
||||
# 'referer': request.headers.get('Referer')
|
||||
# })
|
||||
|
||||
# models.db.session.commit()
|
||||
full_path = safe_join(settings.STATIC_ASSETS_PATHS[-2], 'index.html')
|
||||
return send_file(full_path, **dict(cache_timeout=0, conditional=True))
|
||||
|
@ -9,4 +9,3 @@ class EventResource(BaseResource):
|
||||
for event in events_list:
|
||||
self.record_event(event)
|
||||
|
||||
|
||||
|
@ -42,6 +42,7 @@ class GroupResource(BaseResource):
|
||||
abort(400, message="Can't modify built-in groups.")
|
||||
|
||||
group.name = request.json['name']
|
||||
models.db.session.commit()
|
||||
|
||||
self.record_event({
|
||||
'action': 'edit',
|
||||
@ -77,7 +78,6 @@ class GroupMemberListResource(BaseResource):
|
||||
user = models.User.get_by_id_and_org(user_id, self.current_org)
|
||||
group = models.Group.get_by_id_and_org(group_id, self.current_org)
|
||||
user.group_ids.append(group.id)
|
||||
|
||||
models.db.session.commit()
|
||||
|
||||
self.record_event({
|
||||
@ -87,7 +87,6 @@ class GroupMemberListResource(BaseResource):
|
||||
'object_type': 'group',
|
||||
'member_id': user.id
|
||||
})
|
||||
|
||||
return user.to_dict()
|
||||
|
||||
@require_permission('list_users')
|
||||
@ -104,7 +103,6 @@ class GroupMemberResource(BaseResource):
|
||||
def delete(self, group_id, user_id):
|
||||
user = models.User.get_by_id_and_org(user_id, self.current_org)
|
||||
user.group_ids.remove(int(group_id))
|
||||
|
||||
models.db.session.commit()
|
||||
|
||||
self.record_event({
|
||||
@ -130,7 +128,6 @@ class GroupDataSourceListResource(BaseResource):
|
||||
group = models.Group.get_by_id_and_org(group_id, self.current_org)
|
||||
|
||||
data_source_group = data_source.add_group(group)
|
||||
|
||||
models.db.session.commit()
|
||||
|
||||
self.record_event({
|
||||
@ -164,7 +161,6 @@ class GroupDataSourceResource(BaseResource):
|
||||
view_only = request.json['view_only']
|
||||
|
||||
data_source_group = data_source.update_group_permission(group, view_only)
|
||||
|
||||
models.db.session.commit()
|
||||
|
||||
self.record_event({
|
||||
@ -184,6 +180,7 @@ class GroupDataSourceResource(BaseResource):
|
||||
group = models.Group.get_by_id_and_org(group_id, self.current_org)
|
||||
|
||||
data_source.remove_group(group)
|
||||
models.db.session.commit()
|
||||
|
||||
self.record_event({
|
||||
'action': 'remove_data_source',
|
||||
|
@ -55,13 +55,14 @@ class ObjectPermissionsListResource(BaseResource):
|
||||
abort(400, message='User not found.')
|
||||
|
||||
permission = AccessPermission.grant(obj, access_type, grantee, self.current_user)
|
||||
db.session.commit()
|
||||
|
||||
self.record_event({
|
||||
'action': 'grant_permission',
|
||||
'object_id': object_id,
|
||||
'object_type': object_type,
|
||||
'grantee': grantee.id,
|
||||
'access_type': access_type,
|
||||
'grantee': grantee.id
|
||||
})
|
||||
|
||||
return permission.to_dict()
|
||||
@ -80,7 +81,9 @@ class ObjectPermissionsListResource(BaseResource):
|
||||
grantee = User.query.get(req['user_id'])
|
||||
if grantee is None:
|
||||
abort(400, message='User not found.')
|
||||
|
||||
AccessPermission.revoke(obj, grantee, access_type)
|
||||
db.session.commit()
|
||||
|
||||
self.record_event({
|
||||
'action': 'revoke_permission',
|
||||
@ -89,7 +92,6 @@ class ObjectPermissionsListResource(BaseResource):
|
||||
'access_type': access_type,
|
||||
'grantee_id': grantee_id
|
||||
})
|
||||
db.session.commit()
|
||||
|
||||
|
||||
class CheckPermissionResource(BaseResource):
|
||||
|
@ -121,8 +121,7 @@ class QueryResource(BaseResource):
|
||||
except StaleDataError:
|
||||
abort(409)
|
||||
|
||||
result = query.to_dict(with_visualizations=True)
|
||||
return result
|
||||
return query.to_dict(with_visualizations=True)
|
||||
|
||||
@require_permission('view_query')
|
||||
def get(self, query_id):
|
||||
@ -138,6 +137,7 @@ class QueryResource(BaseResource):
|
||||
query = get_object_or_404(models.Query.get_by_id_and_org, query_id, self.current_org)
|
||||
require_admin_or_owner(query.user_id)
|
||||
query.archive(self.current_user)
|
||||
models.db.session.commit()
|
||||
|
||||
|
||||
class QueryForkResource(BaseResource):
|
||||
@ -145,6 +145,7 @@ class QueryForkResource(BaseResource):
|
||||
def post(self, query_id):
|
||||
query = get_object_or_404(models.Query.get_by_id_and_org, query_id, self.current_org)
|
||||
forked_query = query.fork(self.current_user)
|
||||
models.db.session.commit()
|
||||
return forked_query.to_dict(with_visualizations=True)
|
||||
|
||||
|
||||
|
@ -71,7 +71,6 @@ class QueryResultListResource(BaseResource):
|
||||
'object_type': 'data_source',
|
||||
'query': query
|
||||
})
|
||||
|
||||
return run_query(data_source, parameter_values, query, query_id, max_age)
|
||||
|
||||
|
||||
|
@ -21,13 +21,13 @@ class QuerySnippetResource(BaseResource):
|
||||
require_admin_or_owner(snippet.user.id)
|
||||
|
||||
self.update_model(snippet, params)
|
||||
models.db.session.commit()
|
||||
|
||||
self.record_event({
|
||||
'action': 'edit',
|
||||
'object_id': snippet.id,
|
||||
'object_type': 'query_snippet'
|
||||
})
|
||||
models.db.session.commit()
|
||||
return snippet.to_dict()
|
||||
|
||||
def delete(self, snippet_id):
|
||||
@ -58,13 +58,14 @@ class QuerySnippetListResource(BaseResource):
|
||||
)
|
||||
|
||||
models.db.session.add(snippet)
|
||||
models.db.session.commit()
|
||||
|
||||
self.record_event({
|
||||
'action': 'create',
|
||||
'object_id': snippet.id,
|
||||
'object_type': 'query_snippet'
|
||||
})
|
||||
models.db.session.commit()
|
||||
|
||||
return snippet.to_dict()
|
||||
|
||||
def get(self):
|
||||
|
@ -110,7 +110,7 @@ class UserResource(BaseResource):
|
||||
|
||||
try:
|
||||
self.update_model(user, params)
|
||||
# TODO: this won't be triggered at this point. Need to call db.session.commit?
|
||||
models.db.session.commit()
|
||||
except IntegrityError as e:
|
||||
if "email" in e.message:
|
||||
message = "Email already taken."
|
||||
|
@ -49,7 +49,7 @@ class WidgetListResource(BaseResource):
|
||||
|
||||
widget.dashboard.layout = json.dumps(layout)
|
||||
models.db.session.add(widget.dashboard)
|
||||
|
||||
models.db.session.commit()
|
||||
return {'widget': widget.to_dict(), 'layout': layout, 'new_row': new_row, 'version': dashboard.version}
|
||||
|
||||
|
||||
@ -61,14 +61,13 @@ class WidgetResource(BaseResource):
|
||||
require_object_modify_permission(widget.dashboard, self.current_user)
|
||||
widget_properties = request.get_json(force=True)
|
||||
widget.text = widget_properties['text']
|
||||
|
||||
models.db.session.commit()
|
||||
return widget.to_dict()
|
||||
|
||||
@require_permission('edit_dashboard')
|
||||
def delete(self, widget_id):
|
||||
widget = models.Widget.get_by_id_and_org(widget_id, self.current_org)
|
||||
require_object_modify_permission(widget.dashboard, self.current_user)
|
||||
|
||||
widget.delete()
|
||||
|
||||
models.db.session.commit()
|
||||
return {'layout': widget.dashboard.layout, 'version': widget.dashboard.version}
|
||||
|
@ -13,6 +13,7 @@ logger = get_task_logger(__name__)
|
||||
def record_event(event):
|
||||
original_event = event.copy()
|
||||
models.Event.record(event)
|
||||
models.db.session.commit()
|
||||
for hook in settings.EVENT_REPORTING_WEBHOOKS:
|
||||
logger.debug("Forwarding event to: %s", hook)
|
||||
try:
|
||||
|
Loading…
Reference in New Issue
Block a user