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

Send link with the text_bindings in notifications when link_to is set #17913

Merged
merged 1 commit into from
Aug 29, 2018

Conversation

skateman
Copy link
Member

@skateman skateman commented Aug 28, 2018

Each notification can have a subject, initiator and a cause relation. Each of these are polymorphic and can point to a given entity. When displaying a notification, we would like to have a View details link that could redirect to one of these entities. This can be specified at the notification type declaration by setting the link_to parameter.

Based on this parameter I adjusted the text_bindings to have at most a single link attribute if the link_to is set properly to one of the possible values.

Related issue: ManageIQ/manageiq-v2v#578
Depends on: ManageIQ/manageiq-schema#263
UI part: ManageIQ/manageiq-ui-classic#4492

@miq-bot add_label gaprindashvili/no

result[key] = {
:link => {
Copy link
Member

Choose a reason for hiding this comment

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

I think this is okay, but I just wanted to call out what looks like a slight change in behavior.

Because you are moving which key to link to to the notification type, the :link key is getting moved up as a sibling to the relation keys.

Prior to this change it was possible to set a link for each of :initiator, :subject and, :cause, but now we can only set it to one as determined by the notification type.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yup, the design here was for up to 3 links for a notification with the links in the notification text itself, however, UX designed the visual part differently so only one link is allowed.

@@ -9,6 +9,7 @@ class NotificationType < ApplicationRecord
has_many :notifications
validates :message, :presence => true
validates :level, :inclusion => { :in => %w(success error warning info) }
validates :link_to, :inclusion => { :in => %w(subject initiator cause) }
Copy link
Member

Choose a reason for hiding this comment

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

Should we add a value to :link_to for each type to the notification_type fixture? Also does this need to be set in a migration for existing types?

Copy link
Member Author

Choose a reason for hiding this comment

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

@carbonin only if you need links for those notifications, it's perfectly fine if the link_to is not set, we were never using links in notifications before.

Copy link
Member

Choose a reason for hiding this comment

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

Okay, I think this needs :allow_blank => true then.

Copy link
Member

Choose a reason for hiding this comment

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

Specs should be fixed after adding the allow_blank from the previous comment.

@carbonin
Copy link
Member

@skateman looks like the spec is failing on the old link behavior, can you update it to describe how things should be working after your change?

@skateman
Copy link
Member Author

@carbonin I'm on it!

@skateman skateman force-pushed the notification-links branch 2 times, most recently from 1380a3a to aebaa1b Compare August 29, 2018 14:37
end

it 'contains the link to the initiator' do
expect(notification.to_h).to include(:bindings => a_hash_including(:link => a_hash_including(:model, :id)))
Copy link
Member

Choose a reason for hiding this comment

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

Couldn't this match the user more specifically? I figure it makes the expectation that the user object originally passed in the initiator field should match the one in the link.

Maybe something like this:
expect(notification.to_h).to include(:bindings => a_hash_including(:link => {:model => "user", :id => user.id}))

@miq-bot
Copy link
Member

miq-bot commented Aug 29, 2018

Checked commit skateman@c28d11c with ruby 2.3.3, rubocop 0.52.1, haml-lint 0.20.0, and yamllint 1.10.0
3 files checked, 1 offense detected

app/models/notification.rb

@carbonin carbonin merged commit aaaae91 into ManageIQ:master Aug 29, 2018
@carbonin carbonin added this to the Sprint 94 Ending Sept 10, 2018 milestone Aug 29, 2018
@skateman skateman deleted the notification-links branch August 29, 2018 19:46
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.

3 participants