Skip to content

Commit

Permalink
Add user rights to limit access to certain users (and give all rights…
Browse files Browse the repository at this point in the history
… to others)
  • Loading branch information
mdietrichc2c committed Nov 18, 2014
1 parent e52554c commit e0a359f
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 25 deletions.
2 changes: 1 addition & 1 deletion base_partner_merge/__openerp__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
'base',
],
'data': [
'security/ir.model.access.csv',
'security/security.xml',
'base_partner_merge_view.xml',
],
'installable': True,
Expand Down
34 changes: 13 additions & 21 deletions base_partner_merge/base_partner_merge.py
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,16 @@ def _merge(self, cr, uid, partner_ids, dst_partner=None, context=None):

partner_ids = proxy.exists(cr, uid, list(partner_ids),
context=context)

if not self.pool['res.users'].has_group(
cr, uid, 'base_partner_merge.group_partner_merge'
):
raise orm.except_orm(
_('Error'),
_("You do not belong in the 'Partner Merge' group. "
"Please contact the Administrator to get access to "
"the partner merge functionality."))

if len(partner_ids) < 2:
return

Expand All @@ -350,10 +360,9 @@ def _merge(self, cr, uid, partner_ids, dst_partner=None, context=None):
"together. You can re-open the wizard several times if "
"needed."))

if (openerp.SUPERUSER_ID != uid
and len(set(partner.email for partner
in proxy.browse(cr, uid, partner_ids,
context=context))) > 1):
if (len(set(partner.email for partner

This comment has been minimized.

Copy link
@cesarcruz

cesarcruz Jun 15, 2015

After delete the condition openerp.SUPERUSER_ID != uid, logged in admin user got error message when try to merge contacts, since it is admin this error should not displayed, fixed in 1ef1fe3

This comment has been minimized.

Copy link
@mdietrichc2c

mdietrichc2c Jun 16, 2015

Author

Good catch! It's true that only the administrator has the right to merge contacts with different e-mails (compared to all the other cases, which must be available to every user in the "partner merge" group).
Did you create a PR for your commit? I did not see it.

This comment has been minimized.

Copy link
@cesarcruz

cesarcruz Jun 16, 2015

Yes, here #128, but I not sure why github merged it with previous PR (Spanish Translation)

in proxy.browse(cr, uid, partner_ids,
context=context))) > 1):
raise orm.except_orm(
_('Error'),
_("All contacts must have the same email. Only the "
Expand All @@ -371,23 +380,6 @@ def _merge(self, cr, uid, partner_ids, dst_partner=None, context=None):
src_partners = ordered_partners[:-1]
_logger.info("dst_partner: %s", dst_partner.id)

if (openerp.SUPERUSER_ID != uid
and self._model_is_installed(cr, uid, 'account.move.line',
context=context)
and self.pool.get('account.move.line'
).search(cr, openerp.SUPERUSER_ID,
[('partner_id',
'in',
[partner.id for partner
in src_partners])],
context=context)):
raise orm.except_orm(
_('Error'),
_("Only the destination contact may be linked to existing "
"Journal Items. Please ask the Administrator if you need to"
" merge several contacts linked to existing Journal "
"Items."))

call_it = lambda function: function(cr, uid, src_partners,
dst_partner, context=context)

Expand Down
6 changes: 3 additions & 3 deletions base_partner_merge/base_partner_merge_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<openerp>
<data>
<!-- the sequence of the configuration sub menu is 30 -->
<menuitem id='root_menu' name='Tools' parent='base.menu_base_partner' sequence="25"/>
<menuitem id='root_menu' name='Tools' parent='base.menu_base_partner' sequence="25" groups='group_partner_merge'/>

<record model="ir.actions.act_window" id="base_partner_merge_automatic_act">
<field name="name">Deduplicate Contacts</field>
Expand All @@ -15,7 +15,7 @@

<menuitem id='partner_merge_automatic_menu'
action='base_partner_merge_automatic_act'
groups='base.group_system'
groups='group_partner_merge'
parent='root_menu' />

<record model='ir.ui.view' id='base_partner_merge_automatic_wizard_form'>
Expand Down Expand Up @@ -116,7 +116,7 @@
</record>

<act_window id="action_partner_merge" res_model="base.partner.merge.automatic.wizard" src_model="res.partner"
target="new" multi="True" key2="client_action_multi" view_mode="form" name="Automatic Merge"/>
target="new" multi="True" key2="client_action_multi" view_mode="form" name="Automatic Merge" groups="group_partner_merge"/>

</data>

Expand Down
11 changes: 11 additions & 0 deletions base_partner_merge/security/security.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<record model="res.groups" id="group_partner_merge">
<field name="name">Partner Merge</field>
</record>
<record model="res.groups" id="base.group_system">
<field name="implied_ids" eval="[(4, ref('group_partner_merge'))]"/>
</record>
</data>
</openerp>

0 comments on commit e0a359f

Please sign in to comment.