Passa al contenuto
Menu
È necessario essere registrati per interagire con la community.
La domanda è stata contrassegnata
3 Risposte
7595 Visualizzazioni

I have several groups of users and one of those groups is 'group_reporter'. And this group can create requests and report it. While they create a new request it will be in 'Draft' stage and once they report it, it will be moved to 'Report'.

They should only be able to edit the request when it is in the 'Draft' stage. In the 'Report' stage it has to be in read-only state.

So I've written these two record rules:-

</record> -->
<!--
Name: Request Reporter - Edit
Group(s): group_reporter
Records: Incidents
Condition: if (user is owner of the record AND incident is in Draft stage)
Access Rights: Read/Write/Create
-->
<record id="rule_request_basic_reporter_edit" model="ir.rule">
<field name="name">Request Reporter - Edit</field>
<field name="model_id" ref="generic_request.model_request_request"/>
<field name="domain_force">[('created_by_id', '=', user.id), ('stage_type_name', '=', 'Draft')]</field>
<field name="groups" eval="[(4, ref('generic_request.group_reporter'))]"/>
<field eval="0" name="perm_unlink"/>
<field eval="1" name="perm_write"/>
<field eval="1" name="perm_read"/>
<field eval="1" name="perm_create"/>
</record>

<!--
Name: Request Reporter - Edit
Group(s): group_reporter
Records: Incidents
Condition: if (user is owner of the record AND (incident is in Report stage))
Access Rights: Read-only
-->
<record id="rule_request_basic_reporter_read_only" model="ir.rule">
<field name="name">Request Reporter - Read-only</field>
<field name="model_id" ref="generic_request.model_request_request"/>
<field name="domain_force">[('created_by_id', '=', user.id),('stage_type_name', '=', 'Report')]</field>
<field name="groups" eval="[(4, ref('generic_request.group_reporter'))]"/>
<field eval="0" name="perm_unlink"/>
<field eval="0" name="perm_write"/>
<field eval="1" name="perm_read"/>
<field eval="0" name="perm_create"/>
</record>

But for some reason I am still able to edit the requests that are in 'Report' stage. I'm not sure what's wrong.

Avatar
Abbandona
Risposta migliore

record rules will work as follows:

  1. The logical operation for global record (no groups) rules is 'AND' 
  2. The logical operation for groups record rules is 'OR'


Avatar
Abbandona
Risposta migliore

It's difficult to offer advice without knowing the full setup, but is it possible that the users are members of another user access group that has access to this Model and the Record Rules (for that group) are less restrictive?

Avatar
Abbandona
Risposta migliore

I haven't checked your code but sometimes the record rule apply only when you restart the server. The result actually stored in pre-cache and it will not apply instantly. 

Avatar
Abbandona
Post correlati Risposte Visualizzazioni Attività
1
nov 24
1440
1
set 24
1706
2
ott 22
11686
0
ago 21
2331
1
giu 19
4232