代码之家  ›  专栏  ›  技术社区  ›  kryptonian

允许门户用户访问功能或导航到页面odoo 12

  •  0
  • kryptonian  · 技术社区  · 4 年前


    从控制器的所有可用功能模块,我用 sudo() 这样门户用户就不会获得任何访问权限问题。
    创建新时间表时,控制器直接调用 create() 函数,当delete调用 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)
    
    0 回复  |  直到 4 年前
        1
  •  0
  •   Den Den    4 年前

    <model("account.analytic.line"):timesheet> 在路由中,我相信它会在到达路由时检查模型/登录用户的权限。所以在你打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})
    
    推荐文章