Skip to content

Commit

Permalink
Merge pull request getredash#1847 from getredash/fix/alerts
Browse files Browse the repository at this point in the history
Fix: alert destination details were not updating.
  • Loading branch information
arikfr authored Jun 28, 2017
2 parents e1eeb67 + 24ba110 commit 2e0b930
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 20 deletions.
10 changes: 5 additions & 5 deletions redash/handlers/destinations.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
from flask_restful import abort

from redash import models
from redash.destinations import (destinations,
get_configuration_schema_for_destination_type)
from redash.handlers.base import BaseResource
from redash.permissions import require_admin
from redash.destinations import destinations, get_configuration_schema_for_destination_type
from redash.utils.configuration import ConfigurationContainer, ValidationError
from redash.handlers.base import BaseResource


class DestinationTypeListResource(BaseResource):
Expand All @@ -30,16 +31,15 @@ def post(self, destination_id):
abort(400)

try:
destination.type = req['type']
destination.name = req['name']
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']

return destination.to_dict(all=True)

@require_admin
Expand Down
23 changes: 12 additions & 11 deletions redash/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,20 @@
import logging
import time

from funcy import project

import xlsxwriter
from flask_login import AnonymousUserMixin, UserMixin
from flask_sqlalchemy import SQLAlchemy
from funcy import project
from passlib.apps import custom_app_context as pwd_context
from sqlalchemy import or_
from sqlalchemy.dialects import postgresql
from sqlalchemy.event import listens_for
from sqlalchemy.ext.mutable import Mutable
from sqlalchemy.inspection import inspect
from sqlalchemy.orm import backref, joinedload, object_session, subqueryload
from sqlalchemy.orm.exc import NoResultFound # noqa: F401
from sqlalchemy.types import TypeDecorator

from redash import redis_connection, utils
from redash.destinations import (get_configuration_schema_for_destination_type,
get_destination)
Expand All @@ -23,14 +31,6 @@
get_query_runner)
from redash.utils import generate_token, json_dumps
from redash.utils.configuration import ConfigurationContainer
from sqlalchemy import or_
from sqlalchemy.dialects import postgresql
from sqlalchemy.event import listens_for
from sqlalchemy.ext.mutable import Mutable
from sqlalchemy.inspection import inspect
from sqlalchemy.orm import backref, joinedload, object_session, subqueryload
from sqlalchemy.orm.exc import NoResultFound # noqa: F401
from sqlalchemy.types import TypeDecorator

db = SQLAlchemy(session_options={
'expire_on_commit': False
Expand Down Expand Up @@ -1481,8 +1481,9 @@ class NotificationDestination(BelongsToOrgMixin, db.Model):
user = db.relationship(User, backref="notification_destinations")
name = Column(db.String(255))
type = Column(db.String(255))
options = Column(Configuration)
options = Column(ConfigurationContainer.as_mutable(Configuration))
created_at = Column(db.DateTime(True), default=db.func.now())

__tablename__ = 'notification_destinations'
__table_args__ = (db.Index('notification_destinations_org_id_name', 'org_id',
'name', unique=True),)
Expand Down
13 changes: 9 additions & 4 deletions tests/handlers/test_destinations.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from tests import BaseTestCase

from redash.models import NotificationDestination


Expand Down Expand Up @@ -55,10 +56,14 @@ def test_post(self):
data = {
'name': 'updated',
'type': d.type,
'options': d.options.to_dict()
'options': {"url": "https://www.slack.com/updated"}
}
rv = self.make_request('post', '/api/destinations/{}'.format(d.id), user=self.factory.create_admin(), data=data)
self.assertEqual(rv.status_code, 200)
self.assertEqual(NotificationDestination.query.get(d.id).name, data['name'])

with self.app.app_context():
rv = self.make_request('post', '/api/destinations/{}'.format(d.id), user=self.factory.create_admin(), data=data)

self.assertEqual(rv.status_code, 200)

d = NotificationDestination.query.get(d.id)
self.assertEqual(d.name, data['name'])
self.assertEqual(d.options['url'], data['options']['url'])

0 comments on commit 2e0b930

Please sign in to comment.