-
Notifications
You must be signed in to change notification settings - Fork 74
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
THREESCALE-10758: Filter email notifications by service #4029
base: master
Are you sure you want to change the base?
Conversation
Please read the description and then tell me your opinion about:
|
config/abilities/provider_any.rb
Outdated
service_id = event.try(:service)&.id || event.try(:service_id) | ||
!service_id || user.has_access_to_service?(service_id) | ||
services = event.try(:services) || [event.try(:service)].compact | ||
service_ids = services.map(&:id) || [event.try(:service_id)].compact |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jlledom Have you seen any AccountRelatedEvent
that was already including service_ids
?
On the other hand, you are now adding services
property in AccountRelatedEvent
, while this seems to be the only place where it is used. And if we only need the IDs, maybe this is what we can actually pass? service_ids: some_scope.pluck(:id)
, instead of services: some_scope.to_a
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jlledom Have you seen any
AccountRelatedEvent
that was already includingservice_ids
?
No
On the other hand, you are now adding
services
property inAccountRelatedEvent
, while this seems to be the only place where it is used. And if we only need the IDs, maybe this is what we can actually pass?service_ids: some_scope.pluck(:id)
, instead ofservices: some_scope.to_a
Yeah, I'll do that.
services = event.try(:services) || [event.try(:service)].compact | ||
service_ids = services.map(&:id) || [event.try(:service_id)].compact | ||
|
||
next true if service_ids.empty? && user.admin? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if user has not subscribed to any services, then we send notification? Shouldn't we not send in fact?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could do it that way if you have a strong opinion and think it's the correct thing to do.
Anyway, old code already notified everyone for account related events that aren't connected to any service:
!service_id || user.has_access_to_service?(service_id)
If no service, return true
; otherwise, return whether the user has access to that service.
In the new code I'm restricting that to only notify admins about events not connected to services.
I think that's fine because an admin could be interested in e.g. new buyers signups even when there is no default service for them. Also, admins and all users can disable any from their notification preferences.
wrt the observer, can we move the event to |
I think Messages inbox should only be shown to the members that have "partners" permission, and in this case I believe they can see the list of all accounts, regardless of whether they have subscribed to any of the services that the member has access to (through some other permission, such as "plans"). And in this case all messages should be seen to.
Cannot we somehow preload the list of "bought contracts" in I think we are doing something similar here:
But I might be wrong... |
f5b18e1
to
c89fd0b
Compare
I rebased to solve the conflicts |
I think this is more appropriate because an application always belongs to a service
c89fd0b
to
0e2d18a
Compare
OKI
I'll take a look |
@mayorova I followed your sugestion to use only service ids: b3ff82d About
Nothing worked, because it doesn't matter if the association was cached or not, Any other ideas? |
What this PR does / why we need it:
Clients complain their inboxes are being spammed with non-relevant emails about notifications they don't care about because their users don't have permissions to manage the services the notifications are about.
We already implement a system to filter such notifications, this is how it works:
PublishNotificationEventSubscriber
:porta/app/lib/event_store/repository.rb
Lines 117 to 167 in a897958
porta/app/lib/event_store/repository.rb
Lines 186 to 188 in a897958
3. A
NotificationEvent
is created:porta/app/subscribers/publish_notification_event_subscriber.rb
Lines 12 to 18 in 25fa9bc
AFAIK nobody subscribes to it, but after being added, a
ProcessNotificationEventWorker
job is enqueued:porta/app/events/notification_event.rb
Lines 20 to 22 in 46eb05a
When performed, one
UserNotificationWorker
job is enqueued for each active user in the providerporta/app/workers/process_notification_event_worker.rb
Lines 37 to 55 in 7efaabd
For every user,
should_deliver?
is called:porta/app/workers/process_notification_event_worker.rb
Line 26 in 7efaabd
Which calls
permitted?
:porta/app/models/notification.rb
Lines 38 to 40 in 9833dc4
Which checks the permissions:
porta/app/models/notification.rb
Lines 72 to 74 in 9833dc4
The event can be
BillingRelatedEvent
,AccountRelatedEvent
orServiceRelatedEvent
.:finance
permissionservice
field in their data, and can be notified if the user has access to the service.service
field in their data or not, and can be notified if the user has access to service or the event doesn't contain a service:porta/config/abilities/provider_any.rb
Lines 30 to 41 in af8ef71
This works fine for those events that can be easily associated to a service, for instance creating an application; but some other events are not, for instance sending a message.
In particular, the client complains about:
Accounts::AccountCreatedEvent
Accounts::AccountDeletedEvent
Messages::MessageReceivedEvent
In order to fix
AccountCreatedEvent
andMessageReceivedEvent
I made some changes in the ability so it can handle multiple services rather than only one, if any of the services in the event are permitted, then the notification is sent: 0110eb1Then I added the relevant services to the events: c066485 and 1b45331
Also made all application events related to
Service
rather thanAccount
, I think it's more correct: 0eaca5eAbout
AccountDeletedEvent
we have a problem here. The event is created from an observer:porta/app/observers/account_observer.rb
Lines 34 to 37 in 25fa9bc
But the received
account
is already deleted and not persisted, so itsbought_service_contracts
association is empty and we can't get the service subscriptions. Maybe the correspondingServiceContract
records still exist in DB at this point and can be retrieved, but I think that's error prone so I didn't even try.For that reason I couldn't implement the filtering for this kind of event.
Which issue(s) this PR fixes
https://issues.redhat.com/browse/THREESCALE-10758
https://issues.redhat.com/browse/THREESCALE-8720