【问题标题】:allow portal user to access feature or navigate to the page odoo 12允许门户用户访问功能或导航到 odoo 12 页面
【发布时间】:2020-09-28 06:29:55
【问题描述】:

我在 odoo 12 中创建了一个模块,允许门户用户管理他们的时间表。
从控制器模块的所有可用功能中,我使用了sudo(),这样门户用户就不会遇到任何访问权限问题。
创建新时间表控制器时直接调用create() 函数,删除时调用unlink() 但是当用户想要编辑时间表时,我将用户重定向到另一个页面,在该页面上,有一个编辑表单,但是当门户用户导航到该页面时,它会向我显示 403 禁止错误消息。
仅当我创建新的门户用户时才会出现此问题,它允许已经在 odoo 中的 Joel Willis。
我也在那个编辑时间表模板中添加了sudo(),但它不起作用。
像这样..

class EditTimesheet(http.Controller):

    @http.route(['/edit_timesheet/<model("account.analytic.line"):timesheet>'], type='http', auth="public", website=True)
    def _edit_timesheet(self, timesheet, category='', search='', **kwargs):
        self.sudo().edit_timesheet(timesheet, category='', search='', **kwargs)

    def edit_timesheet(self, timesheet, category='', search='', **kwargs):
        return request.render("timesheet_module.edit_timesheet",{'timesheet':timesheet.sudo()})

记录器中的错误。
Traceback (most recent call last):
  File "/home/milan/workspace/odoo/odoo12/odoo/api.py", line 1049, in get
    value = self._data[key][field][record._ids[0]]
KeyError: 6

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/milan/workspace/odoo/odoo12/odoo/fields.py", line 1012, in __get__
    value = record.env.cache.get(record, self)
  File "/home/milan/workspace/odoo/odoo12/odoo/api.py", line 1051, in get
    raise CacheMiss(record, field)
odoo.exceptions.CacheMiss: ('account.analytic.line(6,).display_name', None)

odoo.exceptions.AccessError: ('The requested operation cannot be completed due to security restrictions. Please contact your system administrator.\n\n(Document type: Analytic Line, Operation: read) - (Records: [6], User: 8)', None)

【问题讨论】:

    标签: python-3.x odoo-12


    【解决方案1】:

    当您在路由中使用&lt;model("account.analytic.line"):timesheet&gt; 时,我相信它会在路由命中时检查模型/登录用户的权限。因此,它甚至在您进行 sudo 调用之前就抛出了错误。我建议改为使用 accout.analytic.line id(确保你只传入 id)并将你的 2 个路由组合成 1 个这样的路由......

    @http.route(['/edit_timesheet/<int:timesheet_id>'], type='http', auth="public", website=True)
        def edit_timesheet(self, timesheet_id, category='', search='', **kwargs):
            timsheet = env['account.analytic.line'].sudo().browse(timesheet_id)
            return request.render("timesheet_module.edit_timesheet",{'timesheet':timesheet})
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-06-11
      • 1970-01-01
      • 2021-08-28
      • 1970-01-01
      • 2019-07-07
      • 1970-01-01
      相关资源
      最近更新 更多