Bug 1463962

Summary: Email notification - Sync errata - email should be send to only those users who belongs/access to the organization.
Product: Red Hat Satellite Reporter: Ranjan Kumar <rankumar>
Component: EmailAssignee: satellite6-bugs <satellite6-bugs>
Status: CLOSED ERRATA QA Contact: Sanket Jagtap <sjagtap>
Severity: high Docs Contact:
Priority: high    
Version: 6.2.9CC: aagrawal, bkearney, jcallaha, okhatavk, rhbgs.10.bigi_gigi, sjagtap
Target Milestone: 6.4.0Keywords: Triaged
Target Release: Unused   
Hardware: x86_64   
OS: Unspecified   
Whiteboard:
Fixed In Version: Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2018-10-16 19:01:07 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Bug Depends On: 1592879    
Bug Blocks:    

Description Ranjan Kumar 2017-06-22 07:12:03 UTC
Description of problem:
If a user subscribes to "Sync errata" notification mails, he gets mails for every repository in the system, also mail related to repos in organizations he does not have access. For 15 organization this means 14 times the number of repos unwanted, disturbing, obscuring spam.

Version-Release number of selected component (if applicable):


How reproducible: Always


Steps to Reproduce:
1. Create User "User-A" for Organization A and of for syn errata email 
 [root@dhcp6-10 ~]# hammer user info --login ranjan
 Id:                   5
 Login:                usera
 Email:                usera
 Organizations:        
    ranjan

2. Create User "User-B" for Organization B and of for syn errata email
 [root@dhcp6-10 ~]# hammer user info --login admin
 Id:                   3
 Login:                userb
 Email:                userb
 Organizations:        
    RedHat

3. Start a repo sync in Organization A

4. User-B also get a mail even he is not a part of Organization B

Sent mail to userb (3968.5ms)
2017-06-22 11:36:29  [app] [D] Date: Thu, 22 Jun 2017 11:36:25 +0530
 | From: satellite-noreply.redhat.com
 | To: userb
 | Subject: [satellite] Sync Summary for Red Hat Enterprise Linux 7 Server RPMs


Actual results: It send mail to all user irrespective of organization


Expected results: Mail should only send to the user who is having access to the organization


Additional info:

Comment 1 Ranjan Kumar 2017-06-22 08:53:37 UTC
Updating steps to reproduce

Steps to Reproduce:
1. Create User "User-A" in Organization-A and select "syn errata" in My Account
 [root@dsatellite ~]# hammer user info --login ranjan
 Id:                   5
 Login:                usera
 Email:                usera
 Organizations:        
    Organization-A

2. Create User "User-B" in Organization-B and select "syn errata" in My Account
 [root@satellite ~]# hammer user info --login admin
 Id:                   3
 Login:                userb
 Email:                userb
 Organizations:        
    Organization-B

3. Start any repository sync in Organization-A

4. Now Observed that User-B also get a mail even the userb is not a part of Organization-A

Sent mail to userb (3968.5ms)
2017-06-22 11:36:29  [app] [D] Date: Thu, 22 Jun 2017 11:36:25 +0530
 | From: satellite
 | To: userb
 | Subject: [satellite] Sync Summary for Red Hat Enterprise Linux 7 Server RPMs

Comment 2 Ranjan Kumar 2017-06-23 06:25:04 UTC
Fix: Patch for 6.2.9

diff --git a/app/lib/actions/katello/content_view/errata_mail.rb b/app/lib/actions/katello/content_view/errata_mail.rb
index b7ccfdd..9fca90e 100644
--- a/app/lib/actions/katello/content_view/errata_mail.rb
+++ b/app/lib/actions/katello/content_view/errata_mail.rb
@@ -11,7 +11,7 @@ module Actions
 
           content_view = ::Katello::ContentView.find(input[:content_view])
           environment = ::Katello::KTEnvironment.find(input[:environment])
