【问题标题】:Permission of ir.config_paramenter in odoo 12odoo 12 中 ir.config_paramenter 的权限
【发布时间】:2021-12-22 22:47:47
【问题描述】:

我遇到了这个问题。为什么我会收到此访问错误,我该如何解决?

Odoo 服务器错误 - 访问错误
抱歉,您无权访问 这个文件。只有具有以下访问级别的用户 目前允许这样做:

  • 管理/设置

(文档模型:ir.config_parameter)-(操作:读取,用户:21)

这是我的代码:

按钮提交:

    <button string="Confirm" name="button_submit" states="draft" type="object" class="oe_highlight"/>

我的python代码:

    def send_email(self, subject, message_body, email_from, email_to): 
        template_obj = self.env['mail.mail']
        template_data = { 
            'subject': subject,
            'body_html': message_body,
            'email_from': email_from, 
            'email_to': email_to 
        } 
        template_id = template_obj.create(template_data)
        template_obj.send(template_id)
        template_id.send()

    @api.multi
    def request_recuitment_send_mail(self):
        """ Send mail with wizard """
         base_url = request.env['ir.config_parameter'].get_param('web.base.url')
        base_url += '/web#id=%d&view_type=form&model=%s' % (self.id, self._name)
        subject = '''Request recuitment for {}'''.format(self.job_id.name)
        message_body = '''
            <div style="font-size: medium;">
                Dear {},
                Please check this link for more information <a href="{}">Click here</a>
            '''.format(
            self.user_id.name,
            base_url,
        )
        email_from = '''HR Recruiment <{}>'''.format(self.approver_id.work_email)
        email_to = self.user_id.email
        self.send_email(subject, message_body, email_from, email_to)

    @api.multi
    def button_approve(self):
        subject = "Request recruitment for {self.job_id.name} has been approved "
        body = '''
            Position Request: {}
            Quantity of Position: {}
            Department: {}
            Expected Gross Salary: {}
        '''.format(
            self.job_id.name,
            self.quantity,
            self.department_id.name,
            self.salary_cross_expected
        )
        self.env['mail.message'].create({'message_type': "notification",
                                         "subtype": self.env.ref("mail.mt_comment").id,
                                         'body': body,
                                         'subject': subject,
                                         'needaction_partner_ids': [(4, self.user_id.partner_id.id,)],
                                         'model': self._name,
                                         'res_id': self.id,
                                         })
        self.request_recuitment_approved_send_mail()
        self.write({'state': 'approved'})

【问题讨论】:

    标签: permissions odoo odoo-12


    【解决方案1】:

    在这种情况下使用sudo()应该是安全的:

    request.env['ir.config_parameter'].sudo().get_param('web.base.url')
    

    “普通”用户对模型ir.config_parameter(系统参数)没有任何权限。只有管​​理员(其默认访问组之一)或超级用户可以读取此类参数。

    关于sudo([flag=True])来自current documentation (Odoo 15)

    返回此记录集的新版本,启用或禁用超级用户模式,具体取决于标志。超级用户模式不会改变当前用户,只是绕过访问权限检查。

    重要提示:我不完全确定何时更改,但 IIRC 自 Odoo 13 以来已删除“当前用户更改”。因此对于 Odoo 12 sudo 将更改当前用户,例如这将对创建时的默认值、创建的消息作者等。

    在您的情况下,这无关紧要,因为您只获取基本 url 或参数值,仅此而已。

    【讨论】:

      猜你喜欢
      • 2020-06-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-08-15
      • 2023-02-09
      • 1970-01-01
      相关资源
      最近更新 更多