diff --git a/formio/models/formio_builder.py b/formio/models/formio_builder.py index 4a62218c..fe12d64b 100644 --- a/formio/models/formio_builder.py +++ b/formio/models/formio_builder.py @@ -79,6 +79,9 @@ class Builder(models.Model): version = fields.Integer("Version", required=True, readonly=True, default=1) version_comment = fields.Text("Version Comment") user_id = fields.Many2one('res.users', string='Assigned user', track_visibility='onchange') + partner_ids = fields.Many2many('res.partner', string='Exclusive to partners', + help='Give access only to users related to this partner (either linked directly to the partner or to its children). If left empty, this restriction doesn\'t apply.') + allowed_user_ids = fields.Many2many('res.users', compute='_compute_allowed_user_ids', store=True) forms = fields.One2many('formio.form', 'builder_id', string='Forms') portal = fields.Boolean("Portal", track_visibility='onchange', help="Form is accessible by assigned portal user") portal_submit_done_url = fields.Char( @@ -246,6 +249,18 @@ def _compute_display_fields(self): r.display_name_full = _("{title} (state: {state} - version: {version})").format( title=r.title, state=r.display_state, version=r.version) + @api.depends('partner_ids') + def _compute_allowed_user_ids(self): + for r in self: + user_domain = [] + + if r.partner_ids: + partner_ids = r.partner_ids.mapped('commercial_partner_id.id') + r.partner_ids.mapped('id') + user_domain = [('partner_id', 'in', partner_ids)] + + user_ids = self.env['res.users'].search(user_domain) + r.allowed_user_ids = [(6, 0, user_ids.ids)] + @api.depends('public') def _compute_public_url(self): for r in self: @@ -308,7 +323,7 @@ def action_obsolete(self): @api.returns('self', lambda value: value) def copy_as_new_version(self): """Get last version for builder-forms by traversing-up on parent_id""" - + self.ensure_one() builder = self @@ -375,7 +390,7 @@ def _get_js_options(self): # only set language if exist in i18n translations if options['i18n'].get(language): options['language'] = language - + return options def _get_js_params(self): diff --git a/formio/security/formio_security.xml b/formio/security/formio_security.xml index bd71469e..f8148918 100644 --- a/formio/security/formio_security.xml +++ b/formio/security/formio_security.xml @@ -16,16 +16,22 @@ License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html) --> + + User: Partner forms + + + + User: All forms - + Admin - + diff --git a/formio/security/ir_model_access.xml b/formio/security/ir_model_access.xml index 6dc750d3..06a9ad87 100644 --- a/formio/security/ir_model_access.xml +++ b/formio/security/ir_model_access.xml @@ -36,6 +36,16 @@ See LICENSE file for full copyright and licensing details. --> + + formio.builder: Partner forms + + + + + + + + formio.builder: Portal User @@ -77,6 +87,16 @@ See LICENSE file for full copyright and licensing details. --> + + formio.form: Partner forms + + + + + + + + formio.form: Portal User @@ -118,6 +138,16 @@ See LICENSE file for full copyright and licensing details. --> + + formio.version: User partner forms + + + + + + + + formio.version: Portal User @@ -159,6 +189,16 @@ See LICENSE file for full copyright and licensing details. --> + + formio.version.asset: User partner forms + + + + + + + + formio.version.asset: Portal User @@ -242,6 +282,16 @@ See LICENSE file for full copyright and licensing details. --> + + formio.translation.source: User partner forms + + + + + + + + formio.translation.source: Portal User @@ -251,7 +301,7 @@ See LICENSE file for full copyright and licensing details. --> - + formio.translation: Admin @@ -282,6 +332,16 @@ See LICENSE file for full copyright and licensing details. --> + + formio.translation: User partner forms + + + + + + + + formio.translation: Portal User @@ -323,6 +383,16 @@ See LICENSE file for full copyright and licensing details. --> + + formio.res.model: User partner forms + + + + + + + + formio.res.model: Portal User @@ -364,6 +434,16 @@ See LICENSE file for full copyright and licensing details. --> + + formio.builder.translation: User partner forms + + + + + + + + formio.builder.translation: Portal User diff --git a/formio/security/ir_rule.xml b/formio/security/ir_rule.xml index 468f9728..a3a2846c 100644 --- a/formio/security/ir_rule.xml +++ b/formio/security/ir_rule.xml @@ -4,6 +4,7 @@ See LICENSE file for full copyright and licensing details. --> + formio.form: User all forms @@ -26,6 +27,17 @@ See LICENSE file for full copyright and licensing details. --> [('user_id', '=', user.id)] + + formio.form: User partner forms + + + + + + + [('builder_id.allowed_user_ids', '=', user.id)] + + formio.form unlink: User assigned forms @@ -38,7 +50,7 @@ See LICENSE file for full copyright and licensing details. --> [('create_uid', '=', user.id), ('user_id', '=', user.id), ('state', '!=', 'COMPLETE')] - + formio.form read, write: Portal User @@ -67,6 +79,18 @@ See LICENSE file for full copyright and licensing details. --> + + + formio.builder: User partner forms + + + + + + + [('allowed_user_ids', '=', user.id)] + + Attachments of completed Forms can't be deleted diff --git a/formio/views/formio_builder_views.xml b/formio/views/formio_builder_views.xml index 99f5fdb0..083ab010 100644 --- a/formio/views/formio_builder_views.xml +++ b/formio/views/formio_builder_views.xml @@ -22,6 +22,7 @@ See LICENSE file for full licensing details. --> + @@ -87,6 +88,7 @@ See LICENSE file for full licensing details. --> +