Odoo 学些 【三】 安全性

先收藏一篇博文:http://www.cnblogs.com/crazyguo/p/6999408.html

Odoo 在安全层面上是非常灵活的,可以控制在不同层面上控制用户做些什么。同时我们也可以对增、读、写、删这四个基本操作来单独操作。

Odoo系统内置的一些用户组,在./openerp/addons/base/security/base_security.xml这个文件中定义:

  <record model="res.groups" id="group_erp_manager">
    <field name="name">Access Rights</field>
  </record>
  <record model="res.groups" id="group_system">
      <field name="name">Settings</field>
      <field name="implied_ids" eval="[(4, ref('group_erp_manager'))]"/>
      <field name="users" eval="[(4, ref('base.user_root'))]"/>
  </record>

  <record model="res.groups" id="group_user">
      <field name="name">Employee</field>
      <field name="users" eval="[(4, ref('base.user_root'))]"/>
  </record>

  <record model="res.groups" id="group_multi_company">
      <field name="name">Multi Companies</field>
  </record>

  <record model="res.groups" id="group_multi_currency">
      <field name="name">Multi Currencies</field>
  </record>

  <record model="res.groups" id="group_no_one">
      <field name="name">Technical Features</field>
  </record>

  <record id="group_sale_salesman" model="res.groups">
      <field name="name">User</field>
  </record>
  <record id="group_sale_manager" model="res.groups">
      <field name="name">Manager</field>
      <field name="implied_ids" eval="[(4, ref('group_sale_salesman'))]"/>
  </record>

数据模型定义在res_users.py中,主要字段如下:

  'users': fields.many2many('res.users', 'res_groups_users_rel', 'gid', 'uid', 'Users'),
  'model_access': fields.one2many('ir.model.access', 'group_id', 'Access Controls', copy=True),
  'rule_groups': fields.many2many('ir.rule', 'rule_group_rel',
  'group_id', 'rule_group_id', 'Rules', domain=[('global', '=', False)]),
  'menu_access': fields.many2many('ir.ui.menu', 'ir_ui_menu_group_rel', 'gid', 'menu_id', 'Access Menu'),
  'view_access': fields.many2many('ir.ui.view', 'ir_ui_view_group_rel', 'group_id', 'view_id', 'Views'), 
  'category_id': fields.many2one('ir.module.category', 'Application', select=True),

users: 指定了组里面的用户。

menu_access: 指定了组里面可访问的菜单,视图层面上。

view_access:指定了组里面的可访问的视图,视图层面上。

rule_groups: 指定了组里面的规则,记录级别,给定模型记录的子集,真实对象层面上。

model_access:指定了组里面的模型,对模型的访问的加以控制,真实对象层面上。

category_id: 指定了组所属的Odoo Module分类。

implied_ids:指定了从指定的组继承过来其权限。

视图层面

我们在 视图字段/视图菜单 级别可以这样做:

  • 对某些用户显示或隐藏字段
  • 使字段对某些用户只读,对某些用户可编辑
  • 对不同的用户,显示不同的变量来用于选择字段

添加groups属性即可,比如:。

   <menuitem id="main_budget_manage_menu" name="Budget Manage" groups="hrp_budget_manage.hrp_budgetm"/>

在字段安全层级上,要使用res.usersres.groups模型,这些模型是彼此是多对多的关系。

模型层面

这些访问权利通常会被定义在ir.model.access.csv中,这些数据会被存储在ir_model_acess表中,例如:

id,name,model_id/id,group_id/id,perm_read,perm_write,perm_create,perm_unlink
access_idea_idea,idea.idea,model_idea_idea,base.group_user,1,1,1,0

id: 外部标示ID,也就是XML ID,唯一性。
name:描述性标题,最好醒目,唯一。
model_id:我们要访问的数据模型的外部标识ID,ORM默认会自动生成这个ID。
group_id:要赋予的权限组,XML ID。
perm_curd: 是具体的权限分配。

记录层面

      'global': fields.function(_get_value, string='Global', type='boolean', store=True, help="If no group is specified the rule is global and applied to everyone"),
      'groups': fields.many2many('res.groups', 'rule_group_rel', 'rule_group_id', 'group_id', 'Groups'),
      'domain_force': fields.text('Domain'),
      'domain': fields.function(_domain_force_get, string='Domain', type='binary'),

global:如果未指定,将会将该规则设置该字段为全局。
groups: 安全规则应用的用户组。
domain_force': 筛选域,文本。
domain: 从domain_force来计算范化筛选域。

posted @ 2018-05-08 18:33  白守敬  阅读(736)  评论(0编辑  收藏  举报