Skip to content

Commit

Permalink
[IMP] fieldservice: basic security
Browse files Browse the repository at this point in the history
- Add a lower security group whose members only have access to their own
field service orders.
- Add related partner to location and worker forms to easily check the
relationship.
  • Loading branch information
chienandalu authored and brian10048 committed Nov 13, 2023
1 parent 49b174f commit d59436d
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 17 deletions.
24 changes: 12 additions & 12 deletions fieldservice/security/ir.model.access.csv
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
access_fsm_stage_fsm_user,fsm.stage.user,model_fsm_stage,fieldservice.group_fsm_user,1,0,0,0
access_fsm_stage_fsm_user,fsm.stage.user,model_fsm_stage,fieldservice.group_fsm_user_own,1,0,0,0
access_fsm_stage_fsm_manager,fsm.stage.manager,model_fsm_stage,fieldservice.group_fsm_manager,1,1,1,1
access_fsm_tag_fsm_user,fsm.tag.user,model_fsm_tag,fieldservice.group_fsm_user,1,0,0,0
access_fsm_tag_fsm_user,fsm.tag.user,model_fsm_tag,fieldservice.group_fsm_user_own,1,0,0,0
access_fsm_tag_fsm_manager,fsm.tag.manager,model_fsm_tag,fieldservice.group_fsm_manager,1,1,1,1
access_fsm_person_user,fsm.person.user,model_fsm_person,fieldservice.group_fsm_user,1,1,0,0
access_fsm_person_user,fsm.person.user,model_fsm_person,fieldservice.group_fsm_user_own,1,1,0,0
access_fsm_person_manager,fsm.person.manager,model_fsm_person,fieldservice.group_fsm_manager,1,1,1,1
access_fsm_location_user,fsm.location.user,model_fsm_location,fieldservice.group_fsm_user,1,1,0,0
access_fsm_location_user,fsm.location.user,model_fsm_location,fieldservice.group_fsm_user_own,1,1,0,0
access_fsm_location_dispatcher,fsm.location.dispatcher,model_fsm_location,fieldservice.group_fsm_dispatcher,1,1,1,0
access_fsm_order_user,fsm.order.user,model_fsm_order,fieldservice.group_fsm_user,1,1,0,0
access_fsm_order_user,fsm.order.user,model_fsm_order,fieldservice.group_fsm_user_own,1,1,0,0
access_fsm_order_dispatcher,fsm.order.dispatcher,model_fsm_order,fieldservice.group_fsm_dispatcher,1,1,1,1
access_fsm_equipment_fsm_user,fsm.equipment.user,model_fsm_equipment,fieldservice.group_fsm_user,1,0,0,0
access_fsm_equipment_fsm_user,fsm.equipment.user,model_fsm_equipment,fieldservice.group_fsm_user_own,1,0,0,0
access_fsm_equipment_fsm_manager,fsm.equipment.manager,model_fsm_equipment,fieldservice.group_fsm_manager,1,1,1,1
access_fsm_category_user,fsm.category.user,model_fsm_category,fieldservice.group_fsm_user,1,0,0,0
access_fsm_category_user,fsm.category.user,model_fsm_category,fieldservice.group_fsm_user_own,1,0,0,0
access_fsm_category_manager,fsm.category.manager,model_fsm_category,fieldservice.group_fsm_manager,1,1,1,1
access_fsm_template_user,fsm.template.user,model_fsm_template,fieldservice.group_fsm_user,1,0,0,0
access_fsm_template_user,fsm.template.user,model_fsm_template,fieldservice.group_fsm_user_own,1,0,0,0
access_fsm_template_manager,fsm.template.manager,model_fsm_template,fieldservice.group_fsm_manager,1,1,1,1
access_fsm_team_user,fsm.team.user,model_fsm_team,fieldservice.group_fsm_user,1,0,0,0
access_fsm_team_user,fsm.team.user,model_fsm_team,fieldservice.group_fsm_user_own,1,0,0,0
access_fsm_team_manager,fsm.team.manager,model_fsm_team,fieldservice.group_fsm_manager,1,1,1,1
access_fsm_location_person_user,fsm.location.person.user,model_fsm_location_person,fieldservice.group_fsm_user,1,1,0,0
access_fsm_location_person_user,fsm.location.person.user,model_fsm_location_person,fieldservice.group_fsm_user_own,1,1,0,0
access_fsm_location_person_manager,fsm.location.person.manager,model_fsm_location_person,fieldservice.group_fsm_manager,1,1,1,1
access_fsm_order_type_user,fsm.order.type.user,model_fsm_order_type,fieldservice.group_fsm_user,1,1,0,0
access_fsm_order_type_user,fsm.order.type.user,model_fsm_order_type,fieldservice.group_fsm_user_own,1,1,0,0
access_fsm_order_type_manager,fsm.order.type.manager,model_fsm_order_type,fieldservice.group_fsm_manager,1,1,1,1
access_fsm_calendar_filter,fsm.calendar.filter.user,model_fsm_person_calendar_filter,fieldservice.group_fsm_user,1,1,1,1
access_fsm_calendar_filter,fsm.calendar.filter.user,model_fsm_person_calendar_filter,fieldservice.group_fsm_user_own,1,1,1,1
access_fsm_wizard,access_fsm_wizard,model_fsm_wizard,fieldservice.group_fsm_dispatcher,1,1,1,0
15 changes: 15 additions & 0 deletions fieldservice/security/ir_rule.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,21 @@
name="domain_force"
>['|',('company_id','=',False),('company_id', 'in', company_ids)]</field>
</record>

