Files
odoo_source/addons/rating/tests/test_security.py
T
ryv-odoo c7a1a2d964 [REF] rating, various: improve rating.rating ACLs
PURPOSE

Rating model should be available only for internal users. External users
access them only through dedicated routes or controllers using sudo and/or
granting access through tokens. Therefore simplifying ACLs should be feasible.

SPECIFICATIONS

Remove access to rating.rating for public and portal users. Only employees
can access it, with full access given to system admins.

Update various functional flows to use sudo() and check that access is
verified before using sudo.

Impacted modules

  * rating / mail: add groups on some rating related fields as only
    internal users should access them now;
  * rating / mail: set some statistics fields using compute_sudo as their
    value should be accessible for external people even without access to
    the underlying rating.rating records;
  * project: makes some use of rating and has to be updated, notably for
    the public rating page;
  * website_{livechat, rating, slides}: add sudo in public routes as access
    is already granted;
  * website_slides: set statistics field using compute_sudo as their
    value should be accessible for external people;

TASK ID 2053096
PR #36592

Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
2019-11-19 15:46:51 +00:00

80 lines
3.1 KiB
Python

# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo.exceptions import AccessError
from odoo.tests import tagged, common, new_test_user
from odoo.tools import mute_logger
from functools import partial
rating_new_test_user = partial(new_test_user, context={'mail_create_nolog': True, 'mail_create_nosubscribe': True, 'mail_notrack': True, 'no_reset_password': True})
@tagged('security')
class TestAccessRating(common.SavepointCase):
@classmethod
def setUpClass(cls):
super(TestAccessRating, cls).setUpClass()
cls.user_manager_partner = rating_new_test_user(
cls.env, name='Jean Admin', login='user_mana', email='admin@example.com',
groups='base.group_partner_manager,base.group_system'
)
cls.user_emp = rating_new_test_user(
cls.env, name='Eglantine Employee', login='user_emp', email='employee@example.com',
groups='base.group_user'
)
cls.user_portal = rating_new_test_user(
cls.env, name='Patrick Portal', login='user_portal', email='portal@example.com',
groups='base.group_portal'
)
cls.user_public = rating_new_test_user(
cls.env, name='Pauline Public', login='user_public', email='public@example.com',
groups='base.group_public'
)
cls.partner_to_rate = cls.env['res.partner'].with_user(cls.user_manager_partner).create({
"name": "Partner to Rate :("
})
@mute_logger('odoo.addons.base.models.ir_model')
def test_rating_access(self):
""" Security test : only a employee (user group) can create and write rating object """
# Public and portal user can't Access direclty to the ratings
with self.assertRaises(AccessError):
self.env['rating.rating'].with_user(self.user_portal).create({
'res_model_id': self.env['ir.model'].sudo().search([('model', '=', 'res.partner')], limit=1).id,
'res_model': 'res.partner',
'res_id': self.partner_to_rate.id,
'rating': 2
})
with self.assertRaises(AccessError):
self.env['rating.rating'].with_user(self.user_public).create({
'res_model_id': self.env['ir.model'].sudo().search([('model', '=', 'res.partner')], limit=1).id,
'res_model': 'res.partner',
'res_id': self.partner_to_rate.id,
'rating': 5
})
# No error with employee
ratting = self.env['rating.rating'].with_user(self.user_emp).create({
'res_model_id': self.env['ir.model'].sudo().search([('model', '=', 'res.partner')], limit=1).id,
'res_model': 'res.partner',
'res_id': self.partner_to_rate.id,
'rating': 5
})
with self.assertRaises(AccessError):
ratting.with_user(self.user_portal).write({
'feedback': 'You should not pass!'
})
with self.assertRaises(AccessError):
ratting.with_user(self.user_public).write({
'feedback': 'You should not pass!'
})