'Test basic project access rights, for project and portal_project'

@mute_logger('odoo.addons.base.ir.ir_model', 'odoo.models')
def test_00_project_access_rights(self):

    pigs_id = self.project_pigs.id
    Issue = self.env['project.issue']
    self.project_pigs.write({'privacy_visibility': 'portal'})
    issues = Issue.sudo(self.user_projectuser.id).search([('project_id', '=', pigs_id)])
    test_issue_ids = set([self.issue_1.id, self.issue_2.id, self.issue_3.id, self.issue_4.id, self.issue_5.id, self.issue_6.id])
    self.assertEqual(set(issues.ids), test_issue_ids, 'access    rights:    project    user    cannot    see    all    issues    of    a    portal    project')
    self.assertRaises(AccessError, Issue.sudo(self.user_noone.id).search, [('project_id', '=', pigs_id)])
    self.issue_1.sudo(self.user_projectuser.id).message_subscribe_users(user_ids=[self.user_portal.id])
    self.issue_3.sudo(self.user_projectuser.id).message_subscribe_users(user_ids=[self.user_portal.id])
    issues = Issue.sudo(self.user_portal.id).search([('project_id', '=', pigs_id)])
    self.assertEqual(set(issues.ids), set([self.issue_1.id, self.issue_3.id, self.issue_5.id]), 'access    rights:    portal    user    should    see    the    followed    issues    of    a    portal    project')
    self.issue_1.sudo(self.user_projectuser.id).message_unsubscribe_users(user_ids=[self.user_portal.id])
    self.issue_3.sudo(self.user_projectuser.id).message_unsubscribe_users(user_ids=[self.user_portal.id])
    self.project_pigs.write({'privacy_visibility': 'employees'})
    issues = Issue.sudo(self.user_projectuser.id).search([('project_id', '=', pigs_id)])
    self.assertEqual(set(issues.ids), set([self.issue_1.id, self.issue_2.id, self.issue_3.id, self.issue_4.id, self.issue_5.id, self.issue_6.id]), 'access    rights:    project    user    cannot    see    all    issues    of    an    employees    project')
    issues = Issue.sudo(self.user_portal.id).search([('project_id', '=', pigs_id)])
    self.assertFalse(issues.ids, 'access    rights:    portal    user    should    not    see    issues    of    an    employees    project,    even    if    assigned')
    self.project_pigs.write({'privacy_visibility': 'followers'})
    self.project_pigs.message_subscribe_users(user_ids=[self.user_projectuser.id, self.user_portal.id, self.user_public.id])
    self.issue_1.sudo(self.user_projectmanager.id).message_subscribe_users(user_ids=[self.user_portal.id, self.user_projectuser.id])
    self.issue_3.sudo(self.user_projectmanager.id).message_subscribe_users(user_ids=[self.user_portal.id, self.user_projectuser.id])
    issues = Issue.sudo(self.user_projectuser.id).search([('project_id', '=', pigs_id)])
    self.assertEqual(set(issues.ids), test_issue_ids, 'access    rights:    employee    user    should    not    see    followed    +    assigned    issues    of    a    follower    project')
    issues = Issue.sudo(self.user_portal.id).search([('project_id', '=', pigs_id)])
    self.assertFalse(set(issues.ids), 'access    rights:    portal    user    should    not    see    issues    of    a    follower    project')
