Files
odoo_source/addons/website_slides/tests/common.py
T
Romain Derie cc1d78a80b [IMP] *: correctly read/write website_published
The `website_published` field from the website's mixins is basically a readonly
from `is_published` field.
On read, this field will simply read `is_published` and check if the record's
website_id is accessible (only for the multi mixin).
On write, it will always write on `is_published`.

This commit improves a few things:
- A lot of code was writting on website_published which was just then writting
  on is_published. Writting directly on is_published makes more sense.
- Some backend fields would still reference `website_published` instead of
  `is_published` which would just go through the related for no reason.
  Plus, using `is_published` will make the field tooltip more accurate as we
  are not in a website context ('Visible on current website' to 'Is Published')
- Filter and search on tree view were still using the `website_published`
  related field, which is just a readonly when we are not in a frontend
  context.
- Some create and write function would have security check on
  `website_published` value but that was wrong as the user could bypass that by
  simply writting on `is_published`. For the write method, check `is_published`
  is more accurate as it will cover both case since `website_published` will
  then call the write method on `is_published`
2019-08-03 09:51:22 +00:00

71 lines
2.4 KiB
Python

# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from contextlib import contextmanager
from functools import partial
from odoo.tests import common, new_test_user
slides_new_test_user = partial(new_test_user, context={'mail_create_nolog': True, 'mail_create_nosubscribe': True, 'mail_notrack': True, 'no_reset_password': True})
class SlidesCase(common.SavepointCase):
def setUp(self):
super(SlidesCase, self).setUp()
self.user_publisher = slides_new_test_user(
self.env, name='Paul Publisher', login='user_publisher', email='publisher@example.com',
groups='base.group_user,website.group_website_publisher'
)
self.user_emp = slides_new_test_user(
self.env, name='Eglantine Employee', login='user_emp', email='employee@example.com',
groups='base.group_user'
)
self.user_portal = slides_new_test_user(
self.env, name='Patrick Portal', login='user_portal', email='portal@example.com',
groups='base.group_portal'
)
self.user_public = slides_new_test_user(
self.env, name='Pauline Public', login='user_public', email='public@example.com',
groups='base.group_public'
)
self.customer = self.env['res.partner'].create({
'name': 'Caroline Customer',
'email': 'customer@example.com',
})
self.channel = self.env['slide.channel'].with_user(self.user_publisher).create({
'name': 'Test Channel',
'channel_type': 'documentation',
'promote_strategy': 'most_voted',
'enroll': 'public',
'visibility': 'public',
'is_published': True,
'karma_gen_channel_finish': 100,
'karma_gen_slide_vote': 5,
'karma_gen_channel_rank': 10,
})
self.slide = self.env['slide.slide'].with_user(self.user_publisher).create({
'name': 'How To Cook Humans',
'channel_id': self.channel.id,
'slide_type': 'presentation',
'is_published': True,
'completion_time': 2.0,
})
@contextmanager
def with_user(self, user):
""" Quick with_user environment """
old_uid = self.uid
try:
self.uid = user.id
yield
finally:
# back
self.uid = old_uid