[FIX] share: hide Share button when user does not belong to Sharing group
[odoo/odoo.git] / addons / share / web / editors.py
1 # -*- coding: utf-8 -*-
2 import openobject.templating
3
4 class ShareActionEditor(openobject.templating.TemplateEditor):
5     templates = ['/openerp/widgets/templates/sidebar.mako']
6     ADD_SHARE_SECTION = u'id="sidebar"'
7
8     def insert_share_link(self, output):
9         # Insert the link on the line right after the link to open the
10         # attachment form
11         share_opener_insertion = output.index(
12                 '\n',
13                 output.index(self.ADD_SHARE_SECTION)) + 1
14         return output[:share_opener_insertion] + '''
15     <%
16         if 'has_share' not in cp.session:
17             cp.session['has_share'] = rpc.RPCProxy('share.wizard').has_share()
18     %>
19     % if cp.session['has_share']:
20         <div id="share-wizard" class="sideheader-a"><h2>${_("Sharing")}</h2></div>
21                      <ul class="clean-a">
22                          <li>
23                              <a id="sharing" href="#share">${_("Share")}</a>
24                          </li>
25                      </ul>
26                        <script type="text/javascript">
27                            jQuery(document).ready(function() {
28                                jQuery("#sharing").click(function() {
29                                    jQuery(this).attr(
30                                        "href",
31                                        openobject.http.getURL('/share', {
32                                            context: jQuery("#_terp_context").val(),
33                                            domain: jQuery("#_terp_domain").val(),
34                                            view_id: jQuery("#_terp_view_id").val(),
35                                            action_id: jQuery("#_terp_action_id").val(),
36                                            search_domain: jQuery("#_terp_search_domain").val(),
37                                    }));
38                                });
39                            });
40                        </script>
41                        \n
42     % endif
43 ''' + output[share_opener_insertion:]
44
45     def edit(self, template, template_text):
46         return self.insert_share_link(
47             super(ShareActionEditor, self).edit(template, template_text))