← Back to team overview

openerp-dev-web team mailing list archive

[Merge] lp:~openerp-dev/openobject-addons/6.0-fixes-share-odo into lp:openobject-addons/6.0

 

Olivier Dony (OpenERP) has proposed merging lp:~openerp-dev/openobject-addons/6.0-fixes-share-odo into lp:openobject-addons/6.0.

Requested reviews:
  OpenERP Publisher's Warranty Team (openerp-opw)

For more details, see:
https://code.launchpad.net/~openerp-dev/openobject-addons/6.0-fixes-share-odo/+merge/60095

This branch provides a few bugfixes for the share wizard, mostly backports from trunk.
Each bugifx comes in a separate commit with some details:

4566: [FIX] share: multi-sharing with an empty filter was not working
4565: [FIX] share: current user restrictions were not properly copied
4564: [FIX] share: use empty domain for shared actions, as ir.rules do enforce the filtering.
4563: [FIX] share: share users with multi-shares should keep same home action
4562: [FIX] share: bumped up module version after changes to web addon
4561: [FIX] share: hide Share button when user does not belong to Sharing group
4560: [FIX] share: avoid crash in web addon with empty share filter

Unfortunately I did not have time to check whether there were LP bugreports for these bugs.
-- 
https://code.launchpad.net/~openerp-dev/openobject-addons/6.0-fixes-share-odo/+merge/60095
Your team OpenERP R&D Team is subscribed to branch lp:~openerp-dev/openobject-addons/6.0-fixes-share-odo.
=== modified file 'share/__openerp__.py'
--- share/__openerp__.py	2011-02-08 12:32:41 +0000
+++ share/__openerp__.py	2011-05-05 16:36:24 +0000
@@ -22,7 +22,7 @@
 
 {
     "name" : "Sharing Tools",
-    "version" : "1.3",
+    "version" : "1.3.1",
     "depends" : ["base"],
     "author" : "OpenERP SA",
     "category": 'Generic Modules',

=== modified file 'share/web/controllers.py'
--- share/web/controllers.py	2011-02-22 18:18:40 +0000
+++ share/web/controllers.py	2011-05-05 16:36:24 +0000
@@ -13,7 +13,7 @@
     _cp_path = "/share"
 
     @expose()
-    def index(self, domain, search_domain, context, view_id, action_id=None):
+    def index(self, domain, context, view_id, search_domain='[]', action_id=None):
         context = ast.literal_eval(context)
 
         if not action_id:

=== modified file 'share/web/editors.py'
--- share/web/editors.py	2011-02-08 12:32:41 +0000
+++ share/web/editors.py	2011-05-05 16:36:24 +0000
@@ -11,8 +11,13 @@
         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 @@
                                });
                            });
                        </script>
-                       \n''' + \
-                output[share_opener_insertion:]
+                       \n
+    % endif
+''' + output[share_opener_insertion:]
 
     def edit(self, template, template_text):
         return self.insert_share_link(

=== modified file 'share/wizard/share_wizard.py'
--- share/wizard/share_wizard.py	2011-01-18 19:30:22 +0000
+++ share/wizard/share_wizard.py	2011-05-05 16:36:24 +0000
@@ -31,6 +31,9 @@
 FULL_ACCESS = ('perm_read', 'perm_write', 'perm_create', 'perm_unlink')
 READ_ONLY_ACCESS = ('perm_read',)
 
+# Pseudo-domain to represent an empty filter, constructed using
+# osv.expression's DUMMY_LEAF
+DOMAIN_ALL = [(1, '=', 1)]
 
 RANDOM_PASS_CHARACTERS = [chr(x) for x in range(48, 58) + range(97, 123) + range(65, 91)]
 RANDOM_PASS_CHARACTERS.remove('l') #lowercase l, easily mistaken as one or capital i
@@ -50,6 +53,18 @@
     _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."),
@@ -144,10 +159,9 @@
 
     def _setup_action_and_shortcut(self, cr, uid, wizard_data, user_ids, new_users, context=None):
         user_obj = self.pool.get('res.users')
-        menu_action_id = user_obj._get_menu(cr, uid, context=context)
         values = {
             'name': (_('%s (Shared)') % wizard_data.action_id.name)[:64],
-            'domain': wizard_data.domain,
+            'domain': '[]',
             'context': wizard_data.action_id.context,
             'res_model': wizard_data.action_id.res_model,
             'view_mode': wizard_data.action_id.view_mode,
@@ -157,9 +171,11 @@
         for user_id in user_ids:
             action_id = self._create_shortcut(cr, user_id, values)
             if new_users:
+                # We do this only for new share users, as existing ones already have their initial home
+                # action. Resetting to the default menu does not work well as the menu is rather empty
+                # and does not contain the shortcuts in most cases.
                 user_obj.write(cr, 1, [user_id], {'action_id': action_id})
-            else:
-                user_obj.write(cr, 1, [user_id], {'action_id': menu_action_id})
+
 
     def _get_recursive_relations(self, cr, uid, model, ttypes, relation_fields=None, suffix=None, context=None):
         """Returns list of tuples representing recursive relationships of type ``ttypes`` starting from
@@ -258,21 +274,21 @@
         user_obj = self.pool.get('res.users')
         rule_obj = self.pool.get('ir.rule')
         current_user = user_obj.browse(cr, uid, uid, context=context)
-        completed_models = set()
+        rules_done = set()
         for group in current_user.groups_id:
             for dummy, model in fields_relations:
-                if model.id in completed_models:
-                    continue
-                completed_models.add(model.id)
                 for rule in group.rule_groups:
-                    if rule.model_id == model.id:
+                    if rule.id in rules_done:
+                        continue
+                    rules_done.add(rule.id)
+                    if rule.model_id.id == model.id:
                         if 'user.' in rule.domain_force:
                             # Above pattern means there is likely a condition
                             # specific to current user, so we must copy the rule using
                             # the evaluated version of the domain.
                             # And it's better to copy one time too much than too few
                             rule_obj.copy(cr, 1, rule.id, default={
-                                'name': '%s (%s)' %(rule.name, _('(Copy for sharing)')),
+                                'name': '%s %s' %(rule.name, _('(Copy for sharing)')),
                                 'groups': [(6,0,[group_id])],
                                 'domain_force': rule.domain, # evaluated version!
                             })
@@ -414,11 +430,12 @@
         #     to uid, and it must be replaced correctly)
         rule_obj = self.pool.get('ir.rule')
         # A.
+        main_domain = wizard_data.domain if wizard_data.domain != '[]' else DOMAIN_ALL
         rule_obj.create(cr, 1, {
             'name': _('Sharing filter created by user %s (%s) for group %s') % \
                         (current_user.name, current_user.login, group_id),
             'model_id': model.id,
-            'domain_force': wizard_data.domain,
+            'domain_force': main_domain,
             'groups': [(4,group_id)]
             })
         # B.


Follow ups