-          users = ::User.select { |user| user.receives?(:promote_errata) && user.can?(:view_content_views, content_view) }
+          users = ::User.select { |user| user.receives?(:promote_errata) && user.organization_ids.include?(content_view.organization_id) && user.can?(:view_content_views, content_view) }
 
           begin
             MailNotification[:promote_errata].deliver(:users => users, :content_view => content_view, :environment => environment) unless users.blank?
diff --git a/app/lib/actions/katello/repository/errata_mail.rb b/app/lib/actions/katello/repository/errata_mail.rb
index e9a30f4..f91da89 100644
--- a/app/lib/actions/katello/repository/errata_mail.rb
+++ b/app/lib/actions/katello/repository/errata_mail.rb
@@ -13,7 +13,7 @@ module Actions
           ::User.current = ::User.anonymous_admin
 
           repo = ::Katello::Repository.find(input[:repo])
-          users = ::User.select { |user| user.receives?(:sync_errata) && user.can?(:view_products, repo.product) }.compact
+          users = ::User.select { |user| user.receives?(:sync_errata) && user.organization_ids.include?(repo.organization.id) && user.can?(:view_products, repo.product) }.compact
           errata = ::Katello::Erratum.where(:id => repo.repository_errata.where('katello_repository_errata.updated_at > ?', input[:last_updated].to_datetime).pluck(:erratum_id))
 
           begin

Comment 3 Satellite Program 2017-06-24 06:17:29 UTC
Moving this bug to POST for triage into Satellite 6 since the upstream issue http://projects.theforeman.org/issues/20084 has been resolved.

Comment 4 Omkar Khatavkar 2018-08-03 12:04:53 UTC
Verified On :
Satellite 6.4.14 Snap 

Steps Performed:

1. Create User "User-A" in Organization-A and select "syn errata" in My Account
 [root@dsatellite ~]# hammer user info --login ranjan
 Id:                   5
 Login:                usera
 Email:                usera
 Organizations:        
    Organization-A

2. Create User "User-B" in Organization-B and select "syn errata" in My Account
 [root@satellite ~]# hammer user info --login admin
 Id:                   3
 Login:                userb
 Email:                userb
 Organizations:        
    Organization-B

3. Start any repository sync in Organization-A

4. Now Observed that User-B also get a mail even the userb is not a part of Organization-A

Status:
Passed

Comment 5 Sanket Jagtap 2018-08-31 07:10:37 UTC
Build : Satellite 6.4.0

1. Created a user1 in OrgA
   User doesn't have accessto Orgb and is subscribed to sync errata mail notifications
When a Sync is completed in OrgA mail is send to the user 

Aug 31 03:01:17 qe-sat6-feature-rhel7 postfix/pickup[21225]: A164E4E27E6: uid=992 from=<root>
Aug 31 03:01:17 qe-sat6-feature-rhel7 postfix/cleanup[31985]: A164E4E27E6: message-id=<5b88e7bd8ec86_68d84c1dcbc144fa.mail>
Aug 31 03:01:17 qe-sat6-feature-rhel7 postfix/qmgr[1655]: A164E4E27E6: from=<root>, size=19784, nrcpt=1 (queue active)
Aug 31 03:01:18 qe-sat6-feature-rhel7 postfix/smtp[31987]: A164E4E27E6: to=<sjagtap@example>, relay=int-mx.corp.example[10.4.203.49]:25, delay=0.68, delays=0.05/0.01/0.29/0.33, dsn=2.0.0, status=sent (250 2.0.0 Ok: queued as 178103091330)
Aug 31 03:01:18 qe-sat6-feature-rhel7 postfix/qmgr[1655]: A164E4E27E6: removed


2. Created a user2 in OrgB 
   User doesn't have accessto OrgA and is subscribed to sync errata mail notifications
No mail is sent to this user.

Comment 6 Bryan Kearney 2018-10-16 19:01:07 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory, and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://access.redhat.com/errata/RHSA-2018:2927