Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Alert redesign #4 - custom notification template #4170

Merged
merged 12 commits into from
Oct 5, 2019

Conversation

ranbena
Copy link
Contributor

@ranbena ranbena commented Sep 22, 2019

  • Refactor
  • Feature

Description

Adds the previously hidden feature of custom subject/body (#3137) for alert notifications.

Now added to Alert edit mode:

Screen Shot 2019-09-23 at 7 17 33

Screen Shot 2019-09-23 at 7 19 26

Switched to preview mode:

Screen Shot 2019-09-23 at 7 19 42

And in Alert page view mode:

Screen Shot 2019-09-23 at 7 17 48

How it looks on webmail:

Screen Shot 2019-09-24 at 11 36 41

How it looks on slack:

Screen Shot 2019-09-24 at 11 50 06

@ranbena ranbena changed the title Added custom notification templating Alert redesign #4 - custom notification template Sep 23, 2019
@ranbena
Copy link
Contributor Author

ranbena commented Sep 23, 2019

@arikfr @rauchy I'd like to test the python changes to templating in this PR - for instance, get an email alert notification to mail or slack. Is that possible?

@ranbena ranbena self-assigned this Sep 23, 2019
Copy link
Member

@arikfr arikfr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know it's a draft, but noticed a few things while reading.

redash/models/__init__.py Outdated Show resolved Hide resolved
redash/models/__init__.py Outdated Show resolved Hide resolved
redash/models/__init__.py Outdated Show resolved Hide resolved
@arikfr
Copy link
Member

arikfr commented Sep 23, 2019

Is that possible?

Locally?

@ranbena
Copy link
Contributor Author

ranbena commented Sep 23, 2019

Locally?

Yes. If not, maybe in deploy preview somehow?

@rauchy
Copy link
Contributor

rauchy commented Sep 23, 2019

Is that possible?

@ranbena #4173 will help you with this.

@ranbena ranbena changed the base branch from alert-1 to alert-3-dialog September 24, 2019 08:55
@ranbena ranbena marked this pull request as ready for review September 24, 2019 09:11
def template(self):
return self.options.get('template', '')
def custom_body(self):
return self.render_template(self.options['custom_body'])
Copy link
Collaborator

@kravets-levko kravets-levko Sep 24, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could it be an issue in terms of backward compatibility (replacing template option with custom_body - and for subject as well - what if somebody already has saved alerts with template option)?

Also - shouldn't it be self.options.get('custom_body', '') as before?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could it be an issue in terms of backward compatibility

There are several backward incompatible changes in here (like the template variables). Because it's hidden behind a feature flag, I doubt many people use it.

But to be friendlier to them I suggest we keep the option name as template? As for the variables, we will document the change in the release notes.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could it be an issue in terms of backward compatibility

This feature was off since it landed, so I'm assuming that chances are slim that someone changed clientConfig.extendedAlertOptions apart for the original author @k-tomoyasu.

Maybe I can do this?:

# backwards compatibility
def template(self):
  return self.custom_body;

Also - shouldn't it be self.options.get('custom_body', '') as before?

render_template() now returns '' if custom_body us empty. Don't think it's enough?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

custom_body feels a better name for this option than template - so if you think it's not an issue - I'd prefer new names as well.

About template variables: do we introduce them (or some new ones), or rename/remove some existing?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

About template variables: do we introduce them (or some new ones), or rename/remove some existing?

I renamed the original 3:

const view = {
state: alert.state,
rows: queryResult.rows,
cols: queryResult.columns,
};

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

render_template() now returns '' if custom_body us empty. Don't think it's enough?

I think @kravets-levko was referring to the case when self.options doesn't have the custom_body key (every existing alert). I address this in my example below. If you access self.options['custom_body'] (or custom_subject) elsewhere in the code, you need to add similar treatment.

Maybe I can do this?:

This won't help. What might happen is that a user will have an existing alert object with the template key in options, while you look for custom_body. To make it backward compatible you can change the custom_body property method into something like:

 def custom_body(self):
        template = self.options.get('custom_body', self.options.get('template'))
        return self.render_template(template)

This will look in the custom_body key but if not found will give a try at looking in template. If not found it will return None, so you need to update render_template as well (to return empty if it's None).

Btw, shouldn't the configuration key be custom_body_template?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@arikfr does this suffice? 5f8634a

redash/models/__init__.py Outdated Show resolved Hide resolved
redash/models/__init__.py Outdated Show resolved Hide resolved
ranbena and others added 2 commits September 26, 2019 14:36
Co-Authored-By: Arik Fraimovich <arik@arikfr.com>
Co-Authored-By: Arik Fraimovich <arik@arikfr.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants