<?xml version="1.0" encoding="utf-8"?>
<openerp>
    <data>
        <!-- Rules -->
        <record id="view_rule_form" model="ir.ui.view">
            <field name="model">ir.rule</field>
            <field name="arch" type="xml">
                <form string="Record rules" version="7.0">
                  <sheet>
                    <group>
                        <group string="General">
                            <field name="name"/>
                            <field name="model_id"/>
                            <field name="active"/>
                        </group>
                        <group col="4" string="Access Rights">
                            <field name="perm_read"/>
                            <field name="perm_write"/>
                            <field name="perm_create"/>
                            <field name="perm_unlink"/>
                        </group>
                    </group>
                    <separator string="Rule Definition (Domain Filter)"/>
                    <field name="domain_force" colspan="2" nolabel="1"/>
                    <group string="Groups (no group = global)">
                        <field name="global"/>
                        <field name="groups" nolabel="1" colspan="4"/>
                    </group>
                    <group string="Interaction between rules">
                        <label  colspan="2"
                            string="Global rules (non group-specific) are restrictions, and cannot be bypassed. Group-local rules grant additional permissions, but are constrained within the bounds of global ones. The first group rules restrict further than global rules, but any additional group rule will add more permissions"/>
                        <label colspan="2"
                            string="Detailed algorithm:"/>
                        <label colspan="2"
                            string="1. Global rules are combined together with a logical AND operator, and with the result of the following steps"/>
                        <label colspan="2"
                            string="2. Group-specific rules are combined together with a logical OR operator"/>
                        <label colspan="2"
                            string="3. If user belongs to several groups, the results from step 2 are combined with logical OR operator"/>
                        <label colspan="2"
                            string="Example: GLOBAL_RULE_1 AND GLOBAL_RULE_2 AND ( (GROUP_A_RULE_1 OR GROUP_A_RULE_2) OR (GROUP_B_RULE_1 OR GROUP_B_RULE_2) )"/>
                    </group>
                   </sheet> 
                </form>
            </field>
        </record>
        <record id="view_rule_tree" model="ir.ui.view">
            <field name="model">ir.rule</field>
            <field name="arch" type="xml">
                <tree string="Record rules">
                    <field name="model_id"/>
                    <field name="name"/>
                    <field name="global"/>
                    <field name="domain_force"/>
                    <field name="perm_read"/>
                    <field name="perm_write"/>
                    <field name="perm_create"/>
                    <field name="perm_unlink"/>
                </tree>
            </field>
        </record>
        <record id="view_rule_search" model="ir.ui.view">
            <field name="model">ir.rule</field>
            <field name="arch" type="xml">
                <search string="Record Rules">
                    <field name="name" string="Record Rule"/>
                    <filter string="Global" icon="terp-stage" domain="[('global','=',True)]"/>
                    <separator/>
                    <filter string="Full Access Right" domain="[('perm_read','=',True),('perm_write','=',True),('perm_create','=',True),('perm_unlink','=',True)]"/>
                    <filter string="Read Access Right" domain="[('perm_read','=',True)]"/>
                    <filter string="Write Access Right" domain="[('perm_write','=',True)]"/>
                    <filter string="Create Access Right" domain="[('perm_create','=',True)]"/>
                    <filter string="Delete Access Right" domain="[('perm_unlink','=',True)]"/>
                    <field name="model_id"/>
                    <field name="groups"/>
                </search>
            </field>
        </record>

        <record id="action_rule" model="ir.actions.act_window">
            <field name="name">Record Rules</field>
            <field name="res_model">ir.rule</field>
            <field name="view_type">form</field>
            <field name="view_id" ref="view_rule_tree"/>
            <field name="search_view_id" ref="view_rule_search"/>
        </record>
        <menuitem action="action_rule" id="menu_action_rule" parent="base.menu_security" sequence="3"/>
    </data>
</openerp>
