根据某些条件简单限制对某些字段的读取和/或写入访问
项目描述
限制字段访问
此模块编写是为了帮助开发者在记录级别以安全和灵活的方式限制对字段的访问。
如果您不是开发者,此模块对您来说不是必需的,因为您需要编写代码才能实际使用它。
用法
要使用此模块,您需要继承此混入模型,并实现以下至少一个方法以实现有用的功能
class ResPartner(models.Model):
# inherit from the mixin
_inherit = ['restrict.field.access.mixin', 'res.partner']
_name = 'res.partner'
@api.multi
def _restrict_field_access_get_field_whitelist(self, action='read'):
# return a whitelist (or a blacklist) of fields, depending on the
# action passed
whitelist = [
'name', 'parent_id', 'is_company', 'firstname', 'lastname',
'infix', 'initials',
] + super(ResPartner, self)\
._restrict_field_access_get_field_whitelist(action=action)
if action == 'read':
whitelist.extend(['section_id', 'user_id'])
return whitelist
@api.multi
def _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 not
result = super(ResPartner, self)\
._restrict_field_access_is_field_accessible(
field_name, action=action)
if result or not self:
return result
return all(this.section_id in self.env.user.section_ids or
this.user_id == self.env.user
for this in self)
@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 decorators
return super(ResPartner, self)._compute_restrict_field_access()
@api.model
def _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 place
domain[:] = expression.AND([
domain,
[
'|',
('section_id', 'in', self.env.user.section_ids.ids),
('user_id', '=', self.env.user.id),
],
])
下面的示例代码将仅允许读取当前用户既不是销售员也不是此合作伙伴销售团队成员的合作伙伴的少量字段。
阅读混入的注释,这是文档的一部分。还可以查看测试,这是另一个如何使用此代码的示例。
有关更多信息,请访问
已知问题/路线图
代码中包含一些待办事项,需要完成
错误追踪器
错误在GitHub Issues上跟踪。如果在那里遇到问题,请检查您的问题是否已被报告。如果是您首先发现的,请通过提供详细的反馈此处帮助我们解决。
致谢
贡献者
Holger Brunn <hbrunn@therp.nl>
维护者
此模块由OCA维护。
OCA,或Odoo社区协会,是一个非营利组织,其使命是支持Odoo功能的协作开发并推广其广泛使用。
为贡献此模块,请访问 https://odoo-community.org。
项目详情
关闭
哈希值 for odoo8_addon_base_mixin_restrict_field_access-8.0.1.0.0.99.dev10-py2-none-any.whl
算法 | 哈希摘要 | |
---|---|---|
SHA256 | 6607a993765b07834aa00eea4bf11e0b244623fe809c1a9ba4f902f2df211c8a |
|
MD5 | ea2b0b8ea4ff41bb265e3fc370e5287b |
|
BLAKE2b-256 | 62a017e73060b14c8fb2aa3048a47f7e50b9f863a6c61ce7f1c096fdcb0afb82 |