美好的一天我改变了website_hr_recruitment模块以添加一些功能来下载一些文件 . 但是当我尝试在没有用户访问权限的情况下下载文件时出现错误 . 错误是
{“message”:“Odoo Server Error”,“code”:200,“data”:{“debug”:“Traceback(最近一次调用最后一次):\ n File \”/ opt / odoo / odoo-server / addons / web / controllers / main.py \“,第70行,在wrap \ n中返回f(* args,** kwargs)\ n文件\”/ opt / odoo / odoo-server / addons / web / controllers / main .py \“,第1092行,在saveas \ n res = Model.read(cr,uid,[int(id)],fields,context)[0] \ n File \”/ opt / odoo / odoo-server / openerp / api.py \“,第268行,在包装器中\ n返回old_api(self,* args,** kwargs)\ n文件\”/ opt / odoo / odoo-server / openerp / addons / base / ir / ir_attachment .py \“,第318行,读取\ n self.check(cr,uid,ids,'read',context = context)\ n文件\”/ opt / odoo / odoo-server / openerp / api.py \ “,第268行,在包装器中\ n返回old_api(self,* args,** kwargs)\ n文件\”/ opt / odoo / odoo-server / openerp / addons / base / ir / ir_attachment.py \“,line 260,在check \ n raise except_orm(('拒绝访问'),(\“抱歉,您不能访问此文档 . \”))\ nexcept_orm :( u'Access Denied',u'Sorry,您不能访问此文档 . ') \ n“,”exception_type“:”except_osv“,”message“:”拒绝访问\ n停止,您不能访问此文档 . “,”name“:”openerp.exceptions.except_orm“,”arguments“:[ “拒绝访问”,“抱歉,您无权访问此文档 . ”]}}
继承模特
@http.route('/jobs/apply/<model("hr.job"):job>', type='http', auth="public", website=True)
def jobs_apply(self, job):
error = {}
default = {}
#Added by SDS 19022016
attachment = http.request.env['ir.attachment'].sudo().search([('name', '=', 'Application-Form-rev2.docx')])
#str_url = 'http://localhost:8069'+'/web/binary/saveas?model=ir.attachment&field=datas&filename_field=name&id='+str(attachment.id)
str_url = request.httprequest.host_url +'web/binary/saveas?model=ir.attachment&field=datas&filename_field=name&id='+str(attachment.id)
if 'website_hr_recruitment_bahia_error' in request.session:
error = request.session.pop('website_hr_recruitment_bahia_error')
default = request.session.pop('website_hr_recruitment_bahia_default')
return request.render("website_hr_recruitment_bahia.apply", {
'job': job,
'error': error,
'default': default,
'url_link': str_url,
})
并且继承了模板
<div t-attf-class="form-group #{error.get('first_name') and 'has-error' or ''}">
Click ”<a t-att-href="url_link" >Apply Now</a> ” to download, fill-out and upload below
<label class="col-md-3 col-sm-4 control-label" for="first_name">First Name</label>
<div class="col-md-7 col-sm-8">
<input type="text" t-att-value="default.get('first_name')" class="form-control" name="first_name" required="True"/>
</div>
</div>
我试图添加sudo访问权限但没有用,有人可以帮助我
谢谢
2 回答
请创建一个名为 ir.model.access.csv 的安全文件,将其添加到 openerp.py 中,如下所示 -
上面 security 是文件夹名称,文件 ir.model.access.csv 存在 .
并在 csv 文件中添加以下行 -
这应该解决访问问题 .
不幸的是,v8对
ir.attachment
对象有一个更严格的策略,它只允许Employee(base.group_user
)组读取所有文档,即用户必须登录才能访问文档 . 因此添加记录规则或访问控制列表规则对您没有帮助 .这里最好的解决方案是覆盖ir.attachment上的def check方法,并且更加放松地检查公开访问文档的安全性,或者你可以只是覆盖并且不会放置任何逻辑并使对象安全性由ir驱动 . 附件 . 或者您也可以让一些模型文档绕过安全检查 .
希望这会帮助你 .
贝斯茨