Files
odoo_source/addons/website_project/models/project.py
T
Thibault Delavallée fcd6813dc9 [FIX][IMP] various: unsudo mail/view controller and get_access_action
This is a backport of saas-13 commit a9bd9ab160.

mail/view controller is a generic controller that redirects the user to a
given view, depending on the record and the user. Users may be redirected
to the backend form view, or to a website view. This is done notably by
calling get_access_action method that gives the action to perform (act_window
or url).

Previously this method was called using SUPERUSER. However it was therefore
impossible to know who the user was. This method is now called using the
current user. Various overrides of get_access_action have been updated to
add some logic and access rights check directly in the method allowing
more fine-grain behavior of the access action.
2016-09-26 14:42:25 +02:00

72 lines
2.7 KiB
Python

# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo import api, exceptions, models
class Project(models.Model):
_inherit = ['project.project']
@api.multi
def get_access_action(self):
""" Instead of the classic form view, redirect to website for portal users
that can read the project. """
self.ensure_one()
if self.env.user.share:
try:
self.check_access_rule('read')
except exceptions.AccessError:
pass
else:
return {
'type': 'ir.actions.act_url',
'url': '/my/project/%s' % self.id,
'target': 'self',
'res_id': self.id,
}
return super(Project, self).get_access_action()
@api.multi
def _notification_group_recipients(self, message, recipients, done_ids, group_data):
""" Override the method to place the portal customers in the 'user' group data as a portal view now exists"""
for recipient in recipients:
if recipient.id in done_ids:
continue
if recipient.user_ids and all(recipient.user_ids.mapped('share')):
group_data['user'] |= recipient
done_ids.add(recipient.id)
return super(Project, self)._notification_group_recipients(message, recipients, done_ids, group_data)
class Task(models.Model):
_inherit = ['project.task']
@api.multi
def get_access_action(self):
""" Instead of the classic form view, redirect to website for portal users
that can read the task. """
self.ensure_one()
if self.env.user.share:
try:
self.check_access_rule('read')
except exceptions.AccessError:
pass
else:
return {
'type': 'ir.actions.act_url',
'url': '/my/task/%s' % self.id,
'target': 'self',
'res_id': self.id,
}
return super(Task, self).get_access_action()
@api.multi
def _notification_group_recipients(self, message, recipients, done_ids, group_data):
""" Override the method to place the portal customers in the 'user' group data as a portal view now exists"""
for recipient in recipients:
if recipient.id in done_ids:
continue
if recipient.user_ids and all(recipient.user_ids.mapped('share')):
group_data['user'] |= recipient
done_ids.add(recipient.id)
return super(Task, self)._notification_group_recipients(message, recipients, done_ids, group_data)