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

Templated notifications #4291

Merged
merged 43 commits into from
Aug 27, 2019

Conversation

jladdjr
Copy link
Contributor

@jladdjr jladdjr commented Jul 9, 2019

See #79 (see notes on templated notifications)

ISSUE TYPE
  • Feature Pull Request
COMPONENT NAME
  • API
  • UI
ADDITIONAL INFORMATION

Currently a work in progress PR, but think this will be wrapped up soon.

Home stretch:

  • Show default values for messages in GET
  • White-list job fields
  • Templated notifications w/ bodies
  • Using awx to send out test notifications when the NT includes custom notifications
  • Ensure that fields are properly formatted (per how this was done previously for limited set of fields)
  • e2e tests pass

@softwarefactory-project-zuul
Copy link
Contributor

Build failed.

@jladdjr jladdjr force-pushed the templated_messages branch from 9fcb5bc to cc834b8 Compare July 9, 2019 07:17
@softwarefactory-project-zuul

This comment has been minimized.

@@ -35,6 +38,16 @@ export default ['Rest', 'Wait',
}
});

Rest.setUrl(GetBasePath('notification_templates'));

This comment was marked as resolved.

This comment was marked as resolved.

This comment was marked as resolved.

This comment was marked as resolved.

This comment was marked as resolved.

This comment was marked as resolved.

This comment was marked as resolved.

This comment was marked as resolved.

@mabashian
Copy link
Member

@keithjgrant this is probably unrelated to your changes and is pretty low priority but it looks like an error gets thrown if the user changes the notif type back to the empty state:

reset_type

I'm pretty sure this error is benign and the user isn't impacted. If this isn't a regression I'd be 👌 with creating a new low priority issue unrelated to this PR.

@mabashian
Copy link
Member

After having read through the code I think I understand why we're showing <DEFAULT_MESSAGE> to read-only users when no changes to the structure of a particular message has changed:

Screen Shot 2019-07-12 at 9 21 38 AM

