2013-04-12 15:12:36 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
##############################################################################
|
|
|
|
#
|
|
|
|
# OpenERP, Open Source Business Applications
|
|
|
|
# Copyright (c) 2013-TODAY OpenERP S.A. <http://openerp.com>
|
|
|
|
#
|
|
|
|
# This program is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU Affero General Public License as
|
|
|
|
# published by the Free Software Foundation, either version 3 of the
|
|
|
|
# License, or (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU Affero General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU Affero General Public License
|
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
#
|
|
|
|
##############################################################################
|
|
|
|
|
2013-07-10 13:29:54 +00:00
|
|
|
from openerp.addons.portal_project.tests.test_access_rights import TestPortalProjectBase
|
2013-12-06 12:57:51 +00:00
|
|
|
from openerp.exceptions import AccessError
|
2013-04-12 15:12:36 +00:00
|
|
|
from openerp.osv.orm import except_orm
|
|
|
|
from openerp.tools import mute_logger
|
|
|
|
|
|
|
|
|
2013-07-10 13:29:54 +00:00
|
|
|
class TestPortalProjectBase(TestPortalProjectBase):
|
2013-04-12 15:12:36 +00:00
|
|
|
|
|
|
|
def setUp(self):
|
2013-07-10 13:29:54 +00:00
|
|
|
super(TestPortalProjectBase, self).setUp()
|
2013-04-12 15:12:36 +00:00
|
|
|
cr, uid = self.cr, self.uid
|
|
|
|
|
|
|
|
# Useful models
|
|
|
|
self.project_issue = self.registry('project.issue')
|
|
|
|
|
|
|
|
# Various test issues
|
2013-07-10 13:29:54 +00:00
|
|
|
self.issue_1_id = self.project_issue.create(cr, uid, {
|
|
|
|
'name': 'Test1', 'user_id': False, 'project_id': self.project_pigs_id}, {'mail_create_nolog': True})
|
|
|
|
self.issue_2_id = self.project_issue.create(cr, uid, {
|
|
|
|
'name': 'Test2', 'user_id': False, 'project_id': self.project_pigs_id}, {'mail_create_nolog': True})
|
|
|
|
self.issue_3_id = self.project_issue.create(cr, uid, {
|
|
|
|
'name': 'Test3', 'user_id': False, 'project_id': self.project_pigs_id}, {'mail_create_nolog': True})
|
|
|
|
self.issue_4_id = self.project_issue.create(cr, uid, {
|
|
|
|
'name': 'Test4', 'user_id': self.user_projectuser_id, 'project_id': self.project_pigs_id}, {'mail_create_nolog': True})
|
|
|
|
self.issue_5_id = self.project_issue.create(cr, uid, {
|
|
|
|
'name': 'Test5', 'user_id': self.user_portal_id, 'project_id': self.project_pigs_id}, {'mail_create_nolog': True})
|
|
|
|
self.issue_6_id = self.project_issue.create(cr, uid, {
|
2013-07-26 15:35:04 +00:00
|
|
|
'name': 'Test6', 'user_id': self.user_public_id, 'project_id': self.project_pigs_id}, {'mail_create_nolog': True})
|
2013-07-10 13:29:54 +00:00
|
|
|
|
|
|
|
|
|
|
|
class TestPortalIssue(TestPortalProjectBase):
|
2014-07-06 14:44:26 +00:00
|
|
|
@mute_logger('openerp.addons.base.ir.ir_model', 'openerp.models')
|
2013-04-12 15:12:36 +00:00
|
|
|
def test_00_project_access_rights(self):
|
|
|
|
""" Test basic project access rights, for project and portal_project """
|
|
|
|
cr, uid, pigs_id = self.cr, self.uid, self.project_pigs_id
|
|
|
|
|
|
|
|
# ----------------------------------------
|
|
|
|
# CASE1: public project
|
|
|
|
# ----------------------------------------
|
|
|
|
|
|
|
|
# Do: Alfred reads project -> ok (employee ok public)
|
|
|
|
# Test: all project issues visible
|
2013-07-10 13:29:54 +00:00
|
|
|
issue_ids = self.project_issue.search(cr, self.user_projectuser_id, [('project_id', '=', pigs_id)])
|
2013-04-12 15:12:36 +00:00
|
|
|
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(issue_ids), test_issue_ids,
|
2013-07-10 13:29:54 +00:00
|
|
|
'access rights: project user cannot see all issues of a public project')
|
2013-04-12 15:12:36 +00:00
|
|
|
# Test: all project issues readable
|
2013-07-10 13:29:54 +00:00
|
|
|
self.project_issue.read(cr, self.user_projectuser_id, issue_ids, ['name'])
|
2013-04-12 15:12:36 +00:00
|
|
|
# Test: all project issues writable
|
2013-07-10 13:29:54 +00:00
|
|
|
self.project_issue.write(cr, self.user_projectuser_id, issue_ids, {'description': 'TestDescription'})
|
2013-04-12 15:12:36 +00:00
|
|
|
|
|
|
|
# Do: Bert reads project -> crash, no group
|
|
|
|
# Test: no project issue visible
|
2013-12-06 12:57:51 +00:00
|
|
|
self.assertRaises(AccessError, self.project_issue.search, cr, self.user_none_id, [('project_id', '=', pigs_id)])
|
2013-04-12 15:12:36 +00:00
|
|
|
# Test: no project issue readable
|
2013-12-06 12:57:51 +00:00
|
|
|
self.assertRaises(AccessError, self.project_issue.read, cr, self.user_none_id, issue_ids, ['name'])
|
2013-04-12 15:12:36 +00:00
|
|
|
# Test: no project issue writable
|
2013-12-06 12:57:51 +00:00
|
|
|
self.assertRaises(AccessError, self.project_issue.write, cr, self.user_none_id, issue_ids, {'description': 'TestDescription'})
|
2013-04-12 15:12:36 +00:00
|
|
|
|
|
|
|
# Do: Chell reads project -> ok (portal ok public)
|
|
|
|
# Test: all project issues visible
|
2013-07-10 13:29:54 +00:00
|
|
|
issue_ids = self.project_issue.search(cr, self.user_portal_id, [('project_id', '=', pigs_id)])
|
2013-04-12 15:12:36 +00:00
|
|
|
self.assertEqual(set(issue_ids), test_issue_ids,
|
2013-07-10 13:29:54 +00:00
|
|
|
'access rights: project user cannot see all issues of a public project')
|
2013-04-12 15:12:36 +00:00
|
|
|
# Test: all project issues readable
|
2013-07-10 13:29:54 +00:00
|
|
|
self.project_issue.read(cr, self.user_portal_id, issue_ids, ['name'])
|
2013-04-12 15:12:36 +00:00
|
|
|
# Test: no project issue writable
|
2013-12-06 12:57:51 +00:00
|
|
|
self.assertRaises(AccessError, self.project_issue.write, cr, self.user_portal_id, issue_ids, {'description': 'TestDescription'})
|
2013-04-12 15:12:36 +00:00
|
|
|
|
2013-07-26 09:04:45 +00:00
|
|
|
# Do: Donovan reads project -> ok (public ok public)
|
2013-04-15 15:01:07 +00:00
|
|
|
# Test: all project issues visible
|
2013-07-26 15:35:04 +00:00
|
|
|
issue_ids = self.project_issue.search(cr, self.user_public_id, [('project_id', '=', pigs_id)])
|
2013-04-15 15:01:07 +00:00
|
|
|
self.assertEqual(set(issue_ids), test_issue_ids,
|
2013-07-10 13:29:54 +00:00
|
|
|
'access rights: project user cannot see all issues of a public project')
|
2013-04-12 15:12:36 +00:00
|
|
|
|
|
|
|
# ----------------------------------------
|
|
|
|
# CASE2: portal project
|
|
|
|
# ----------------------------------------
|
|
|
|
self.project_project.write(cr, uid, [pigs_id], {'privacy_visibility': 'portal'})
|
|
|
|
|
|
|
|
# Do: Alfred reads project -> ok (employee ok public)
|
|
|
|
# Test: all project issues visible
|
2013-07-10 13:29:54 +00:00
|
|
|
issue_ids = self.project_issue.search(cr, self.user_projectuser_id, [('project_id', '=', pigs_id)])
|
2013-04-12 15:12:36 +00:00
|
|
|
self.assertEqual(set(issue_ids), test_issue_ids,
|
2013-07-10 13:29:54 +00:00
|
|
|
'access rights: project user cannot see all issues of a portal project')
|
2013-04-12 15:12:36 +00:00
|
|
|
|
|
|
|
# Do: Bert reads project -> crash, no group
|
|
|
|
# Test: no project issue searchable
|
2013-12-06 12:57:51 +00:00
|
|
|
self.assertRaises(AccessError, self.project_issue.search, cr, self.user_none_id, [('project_id', '=', pigs_id)])
|
2013-04-12 15:12:36 +00:00
|
|
|
|
|
|
|
# Data: issue follower
|
2013-07-10 13:29:54 +00:00
|
|
|
self.project_issue.message_subscribe_users(cr, self.user_projectuser_id, [self.issue_1_id, self.issue_3_id], [self.user_portal_id])
|
2013-04-12 15:12:36 +00:00
|
|
|
|
|
|
|
# Do: Chell reads project -> ok (portal ok public)
|
|
|
|
# Test: only followed project issues visible + assigned
|
2013-07-10 13:29:54 +00:00
|
|
|
issue_ids = self.project_issue.search(cr, self.user_portal_id, [('project_id', '=', pigs_id)])
|
2013-04-12 15:12:36 +00:00
|
|
|
test_issue_ids = set([self.issue_1_id, self.issue_3_id, self.issue_5_id])
|
|
|
|
self.assertEqual(set(issue_ids), test_issue_ids,
|
2013-07-10 13:29:54 +00:00
|
|
|
'access rights: portal user should see the followed issues of a portal project')
|
2013-04-12 15:12:36 +00:00
|
|
|
|
|
|
|
# Data: issue follower cleaning
|
2013-07-10 13:29:54 +00:00
|
|
|
self.project_issue.message_unsubscribe_users(cr, self.user_projectuser_id, [self.issue_1_id, self.issue_3_id], [self.user_portal_id])
|
2013-04-12 15:12:36 +00:00
|
|
|
|
|
|
|
# ----------------------------------------
|
|
|
|
# CASE3: employee project
|
|
|
|
# ----------------------------------------
|
|
|
|
self.project_project.write(cr, uid, [pigs_id], {'privacy_visibility': 'employees'})
|
|
|
|
|
|
|
|
# Do: Alfred reads project -> ok (employee ok employee)
|
|
|
|
# Test: all project issues visible
|
2013-07-10 13:29:54 +00:00
|
|
|
issue_ids = self.project_issue.search(cr, self.user_projectuser_id, [('project_id', '=', pigs_id)])
|
2013-04-12 15:12:36 +00:00
|
|
|
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(issue_ids), test_issue_ids,
|
2013-07-10 13:29:54 +00:00
|
|
|
'access rights: project user cannot see all issues of an employees project')
|
2013-04-12 15:12:36 +00:00
|
|
|
|
|
|
|
# Do: Chell reads project -> ko (portal ko employee)
|
|
|
|
# Test: no project issue visible + assigned
|
2013-07-10 13:29:54 +00:00
|
|
|
issue_ids = self.project_issue.search(cr, self.user_portal_id, [('project_id', '=', pigs_id)])
|
2013-04-12 15:12:36 +00:00
|
|
|
self.assertFalse(issue_ids, 'access rights: portal user should not see issues of an employees project, even if assigned')
|
|
|
|
|
|
|
|
# ----------------------------------------
|
|
|
|
# CASE4: followers project
|
|
|
|
# ----------------------------------------
|
|
|
|
self.project_project.write(cr, uid, [pigs_id], {'privacy_visibility': 'followers'})
|
|
|
|
|
|
|
|
# Do: Alfred reads project -> ko (employee ko followers)
|
|
|
|
# Test: no project issue visible
|
2013-07-10 13:29:54 +00:00
|
|
|
issue_ids = self.project_issue.search(cr, self.user_projectuser_id, [('project_id', '=', pigs_id)])
|
2013-04-12 15:12:36 +00:00
|
|
|
test_issue_ids = set([self.issue_4_id])
|
|
|
|
self.assertEqual(set(issue_ids), test_issue_ids,
|
2013-07-10 13:29:54 +00:00
|
|
|
'access rights: employee user should not see issues of a not-followed followers project, only assigned')
|
2013-04-12 15:12:36 +00:00
|
|
|
|
|
|
|
# Do: Chell reads project -> ko (portal ko employee)
|
|
|
|
# Test: no project issue visible
|
2013-07-10 13:29:54 +00:00
|
|
|
issue_ids = self.project_issue.search(cr, self.user_portal_id, [('project_id', '=', pigs_id)])
|
2013-04-12 15:12:36 +00:00
|
|
|
test_issue_ids = set([self.issue_5_id])
|
|
|
|
self.assertEqual(set(issue_ids), test_issue_ids,
|
2013-07-10 13:29:54 +00:00
|
|
|
'access rights: portal user should not see issues of a not-followed followers project, only assigned')
|
2013-04-12 15:12:36 +00:00
|
|
|
|
|
|
|
# Data: subscribe Alfred, Chell and Donovan as follower
|
2013-07-26 15:35:04 +00:00
|
|
|
self.project_project.message_subscribe_users(cr, uid, [pigs_id], [self.user_projectuser_id, self.user_portal_id, self.user_public_id])
|
2014-01-07 17:33:39 +00:00
|
|
|
self.project_issue.message_subscribe_users(cr, self.user_manager_id, [self.issue_1_id, self.issue_3_id], [self.user_portal_id, self.user_projectuser_id])
|
2013-04-12 15:12:36 +00:00
|
|
|
|
|
|
|
# Do: Alfred reads project -> ok (follower ok followers)
|
|
|
|
# Test: followed + assigned issues visible
|
2013-07-10 13:29:54 +00:00
|
|
|
issue_ids = self.project_issue.search(cr, self.user_projectuser_id, [('project_id', '=', pigs_id)])
|
2013-04-12 15:12:36 +00:00
|
|
|
test_issue_ids = set([self.issue_1_id, self.issue_3_id, self.issue_4_id])
|
|
|
|
self.assertEqual(set(issue_ids), test_issue_ids,
|
2013-07-10 13:29:54 +00:00
|
|
|
'access rights: employee user should not see followed + assigned issues of a follower project')
|
2013-04-12 15:12:36 +00:00
|
|
|
|
|
|
|
# Do: Chell reads project -> ok (follower ok follower)
|
|
|
|
# Test: followed + assigned issues visible
|
2013-07-10 13:29:54 +00:00
|
|
|
issue_ids = self.project_issue.search(cr, self.user_portal_id, [('project_id', '=', pigs_id)])
|
2013-04-12 15:12:36 +00:00
|
|
|
test_issue_ids = set([self.issue_1_id, self.issue_3_id, self.issue_5_id])
|
|
|
|
self.assertEqual(set(issue_ids), test_issue_ids,
|
2013-07-10 13:29:54 +00:00
|
|
|
'access rights: employee user should not see followed + assigned issues of a follower project')
|