Skip to content

Commit

Permalink
[IMP] spreadsheet_oca: add possibility to give write or read access, …
Browse files Browse the repository at this point in the history
…by groups and not only by users
  • Loading branch information
legalsylvain committed Jan 27, 2025
1 parent 33aeaa4 commit 9506a4e
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 12 deletions.
14 changes: 14 additions & 0 deletions spreadsheet_oca/models/spreadsheet_spreadsheet.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,27 @@ class SpreadsheetSpreadsheet(models.Model):
column2="user_id",
string="Contributors",
)
contributor_group_ids = fields.Many2many(
"res.groups",
relation="spreadsheet_group_contributor",
column1="spreadsheet_id",
column2="group_id",
string="Contributors Groups",
)
reader_ids = fields.Many2many(
"res.users",
relation="spreadsheet_reader",
column1="spreadsheet_id",
column2="user_id",
string="Readers",
)
reader_group_ids = fields.Many2many(
"res.groups",
relation="spreadsheet_group_reader",
column1="spreadsheet_id",
column2="group_id",
string="Readers Groups",
)

company_id = fields.Many2one(
comodel_name="res.company",
Expand Down
8 changes: 6 additions & 2 deletions spreadsheet_oca/security/security.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,19 @@
<field name="name">Spreadsheet Contributor</field>
<field name="model_id" ref="model_spreadsheet_spreadsheet" />
<field name="groups" eval="[(4, ref('spreadsheet_oca.group_user'))]" />
<field name="domain_force">[('contributor_ids','=', user.id)]</field>
<field
name="domain_force"
>['|', ('contributor_ids','=', user.id), ('contributor_group_ids','in', user.groups_id.ids)]</field>
<field name="perm_create" eval="False" />
<field name="perm_unlink" eval="False" />
</record>
<record model="ir.rule" id="spreadsheet_reader_rule">
<field name="name">Spreadsheet Reader</field>
<field name="model_id" ref="model_spreadsheet_spreadsheet" />
<field name="groups" eval="[(4, ref('spreadsheet_oca.group_user'))]" />
<field name="domain_force">[('reader_ids','=', user.id)]</field>
<field
name="domain_force"
>['|', ('reader_ids','=', user.id), ('reader_group_ids','in', user.groups_id.ids)]</field>
<field name="perm_write" eval="False" />
<field name="perm_create" eval="False" />
<field name="perm_unlink" eval="False" />
Expand Down
36 changes: 26 additions & 10 deletions spreadsheet_oca/views/spreadsheet_spreadsheet.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,32 @@
<field name="name" placeholder="Name" />
</h1>
<group>
<field name="owner_id" />
<field name="company_id" groups="base.group_multi_company" />
<field name="contributor_ids" widget="many2many_tags" />
<field name="reader_ids" widget="many2many_tags" />
<field
name="data"
filename="filename"
groups="base.group_no_one"
/>
<field name="filename" invisible="1" />
<group colspan="4">
<field name="owner_id" />
<field
name="company_id"
groups="base.group_multi_company"
/>
</group>
<group string="Write Access">
<field name="contributor_ids" widget="many2many_tags" />
<field
name="contributor_group_ids"
widget="many2many_tags"
/>
</group>
<group string="Read Access">
<field name="reader_ids" widget="many2many_tags" />
<field name="reader_group_ids" widget="many2many_tags" />
</group>
<group colspan="4">
<field
name="data"
filename="filename"
groups="base.group_no_one"
/>
<field name="filename" invisible="1" />
</group>
</group>
</sheet>
</form>
Expand Down

0 comments on commit 9506a4e

Please sign in to comment.