使基于某些条件限制对某些字段的读和/或写访问变得简单
odoo8-addon-base-mixin-restrict-field-access的Python项目详细描述
限制字段访问
编写此模块是为了帮助开发人员限制对 安全灵活的记录级别。
如果您不是开发人员,则此模块不适合您,因为您需要编写代码 为了实际使用它。
使用量
使用此模块,需要为其字段继承该混合 您希望限制并实现至少以下方法 有用的东西:
classResPartner(models.Model):# inherit from the mixin_inherit=['restrict.field.access.mixin','res.partner']_name='res.partner'@api.multidef_restrict_field_access_get_field_whitelist(self,action='read'):# return a whitelist (or a blacklist) of fields, depending on the# action passedwhitelist=['name','parent_id','is_company','firstname','lastname','infix','initials',]+super(ResPartner,self)\ ._restrict_field_access_get_field_whitelist(action=action)ifaction=='read':whitelist.extend(['section_id','user_id'])returnwhitelist@api.multidef_restrict_field_access_is_field_accessible(self,field_name,action='read'):# in case the whitelist is not enough, you can also decide for# specific records if an action can be carried out on it or notresult=super(ResPartner,self)\ ._restrict_field_access_is_field_accessible(field_name,action=action)ifresultornotself:returnresultreturnall(this.section_idinself.env.user.section_idsorthis.user_id==self.env.userforthisinself)@api.multi@api.onchange('section_id','user_id')@api.depends('section_id','user_id')def_compute_restrict_field_access(self):# if your decision depends on other fields, you probably need to# override this function in order to attach the correct onchange/# depends decoratorsreturnsuper(ResPartner,self)._compute_restrict_field_access()@api.modeldef_restrict_field_access_inject_restrict_field_access_domain(self,domain):# you also might want to decide with a domain expression which# records are visible in the first placedomain[:]=expression.AND([domain,['|',('section_id','in',self.env.user.section_ids.ids),('user_id','=',self.env.user.id),],])
这里的示例代码只允许读取 当前用户既不是销售人员也不是此合作伙伴的销售人员 团队。
阅读Mixin的评论,这是文档的一部分。也有一个 看看测试,这是关于如何使用这段代码的另一个例子。
有关详细信息,请访问:
已知问题/路线图
- 代码中包含一些应完成的任务
缺陷跟踪器
在GitHub Issues上跟踪错误。 如果出现问题,请检查是否已报告您的问题。 如果您首先发现了它,请提供详细且受欢迎的反馈,帮助我们粉碎它 here。
学分
贡献者
- 霍尔格·布鲁恩hbrunn@therp.nl>;
维护人员
此模块由OCA维护。
oca,或odoo社区协会,是一个非营利性组织 任务是支持odoo特性和 促进其广泛应用。
若要对此模块作出贡献,请访问https://odoo-community.org。