<record id="fsm_order_own_rule" model="ir.rule">
<field name="name">FSM Orders Entry (only own)</field>
<field name="model_id" ref="model_fsm_order"/>
<field name="domain_force">['|',('person_id.user_ids','=',user.id),('person_id','=',False)]</field>
<field name="groups" eval="[(4, ref('fieldservice.group_fsm_user_own'))]"/>
</record>

<record id="fsm_order_user" model="ir.rule">
<field name="name">FSM Orders Entry</field>
<field name="model_id" ref="model_fsm_order"/>
<field name="domain_force">[(1, '=', 1)]</field>
<field name="groups" eval="[(4, ref('fieldservice.group_fsm_user'))]"/>
</record>

<record id="fsm_template_comp_rule" model="ir.rule">
<field name="name">FSM Templates Entry</field>
<field name="model_id" ref="model_fsm_template" />
Expand Down
10 changes: 8 additions & 2 deletions fieldservice/security/res_groups.xml
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
<odoo>
<!-- FSM groups -->
<record id="group_fsm_user_own" model="res.groups">
<field name="name">User (only own documents)</field>
<field name="category_id" ref="fsm"/>
<field name="implied_ids" eval="[(4, ref('base.group_user'))]"/>
</record>

<record id="group_fsm_user" model="res.groups">
<field name="name">User</field>
<field name="category_id" ref="fsm" />
<field name="implied_ids" eval="[(4, ref('base.group_user'))]" />
<field name="category_id" ref="fsm"/>
<field name="implied_ids" eval="[(4, ref('fieldservice.group_fsm_user_own'))]"/>
</record>
<record id="group_fsm_dispatcher" model="res.groups">
<field name="name">Dispatcher</field>
Expand Down
1 change: 1 addition & 0 deletions fieldservice/views/fsm_location.xml
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@
<group id="main-left">
<field name="id" invisible="1" />
<field name="fsm_parent_id" domain="[('id', '!=', id)]" />
<field name="partner_id" groups="base.group_no_one" readonly="1" />
<field name="owner_id" />
<field
name="contact_id"
Expand Down
2 changes: 1 addition & 1 deletion fieldservice/views/fsm_order.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
string="Complete"
class="oe_highlight"
type="object"
groups="fieldservice.group_fsm_user"
groups="fieldservice.group_fsm_user_own"
attrs="{'invisible': [('stage_id', 'in', (%(fieldservice.fsm_stage_completed)d, %(fieldservice.fsm_stage_cancelled)d))]}"
/>
<button
Expand Down
1 change: 1 addition & 0 deletions fieldservice/views/fsm_person.xml
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@
</h1>
<group>
<group>
<field name="partner_id" groups="base.group_no_one" readonly="1" />
<field
name="category_ids"
widget="many2many_tags"
Expand Down
2 changes: 1 addition & 1 deletion fieldservice/views/menu.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
id="root"
name="Field Service"
sequence="10"
groups="group_fsm_user"
groups="group_fsm_user_own"
web_icon="fieldservice,static/description/icon.png"
/>
<menuitem id="dashboard" name="Dashboard" sequence="10" parent="root" />
Expand Down
3 changes: 2 additions & 1 deletion fieldservice/views/res_partner.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
<field name="name">res.partner.fsm.form</field>
<field name="model">res.partner</field>
<field name="inherit_id" ref="base.view_partner_form" />
<field name="groups_id" eval="[(4, ref('group_fsm_user_own'))]" />
<field name="arch" type="xml">
<div name="button_box" position="inside">
<button
Expand All @@ -27,7 +28,7 @@
name="action_open_owned_locations"
icon="fa-map-marker"
context="{'default_owner_id': active_id}"
groups="fieldservice.group_fsm_user"
groups="fieldservice.group_fsm_user_own"
>
<field
string="Owned Locations"
Expand Down

0 comments on commit d59436d

Please sign in to comment.