使基于某些条件限制对某些字段的读和/或写访问变得简单

odoo8-addon-base-mixin-restrict-field-access的Python项目详细描述


License: AGPL-3

限制字段访问

编写此模块是为了帮助开发人员限制对 安全灵活的记录级别。

如果您不是开发人员,则此模块不适合您,因为您需要编写代码 为了实际使用它。

使用量

使用此模块,需要为其字段继承该混合 您希望限制并实现至少以下方法 有用的东西:

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

学分

贡献者

维护人员

Odoo Community Association

此模块由OCA维护。

oca,或odoo社区协会,是一个非营利性组织 任务是支持odoo特性和 促进其广泛应用。

若要对此模块作出贡献,请访问https://odoo-community.org

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
通过GWT JSNI传递Java对象时发生javascript错误   java Spring启动项目wildfly服务器失败   java如何进行会话来存储Id?   javajpa/hibernate如何通过带注释的外键映射元素集合   Java将字节[]转换为双[],反之亦然   eclipse显示Java双值   java如何正确读取socket数据包   是否存在用于集合处理的Java库?   javacom。太阳jna。无法将指针强制转换为com。太阳jna。站台win32。温迪夫。LPARAM   java Eclipse插件开发。我可以在插件中使用已经存在的jar文件吗?   分析Java错误:找不到符号变量   java如何使按钮摆动以进行大的处理   如何通过传递bucket name和file name从java中的minio服务器下载多个文件   JavaScrollPane JavaFX使其滚动更多?   java无法加载C:\Users\username\AppData\Local\Android\Sdk\buildtools\28.0.3\lib\dx。罐子   JavaSwing中是否有一个“组框”等价物?   java使用slf4j和log4j与单独使用log4j相比,是否存在性能开销?   java模式和匹配:格式化文本文件   JTable行增长的java问题