<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data noupdate="0">

    <!-- Privilege Definition -->
    <record model="res.groups.privilege" id="res_groups_privilege_seo_content">
        <field name="name">SEO Content</field>
        <field name="sequence">10</field>
        <field name="category_id" ref="otoolkit_seo_content.module_category_otoolkit_seo"/>
    </record>

    <!-- Security Groups -->
    <record id="group_seo_content_user" model="res.groups">
        <field name="name">User</field>
        <field name="sequence">10</field>
        <field name="comment">Can create and manage their own SEO content</field>
        <field name="privilege_id" ref="res_groups_privilege_seo_content"/>
    </record>

    <record id="group_seo_content_manager" model="res.groups">
        <field name="name">Administrator</field>
        <field name="sequence">20</field>
        <field name="comment">Can manage all SEO content and configure templates</field>
        <field name="privilege_id" ref="res_groups_privilege_seo_content"/>
        <field name="implied_ids" eval="[(4, ref('group_seo_content_user'))]"/>
    </record>

</data>
<data noupdate="1">

    <!-- Record Rules -->

    <!-- SEO Content: Users can see their own content -->
    <record model="ir.rule" id="seo_content_user_rule">
        <field name="name">SEO Content: User own records</field>
        <field name="model_id" search="[('model','=','otk.seo.content')]" model="ir.model"/>
        <field name="domain_force">[('create_uid', '=', user.id)]</field>
        <field name="groups" eval="[(4, ref('group_seo_content_user'))]"/>
        <field name="perm_unlink" eval="False"/>
    </record>

    <!-- SEO Content: Managers can see all content -->
    <record model="ir.rule" id="seo_content_manager_rule">
        <field name="name">SEO Content: Manager all records</field>
        <field name="model_id" search="[('model','=','otk.seo.content')]" model="ir.model"/>
        <field name="domain_force">[(1, '=', 1)]</field>
        <field name="groups" eval="[(4, ref('group_seo_content_manager'))]"/>
    </record>

    <!-- SEO Content Image: Users follow parent content access -->
    <record model="ir.rule" id="seo_content_image_user_rule">
        <field name="name">SEO Content Image: User own records</field>
        <field name="model_id" search="[('model','=','otk.seo.content.image')]" model="ir.model"/>
        <field name="domain_force">[('content_id.create_uid', '=', user.id)]</field>
        <field name="groups" eval="[(4, ref('group_seo_content_user'))]"/>
        <field name="perm_unlink" eval="False"/>
    </record>

    <record model="ir.rule" id="seo_content_image_manager_rule">
        <field name="name">SEO Content Image: Manager all records</field>
        <field name="model_id" search="[('model','=','otk.seo.content.image')]" model="ir.model"/>
        <field name="domain_force">[(1, '=', 1)]</field>
        <field name="groups" eval="[(4, ref('group_seo_content_manager'))]"/>
    </record>

    <!-- SEO Content Batch: Users can see their own batches -->
    <record model="ir.rule" id="seo_content_batch_user_rule">
        <field name="name">SEO Content Batch: User own records</field>
        <field name="model_id" search="[('model','=','otk.seo.content.batch')]" model="ir.model"/>
        <field name="domain_force">[('create_uid', '=', user.id)]</field>
        <field name="groups" eval="[(4, ref('group_seo_content_user'))]"/>
        <field name="perm_unlink" eval="False"/>
    </record>

    <record model="ir.rule" id="seo_content_batch_manager_rule">
        <field name="name">SEO Content Batch: Manager all records</field>
        <field name="model_id" search="[('model','=','otk.seo.content.batch')]" model="ir.model"/>
        <field name="domain_force">[(1, '=', 1)]</field>
        <field name="groups" eval="[(4, ref('group_seo_content_manager'))]"/>
    </record>

    <!-- SEO Content Batch Items: Follow parent batch access -->
    <record model="ir.rule" id="seo_content_batch_item_user_rule">
        <field name="name">SEO Content Batch Item: User own records</field>
        <field name="model_id" search="[('model','=','otk.seo.content.batch.item')]" model="ir.model"/>
        <field name="domain_force">[('batch_id.create_uid', '=', user.id)]</field>
        <field name="groups" eval="[(4, ref('group_seo_content_user'))]"/>
        <field name="perm_unlink" eval="False"/>
    </record>

    <record model="ir.rule" id="seo_content_batch_item_manager_rule">
        <field name="name">SEO Content Batch Item: Manager all records</field>
        <field name="model_id" search="[('model','=','otk.seo.content.batch.item')]" model="ir.model"/>
        <field name="domain_force">[(1, '=', 1)]</field>
        <field name="groups" eval="[(4, ref('group_seo_content_manager'))]"/>
    </record>

    <!-- SEO Content Versions: Follow parent content access -->
    <record model="ir.rule" id="seo_content_version_user_rule">
        <field name="name">SEO Content Version: User own records</field>
        <field name="model_id" search="[('model','=','otk.seo.content.version')]" model="ir.model"/>
        <field name="domain_force">[('content_id.create_uid', '=', user.id)]</field>
        <field name="groups" eval="[(4, ref('group_seo_content_user'))]"/>
        <field name="perm_write" eval="False"/>
        <field name="perm_create" eval="False"/>
        <field name="perm_unlink" eval="False"/>
    </record>

    <record model="ir.rule" id="seo_content_version_manager_rule">
        <field name="name">SEO Content Version: Manager all records</field>
        <field name="model_id" search="[('model','=','otk.seo.content.version')]" model="ir.model"/>
        <field name="domain_force">[(1, '=', 1)]</field>
        <field name="groups" eval="[(4, ref('group_seo_content_manager'))]"/>
    </record>

    <!-- SEO Reference Library: All users can read -->
    <record model="ir.rule" id="seo_reference_user_rule">
        <field name="name">SEO Reference: User read all</field>
        <field name="model_id" search="[('model','=','otk.seo.reference')]" model="ir.model"/>
        <field name="domain_force">[(1, '=', 1)]</field>
        <field name="groups" eval="[(4, ref('group_seo_content_user'))]"/>
        <field name="perm_write" eval="False"/>
        <field name="perm_create" eval="False"/>
        <field name="perm_unlink" eval="False"/>
    </record>

    <record model="ir.rule" id="seo_reference_manager_rule">
        <field name="name">SEO Reference: Manager full access</field>
        <field name="model_id" search="[('model','=','otk.seo.reference')]" model="ir.model"/>
        <field name="domain_force">[(1, '=', 1)]</field>
        <field name="groups" eval="[(4, ref('group_seo_content_manager'))]"/>
    </record>

    <!-- SEO Reference Tags: All users can read -->
    <record model="ir.rule" id="seo_reference_tag_user_rule">
        <field name="name">SEO Reference Tag: User read all</field>
        <field name="model_id" search="[('model','=','otk.seo.reference.tag')]" model="ir.model"/>
        <field name="domain_force">[(1, '=', 1)]</field>
        <field name="groups" eval="[(4, ref('group_seo_content_user'))]"/>
        <field name="perm_write" eval="False"/>
        <field name="perm_create" eval="False"/>
        <field name="perm_unlink" eval="False"/>
    </record>

    <record model="ir.rule" id="seo_reference_tag_manager_rule">
        <field name="name">SEO Reference Tag: Manager full access</field>
        <field name="model_id" search="[('model','=','otk.seo.reference.tag')]" model="ir.model"/>
        <field name="domain_force">[(1, '=', 1)]</field>
        <field name="groups" eval="[(4, ref('group_seo_content_manager'))]"/>
    </record>

</data>
</odoo>
