跳到正文
Skillpedia
安全48k · #5352

odoo-security-rules

它能做什么

这个工具帮你设置在 Odoo 中谁可以查看和修改信息。它会创建规则,确保只有合适的人才能访问对应的数据。

适用场景

  • ✓为 Odoo 新的自定义模块设置访问权限时。
  • ✓希望用户只能查看自己的数据或所在公司的数据时。
  • ✓修复“Access Denied”或“You are not allowed to access”之类的错误时。

技能链接

https://github.com/sickn33/agentic-awesome-skills/blob/main/plugins/agentic-awesome-skills-claude/skills/odoo-security-rules/SKILL.md

复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。

使用方法

最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。

可直接粘贴的消息

请用这个技能帮我:https://github.com/sickn33/agentic-awesome-skills/blob/main/plugins/agentic-awesome-skills-claude/skills/odoo-security-rules/SKILL.md 阅读该链接中的 SKILL.md 文件,并在我的任务中按照它的说明来做。
想让你的 AI 自己找到这样的技能吗?安装免费的 Skillpedia MCP:只需一行,每次任务前它都会在 15,000+ 个技能中搜索。1 分钟完成安装 →

可以这样问 AI

“我需要设置权限,让普通用户只能看到自己的销售订单,看不到别人的。”

每周 5 个新技能,1 分钟读完。

工作原理

你描述希望的权限规则,工具会生成相应代码,让 Odoo 理解并执行这些安全规则。

技术内容(原始 SKILL.md)

作者在 GitHub 上的英文原文。

Odoo Security Rules

Overview

Security in Odoo is managed at two levels: model-level access (who can read/write which models) and record-level rules (which records a user can see). This skill helps you write correct ir.model.access.csv entries and ir.rule domain-based record rules.

When to Use This Skill

  • Setting up access rights for a new custom module.
  • Restricting records so users only see their own data or their company's data.
  • Debugging "Access Denied" or "You are not allowed to access" errors.
  • Implementing multi-company record visibility rules.

How It Works

  1. Activate: Mention @odoo-security-rules and describe the access scenario.
  2. Generate: Get correct CSV access lines and XML record rules.
  3. Debug: Paste an access error and get a diagnosis with the fix.

Examples

Example 1: ir.model.access.csv

id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
access_hospital_patient_user,hospital.patient.user,model_hospital_patient,base.group_user,1,0,0,0
access_hospital_patient_manager,hospital.patient.manager,model_hospital_patient,base.group_erp_manager,1,1,1,1

Note: Use base.group_erp_manager for ERP managers, not base.group_system — that group is reserved for Odoo's technical superusers. Always create a custom group for module-specific manager roles:

<record id="group_hospital_manager" model="res.groups">
    <field name="name">Hospital Manager</field>
    <field name="category_id" ref="base.module_category_hidden"/>
</record>

Example 2: Record Rule — Users See Only Their Own Records

<record id="rule_hospital_patient_own" model="ir.rule">
    <field name="name">Hospital Patient: Own Records Only</field>
    <field name="model_id" ref="model_hospital_patient"/>
    <field name="domain_force">[('create_uid', '=', user.id)]</field>
    <field name="groups" eval="[(4, ref('base.group_user'))]"/>
    <field name="perm_read" eval="True"/>
    <field name="perm_write" eval="True"/>
    <field name="perm_create" eval="True"/>
    <field name="perm_unlink" eval="False"/>
</record>

Important: If you omit <field name="groups">, the rule becomes global and applies to ALL users, including admins. Always assign a group unless you explicitly intend a global restriction.

Example 3: Multi-Company Record Rule

<record id="rule_hospital_patient_company" model="ir.rule">
    <field name="name">Hospital Patient: Multi-Company</field>
    <field name="model_id" ref="model_hospital_patient"/>
    <field name="domain_force">
        ['|', ('company_id', '=', False),
               ('company_id', 'in', company_ids)]
    </field>
    <field name="groups" eval="[(4, ref('base.group_user'))]"/>
</record>

Best Practices

  • ✅ Do: Start with the most restrictive access and open up as needed.
  • ✅ Do: Use company_ids (plural) in multi-company rules — it includes all companies the user belongs to.
  • ✅ Do: Test rules using a non-admin user in debug mode — sudo() bypasses all record rules entirely.
  • ✅ Do: Create dedicated security groups per module rather than reusing core Odoo groups.
  • ❌ Don't: Give perm_unlink = 1 to regular users unless deletion is explicitly required by the business process.
  • ❌ Don't: Leave group_id blank in ir.model.access.csv unless you intend to grant public (unauthenticated) access.
  • ❌ Don't: Use base.group_system for module managers — that grants full technical access including server configurations.

Limitations

  • Does not cover field-level access control (ir.model.fields read/write restrictions) — those require custom OWL or Python overrides.
  • Portal and public user access rules have additional nuances not fully covered here; test carefully with base.group_portal.
  • Record rules are bypassed by sudo() — any code running in superuser context ignores all ir.rule entries.
  • Does not cover row-level security via PostgreSQL (RLS) — Odoo manages all security at the ORM layer.
常见问题

`ir.model.access.csv` 是什么?

这是一个文件,用来定义对 Odoo 中不同类型信息(即模型)的通用访问权限。

“记录规则”(`ir.rule`)是什么?

这是更具体的规则,用来决定用户可以查看或修改哪些记录(数据行),条件可以是“属于我所在的公司”或“由我创建”等。

为什么不应该使用 `base.group_system`?

`base.group_system` 用户组面向 Odoo 的技术超级管理员,拥有完全访问权限,包括敏感的系统配置。更好的做法是为模块管理员创建专门的用户组。

详情

作者的原始描述

Expert in Odoo access control: ir.model.access.csv, record rules (ir.rule), groups, and multi-company security patterns.

repo: sickn33/agentic-awesome-skills

热度

GitHub 星标
48k
排名
#5352
许可证
MIT
更新时间
2026/10/15

这个技能有用吗?

0

登录 后即可投票。

评论

  • …

同一仓库的更多技能

相似技能