From a60aaa391075e04626457c2f0b3b9cb7315da91f Mon Sep 17 00:00:00 2001 From: "Xavier BOL (xbo)" Date: Thu, 5 Aug 2021 15:38:37 +0200 Subject: [PATCH] [IMP] project: use project sharings in portal route Before this commit, when the portal user can access to project sharing and click on the shared link of the project. He is redirected to the `/project_sharing/` route. Since only the portal user can access and no public users, we could directly redirect to the portal route and display project sharing views. This commit removes the `/project_sharing/` route. The main route will always be the `/my/project/` and we check if the user can access project before rendering. If the user can access to the project via the shared link: 1. If he is a public user then we render the classic portal view. 2. If he is a portal user then - we check if he is an access to project sharing, if yes then we render project sharing views otherwise we display the classic portal views. task-2379518 closes #73341 --- addons/project/controllers/portal.py | 22 +++++-------------- .../views/project_sharing_templates.xml | 2 +- 2 files changed, 7 insertions(+), 17 deletions(-) diff --git a/addons/project/controllers/portal.py b/addons/project/controllers/portal.py index e7a3f3dfd53..cd04920d309 100644 --- a/addons/project/controllers/portal.py +++ b/addons/project/controllers/portal.py @@ -3,18 +3,18 @@ from collections import OrderedDict from operator import itemgetter - from markupsafe import Markup from odoo import conf, http, _ from odoo.exceptions import AccessError, MissingError from odoo.http import request -from odoo.addons.web.controllers.main import HomeStaticTemplateHelpers from odoo.addons.portal.controllers.portal import CustomerPortal, pager as portal_pager -from odoo.tools import consteq, groupby as groupbyelem +from odoo.tools import groupby as groupbyelem from odoo.osv.expression import OR +from odoo.addons.web.controllers.main import HomeStaticTemplateHelpers + class ProjectCustomerPortal(CustomerPortal): @@ -86,22 +86,12 @@ class ProjectCustomerPortal(CustomerPortal): project_sudo = self._document_check_access('project.project', project_id, access_token) except (AccessError, MissingError): return request.redirect('/my') - if project_sudo.privacy_visibility == 'portal' and not request.env.user._is_public(): + if project_sudo.with_user(request.env.user)._check_project_sharing_access(): return request.render("project.project_sharing_portal", {'project_id': project_id}) values = self._project_get_page_view_values(project_sudo, access_token, **kw) return request.render("project.portal_my_project", values) - @http.route("/project_sharing/", type='http', auth="user", methods=['GET']) - def get_project_sharing(self, project_id, model='project.project', access_token=None): - if not model or model != 'project.project' or not access_token: - return request.not_found() - project = request.env[model].sudo().browse(project_id) - project_validation = project and project.exists() and consteq(project.access_token, access_token) and project.privacy_visibility == 'portal' - if not project_validation: - return request.not_found() - return request.render('project.project_sharing', {'project_id': project.id}) - - @http.route("/embed/project/", type="http", auth="user", methods=['GET']) + @http.route("/my/project//project_sharing", type="http", auth="user", methods=['GET']) def render_project_backend_view(self, project_id): project = request.env['project.project'].sudo().browse(project_id) if not project.exists() or not project.with_user(request.env.user)._check_project_sharing_access(): @@ -123,7 +113,7 @@ class ProjectCustomerPortal(CustomerPortal): cache_hashes=cache_hashes, action_name='project.project_sharing_project_task_action', project_id=project.id, - can_edit=project.user_can_edit, + can_edit=project._check_project_sharing_access('edit'), user_companies={ 'current_company': project_company.id, 'allowed_companies': { diff --git a/addons/project/views/project_sharing_templates.xml b/addons/project/views/project_sharing_templates.xml index 3456532c48f..0dcc2e574a5 100644 --- a/addons/project/views/project_sharing_templates.xml +++ b/addons/project/views/project_sharing_templates.xml @@ -9,7 +9,7 @@