diff options
| author | Jay Vora (OpenERP) <jvo@tinyerp.com> | 2011-06-07 13:00:27 +0530 |
|---|---|---|
| committer | Jay Vora (OpenERP) <jvo@tinyerp.com> | 2011-06-07 13:00:27 +0530 |
| commit | 6ccb0e047a0e73e4bee6acff1f3ea5bfba09c9ca (patch) | |
| tree | 74a827757a9f0c5c9b6c905c2c5c3711a6d54d0a | |
| parent | ed1008a73c24acfa345f62f0bede829b42778b3d (diff) | |
| parent | 7928a00024def2ff1f31ef4c1c7544b6e473477d (diff) | |
[MERGE] Merged Oliver Dony's branch for the fixes of share module
bzr revid: jvo@tinyerp.com-20110607073027-gd9wius28dxck4js
| -rw-r--r-- | addons/share/__openerp__.py | 2 | ||||
| -rw-r--r-- | addons/share/web/controllers.py | 2 | ||||
| -rw-r--r-- | addons/share/web/editors.py | 18 | ||||
| -rw-r--r-- | addons/share/wizard/share_wizard.py | 39 |
4 files changed, 43 insertions, 18 deletions
diff --git a/addons/share/__openerp__.py b/addons/share/__openerp__.py index 7a68936970d..9a71412523a 100644 --- a/addons/share/__openerp__.py +++ b/addons/share/__openerp__.py @@ -22,7 +22,7 @@ { "name" : "Sharing Tools", - "version" : "1.3", + "version" : "1.3.2", "depends" : ["base"], "author" : "OpenERP SA", "category": 'Generic Modules', diff --git a/addons/share/web/controllers.py b/addons/share/web/controllers.py index aa689019259..1b57d960e99 100644 --- a/addons/share/web/controllers.py +++ b/addons/share/web/controllers.py @@ -13,7 +13,7 @@ class ShareWizardController(openerp.controllers.SecuredController): _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: diff --git a/addons/share/web/editors.py b/addons/share/web/editors.py index fd6199a4fd6..1e1573b05af 100644 --- a/addons/share/web/editors.py +++ b/addons/share/web/editors.py @@ -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> @@ -28,13 +33,16 @@ class ShareActionEditor(openobject.templating.TemplateEditor): domain: jQuery("#_terp_domain").val(), view_id: jQuery("#_terp_view_id").val(), action_id: jQuery("#_terp_action_id").val(), - search_domain: jQuery("#_terp_search_domain").val(), + search_domain: jQuery("#_terp_view_type").val() == "form" ? + ("[('id','=',"+jQuery("#_terp_id").val()+")]") : + jQuery("#_terp_search_domain").val(), })); }); }); </script> - \n''' + \ - output[share_opener_insertion:] + \n + % endif +''' + output[share_opener_insertion:] def edit(self, template, template_text): return self.insert_share_link( diff --git a/addons/share/wizard/share_wizard.py b/addons/share/wizard/share_wizard.py index 48243c57dda..c22be871b60 100644 --- a/addons/share/wizard/share_wizard.py +++ b/addons/share/wizard/share_wizard.py @@ -31,6 +31,9 @@ from tools.safe_eval import safe_eval 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 @@ 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."), @@ -144,10 +159,9 @@ class share_create(osv.osv_memory): 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 @@ class share_create(osv.osv_memory): 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 @@ class share_create(osv.osv_memory): 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 @@ class share_create(osv.osv_memory): # 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. |