The UI doesn't have access to those default message templates because they're provided in the POST section of the options response (system auditors won't have this in their response). I feel like this UX is kind of weird though. It makes it seem like there's something hidden. This may not be a huge deal but I was curious if there were any discussions around that @jladdjr.

@mabashian
Copy link
Member

Last thing I'm curious about:

Screen Shot 2019-07-12 at 9 30 31 AM

Do we actually need this checkbox? As far as I can tell it really just acts like a show/hide for those codemirrors. If the user changes the notif type then the fields in that section change. I'm sure you all probably talked about this but I'm just wondering if we need that extra click.

@keithjgrant
Copy link
Member

The UI doesn't have access to those default message templates because they're provided in the POST section of the options response (system auditors won't have this in their response). I feel like this UX is kind of weird though. It makes it seem like there's something hidden. This may not be a huge deal but I was curious if there were any discussions around that @jladdjr.

We're looking into adding the defaults onto the GET section as well, so all users can see the default values. I pushed this up as a sort of stable halfway point toward that end.

Do we actually need this checkbox?

I did this in an effort to reduce the visual noise of the form, basically hiding "advanced" options until the user needs them. These fields add a lot of length to the form, especially for e-mail notifications which also have longer body field for each notification type (started/succeeded/failed).

@jladdjr
Copy link
Contributor Author

jladdjr commented Jul 15, 2019

(keith:) We're looking into adding the defaults onto the GET section as well, so all users can see the default values. I pushed this up as a sort of stable halfway point toward that end.

Just now catching up on all the threads here. @mabashian, I mentioned this in response to one of the code comments, and @keithjgrant basically already said this, but wanted to echo that I'm working on getting the defaults posted outside of the POST section listed under the GET section (you're exactly right, btw, about the issue being that we need to move the default info outside of the POST section). My other comment has more details on some of the hurdles I'm seeing w/ moving the default info out. Tackling those hurdles now.

@jladdjr
Copy link
Contributor Author

jladdjr commented Jul 15, 2019

@keithjgrant (cc @mabashian) - I pushed a commit that surfaces the messages's default field under OPTIONS -> GET.

image

By default, we explicitly filter out default (and several other fields) under OPTIONS -> GET. So, in order to get this to work, I had to make a tweak to our framework so that we can specifically call out fields in the model that should not get dropped (the change consisted of creating a new field preserve_metadata, and adding some logic to our Metadata class that would read that field and prevent any items it saw listed from getting dropped.

While this works, I'm not sure if it's the best approach. Changing our framework feels like a pretty heavy hammer, although since we explicitly drop default under GET, I didn't really see an alternative. I'm going to run this change by the rest of the API team to see what they think. I'll be in touch with another update.

@@ -4167,6 +4167,9 @@ class NotificationTemplateSerializer(BaseSerializer):
class Meta:
model = NotificationTemplate
fields = ('*', 'organization', 'notification_type', 'notification_configuration', 'messages')
# preserve metadata for `messages` so default value can be shown for users with read-only access
preserve_metadata = {'messages': 'default'}

This comment was marked as resolved.

This comment was marked as resolved.

@jladdjr
Copy link
Contributor Author

jladdjr commented Jul 15, 2019

@keithjgrant @mabashian - the API team seems to think that what I have for exposing the messages default under OPTIONS -> GET is reasonable. There are still a couple folks that haven't weighed in, but I'm going to run with what I have for now.

Copy link
Contributor

@jbradberry jbradberry left a comment

Choose a reason for hiding this comment

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

This seems like a reasonable approach to me.

preserve_metadata = serializer.Meta.preserve_metadata
if field in preserve_metadata:
if type(preserve_metadata[field]) is str:
preserve_metadata[field] = {preserve_metadata[field]}

This comment was marked as resolved.

This comment was marked as resolved.

@mabashian
Copy link
Member

@jladdjr re: default messages in GET 👍 thanks for that!

Copy link
Member

@mabashian mabashian left a comment

Choose a reason for hiding this comment

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

UI changes lgtm. Ping @unlikelyzero I think this will be ready for your eyes soon.


from awx.api.serializers import UnifiedJobSerializer # Need to import here (To avoid circular import?)
job_serialization = UnifiedJobSerializer(self).to_representation(self) # TODO: Filter job serialization to only include whitelisted fields
context = dict(job=job_serialization,

This comment was marked as resolved.

This comment was marked as resolved.

@jladdjr jladdjr force-pushed the templated_messages branch 2 times, most recently from e7824a6 to a5182f0 Compare July 18, 2019 02:12
@jladdjr jladdjr force-pushed the templated_messages branch 2 times, most recently from d750353 to 0a83a02 Compare July 28, 2019 02:20
@jladdjr jladdjr changed the title [WIP] Templated notifications 📣 Templated notifications 📣 Jul 29, 2019
@jladdjr jladdjr force-pushed the templated_messages branch from d74ea97 to 13de642 Compare August 25, 2019 05:56
@softwarefactory-project-zuul

This comment has been minimized.

@jladdjr jladdjr force-pushed the templated_messages branch from 13de642 to 901d41e Compare August 26, 2019 06:11
@softwarefactory-project-zuul

This comment has been minimized.

@softwarefactory-project-zuul

This comment has been minimized.

@jladdjr
Copy link
Contributor Author

jladdjr commented Aug 26, 2019

@unlikelyzero @one-t - I believe everything has been addressed for notification templates. Can either of you think of anything else that needs to be addressed before we plan a merge mtg?

@jladdjr jladdjr force-pushed the templated_messages branch from 9a2a12a to 901d41e Compare August 26, 2019 13:01
@softwarefactory-project-zuul

This comment has been minimized.

@unlikelyzero
Copy link

@jladdjr just a clean yolo run. Otherwise the only open issue can be resolved post-merge
#4521

@softwarefactory-project-zuul
Copy link
Contributor

Build succeeded (gate pipeline).

@softwarefactory-project-zuul softwarefactory-project-zuul bot merged commit 534c4e7 into ansible:devel Aug 27, 2019
@jladdjr jladdjr deleted the templated_messages branch October 4, 2019 21:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.