- Create a portal user - Set an email address - Create a project with tasks / issues - Create a task / issue, set the portal user as follower => he should have access to the task from URL `/my/task/<id>`. - On an email received (e.g. when the user is set as follower), click on 'View Task' The user is redirected to the chatter instead of `/my/task/<id>` or `/my/issue/<id>`. In method, `_redirect_to_record`, the record is browsed as `sudo`. Therefore, in `get_access_action`, `self.env.user` is the admin. We check the context to get the original user. opw-1814577
76 lines
2.4 KiB
Python
76 lines
2.4 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.context.get('uid'):
|
|
user = self.env['res.users'].browse(self.env.context['uid'])
|
|
else:
|
|
user = self.env.user
|
|
if 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_recipients(self, message, groups):
|
|
groups = super(Project, self)._notification_recipients(message, groups)
|
|
|
|
for group_name, group_method, group_data in groups:
|
|
group_data['has_button_access'] = True
|
|
|
|
return groups
|
|
|
|
|
|
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.context.get('uid'):
|
|
user = self.env['res.users'].browse(self.env.context['uid'])
|
|
else:
|
|
user = self.env.user
|
|
if 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_recipients(self, message, groups):
|
|
groups = super(Task, self)._notification_recipients(message, groups)
|
|
|
|
for group_name, group_method, group_data in groups:
|
|
group_data['has_button_access'] = True
|
|
|
|
return groups
|