[FIX] share: hide Share button when user does not belong to Sharing group

bzr revid: odo@openerp.com-20110505161426-c4ocuy98mgbceq5w
This commit is contained in:
Olivier Dony
2011-05-05 18:14:26 +02:00
parent 8fd72aff40
commit ef4c13fad5
2 changed files with 22 additions and 4 deletions
+10 -4
View File
@@ -11,8 +11,13 @@ class ShareActionEditor(openobject.templating.TemplateEditor):
share_opener_insertion = output.index(
'\n',
output.index(self.ADD_SHARE_SECTION)) + 1
return output[:share_opener_insertion] + \
'''<div id="share-wizard" class="sideheader-a"><h2>${_("Sharing")}</h2></div>
return output[:share_opener_insertion] + '''
<%
if 'has_share' not in cp.session:
cp.session['has_share'] = rpc.RPCProxy('share.wizard').has_share()
%>
% if cp.session['has_share']:
<div id="share-wizard" class="sideheader-a"><h2>${_("Sharing")}</h2></div>
<ul class="clean-a">
<li>
<a id="sharing" href="#share">${_("Share")}</a>
@@ -33,8 +38,9 @@ class ShareActionEditor(openobject.templating.TemplateEditor):
});
});
</script>
\n''' + \
output[share_opener_insertion:]
\n
% endif
''' + output[share_opener_insertion:]
def edit(self, template, template_text):
return self.insert_share_link(
+12
View File
@@ -50,6 +50,18 @@ class share_create(osv.osv_memory):
_name = 'share.wizard'
_description = 'Share Wizard'
def has_group(self, cr, uid, module, group_xml_id, context=None):
"""Returns True if current user is a member of the group identified by the module, group_xml_id pair."""
# if the group was deleted or does not exist, we say NO (better safe than sorry)
try:
model, group_id = self.pool.get('ir.model.data').get_object_reference(cr, uid, module, group_xml_id)
except ValueError:
return False
return group_id in self.pool.get('res.users').read(cr, uid, uid, ['groups_id'], context=context)['groups_id']
def has_share(self, cr, uid, context=None):
return self.has_group(cr, uid, module='share', group_xml_id='group_share_user', context=context)
_columns = {
'action_id': fields.many2one('ir.actions.act_window', 'Action to share', required=True,
help="The action that opens the screen containing the data you wish to share."),