Skip to content

Commit

Permalink
[FIX] dms: Allow share (directories and files) without 'Contact creat…
Browse files Browse the repository at this point in the history
…ion' permission

Extra changes: Replace Share buttons with actions

Steps to reproduce:
 - Go to Settings > Users & Companies > Users and create a user only with Documents > Manager permission.
(User must not have the Extra Rights > Contact Creation permission).
 - Go to Documents and go into a directory form view and click on "Share" button.
 - An access error is displayed
  • Loading branch information
victoralmau authored and tva-subteno-it committed Jun 20, 2024
1 parent fd98341 commit 28b104c
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 12 deletions.
1 change: 1 addition & 0 deletions dms/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"views/dms_portal_templates.xml",
# Wizard
"wizards/wizard_dms_file_move_views.xml",
"wizards/wizard_dms_share_views.xml",
],
"assets": {
"mail.assets_messaging": [
Expand Down
1 change: 1 addition & 0 deletions dms/security/ir.model.access.csv
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,4 @@ access_security_access_groups_user,access_security_access_groups_user,model_dms_
access_security_access_groups_dms_user,access_security_access_groups_dms_user,model_dms_access_group,group_dms_user,1,1,1,1

access_wizard_dms_file_move,access_wizard_dms_file_move,model_wizard_dms_file_move,group_dms_user,1,1,1,1
access_wizard_dms_share,access_wizard_dms_share,model_wizard_dms_share,group_dms_manager,1,1,1,0
2 changes: 2 additions & 0 deletions dms/tests/test_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from odoo.exceptions import UserError
from odoo.tests import new_test_user
from odoo.tests.common import users
from odoo.tools import mute_logger

from .common import StorageFileBaseCase

Expand Down Expand Up @@ -48,6 +49,7 @@ def test_file_access(self):
self.assertIn(self.sub_directory_x.id, dms_directories.ids)

@users("dms-manager", "dms-user")
@mute_logger("odoo.models.unlink")
def test_content_file(self):
lobject_file = self.create_file(directory=self.directory)
self.assertTrue(lobject_file.content)
Expand Down
6 changes: 0 additions & 6 deletions dms/views/directory.xml
Original file line number Diff line number Diff line change
Expand Up @@ -402,12 +402,6 @@
<field name="arch" type="xml">
<form>
<header>
<button
name="%(portal.portal_share_action)d"
string="Share"
type="action"
class="oe_highlight oe_read_only"
/>
</header>
<sheet>
<div class="oe_button_box" name="button_box">
Expand Down
6 changes: 0 additions & 6 deletions dms/views/dms_file.xml
Original file line number Diff line number Diff line change
Expand Up @@ -378,12 +378,6 @@
string="Unlock"
attrs="{'invisible':['|',('is_locked', '=', False),('is_lock_editor', '=', False)]}"
/>
<button
name="%(portal.portal_share_action)d"
string="Share"
type="action"
class="oe_highlight oe_read_only"
/>
</header>
<sheet>
<widget
Expand Down
1 change: 1 addition & 0 deletions dms/wizards/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
from . import wizard_dms_file_move
from . import wizard_dms_share
19 changes: 19 additions & 0 deletions dms/wizards/wizard_dms_share.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Copyright 2024 Tecnativa - Víctor Martínez
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import api, models


class WizardDmsShare(models.TransientModel):
_name = "wizard.dms.share"
_inherit = "portal.share"
_description = "Wizard for sharing DMS records"

@api.model
def _selection_target_model(self):
return [
(model.model, model.name)
for model in self.env["ir.model"]
.sudo()
.search([("model", "in", ("dms.directory", "dms.file"))])
]
28 changes: 28 additions & 0 deletions dms/wizards/wizard_dms_share_views.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo>
<record id="wizard_dms_share_form" model="ir.ui.view">
<field name="name">wizard.dms.share.form</field>
<field name="model">wizard.dms.share</field>
<field name="inherit_id" ref="portal.portal_share_wizard" />
<field name="mode">primary</field>
<field name="arch" type="xml">
<field name="res_model" position="attributes">
<attribute name="invisible">1</attribute>
</field>
</field>
</record>
<record id="wizard_dms_directory_share_action" model="ir.actions.act_window">
<field name="name">Share</field>
<field name="res_model">wizard.dms.share</field>
<field name="binding_model_id" ref="model_dms_directory" />
<field name="view_mode">form</field>
<field name="target">new</field>
</record>
<record id="wizard_dms_file_share_action" model="ir.actions.act_window">
<field name="name">Share</field>
<field name="res_model">wizard.dms.share</field>
<field name="binding_model_id" ref="model_dms_file" />
<field name="view_mode">form</field>
<field name="target">new</field>
</record>
</odoo>

0 comments on commit 28b104c

Please sign in to comment.