mirror of
https://github.com/valitydev/redash.git
synced 2024-11-08 18:03:54 +00:00
Enforce AlertSubscription uniqueness; update AlertSubscription delete handler
This commit is contained in:
parent
3cfbb9855b
commit
82b7146216
@ -106,8 +106,10 @@ class AlertSubscriptionListResource(BaseResource):
|
||||
|
||||
class AlertSubscriptionResource(BaseResource):
|
||||
def delete(self, alert_id, subscriber_id):
|
||||
models.AlertSubscription.unsubscribe(alert_id, subscriber_id)
|
||||
require_admin_or_owner(subscriber_id)
|
||||
|
||||
subscription = get_object_or_404(models.AlertSubscription.get_by_id, subscriber_id)
|
||||
require_admin_or_owner(subscription.id)
|
||||
subscription.delete_instance()
|
||||
|
||||
self.record_event({
|
||||
'action': 'unsubscribe',
|
||||
|
@ -1105,8 +1105,13 @@ class AlertSubscription(ModelTimestampsMixin, BaseModel):
|
||||
class Meta:
|
||||
db_table = 'alert_subscriptions'
|
||||
|
||||
indexes = (
|
||||
(('destination', 'alert'), True),
|
||||
)
|
||||
|
||||
def to_dict(self):
|
||||
d = {
|
||||
'id': self.id,
|
||||
'user': self.user.to_dict(),
|
||||
'alert_id': self.alert_id
|
||||
}
|
||||
@ -1120,11 +1125,6 @@ class AlertSubscription(ModelTimestampsMixin, BaseModel):
|
||||
def all(cls, alert_id):
|
||||
return AlertSubscription.select(AlertSubscription, User).join(User).where(AlertSubscription.alert==alert_id)
|
||||
|
||||
@classmethod
|
||||
def unsubscribe(cls, alert_id, user_id):
|
||||
query = AlertSubscription.delete().where(AlertSubscription.alert==alert_id).where(AlertSubscription.user==user_id)
|
||||
return query.execute()
|
||||
|
||||
|
||||
all_models = (Organization, Group, DataSource, DataSourceGroup, User, QueryResult, Query, Alert, Dashboard, Visualization, Widget, Event, NotificationDestination, AlertSubscription)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user