[FIX] website(_slides): correctly check can_publish status at create
Currently creating a record with 'is_published' being False (aka not published) crashes when people can't publish. However 'is_published' being False is the default value, and create should work in both cases. It now correctly checks that published records could effectively be published. This allows to remove a small workaround done in eLearning. See odoo/odoo@4086f344d8 for ref. Only failing use case would be having def _default_is_published(self): return True def _compute_can_publish(self): for record in self: record.can_publish = self.env.user.has_group('something') But this would not be a really valid use case: not being able to publish but having default publish to True makes no sense: what matters is publishing records as it gives more visibility to records, not the flag change itself. Followup of odoo/odoo#70291 Task-3299702 closes odoo/odoo#137900 Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
This commit is contained in:
@@ -205,10 +205,7 @@ class WebsitePublishedMixin(models.AbstractModel):
|
||||
@api.model_create_multi
|
||||
def create(self, vals_list):
|
||||
records = super(WebsitePublishedMixin, self).create(vals_list)
|
||||
is_publish_modified = any(
|
||||
[set(v.keys()) & {'is_published', 'website_published'} for v in vals_list]
|
||||
)
|
||||
if is_publish_modified and any(not record.can_publish for record in records):
|
||||
if any(record.is_published and not record.can_publish for record in records):
|
||||
raise AccessError(self._get_can_publish_error_message())
|
||||
|
||||
return records
|
||||
|
||||
@@ -1451,11 +1451,6 @@ class WebsiteSlides(WebsiteProfile):
|
||||
# create slide itself
|
||||
try:
|
||||
values['user_id'] = request.env.uid
|
||||
# Hack, to remove when reworking create method of website.published.mixin
|
||||
# We cannot create slide with is_published in values and can_publish = False
|
||||
if 'is_published' in values:
|
||||
if not values.get('is_published') or not can_publish:
|
||||
del values['is_published']
|
||||
slide = request.env['slide.slide'].sudo().create(values)
|
||||
except UserError as e:
|
||||
_logger.error(e)
|
||||
|
||||
Reference in New Issue
Block a user