Thibault Delavallée (OpenERP) has proposed merging 
lp:~openerp-dev/openobject-addons/trunk-portal-share-cleaning-tde into 
lp:openobject-addons.

Requested reviews:
  OpenERP Core Team (openerp)

For more details, see:
https://code.launchpad.net/~openerp-dev/openobject-addons/trunk-portal-share-cleaning-tde/+merge/123515

Portal / Share cleaning
-- 
https://code.launchpad.net/~openerp-dev/openobject-addons/trunk-portal-share-cleaning-tde/+merge/123515
Your team OpenERP R&D Team is subscribed to branch 
lp:~openerp-dev/openobject-addons/trunk-portal-share-cleaning-tde.
=== modified file 'mail/static/src/css/mail.css'
--- mail/static/src/css/mail.css	2012-09-07 15:08:20 +0000
+++ mail/static/src/css/mail.css	2012-09-10 09:31:26 +0000
@@ -100,6 +100,11 @@
     display: inline;
 }
 
+/* TDE: FIXME */
+.openerp button.oe_mail_button_invite {
+    display: inline;
+}
+
 .openerp button.oe_mail_button_mouseout {
   color: white;
   background-color: #8a89ba;

=== modified file 'mail/static/src/xml/mail_followers.xml'
--- mail/static/src/xml/mail_followers.xml	2012-09-05 16:31:35 +0000
+++ mail/static/src/xml/mail_followers.xml	2012-09-10 09:31:26 +0000
@@ -7,6 +7,7 @@
         -->
     <div t-name="mail.followers" class="oe_mail_recthread_aside oe_semantic_html_override">
         <div class="oe_mail_recthread_actions">
+            <button type="button" class="oe_mail_button_invite">Invite</button>
             <button type="button" class="oe_mail_button_follow oe_mail_button_mouseout">Not following</button>
             <button type="button" class="oe_mail_button_unfollow oe_mail_button_mouseout">Following</button>
         </div>

=== modified file 'portal/wizard/portal_wizard.py'
--- portal/wizard/portal_wizard.py	2012-09-04 16:13:46 +0000
+++ portal/wizard/portal_wizard.py	2012-09-10 09:31:26 +0000
@@ -23,13 +23,10 @@
 import random
 
 from osv import osv, fields
-from tools.misc import email_re
 from tools.translate import _
 
-from base.res.res_partner import _lang_get
 _logger = logging.getLogger(__name__)
 
-
 # welcome email sent to new portal users (note that calling tools.translate._
 # has no effect except exporting those strings for translation)
 WELCOME_EMAIL_SUBJECT = _("Your OpenERP account at %(company)s")
@@ -62,13 +59,6 @@
     random.shuffle(chars)
     return ''.join(chars)
 
-def extract_email(email):
-    """ extract the email address from a user-friendly email address """
-    m = email_re.search(email or "")
-    return m and m.group(0) or ""
-
-
-
 class wizard(osv.osv_memory):
     """
         A wizard to create portal users from instances of 'res.partner'. The purpose
@@ -76,164 +66,110 @@
     """
     _name = 'res.portal.wizard'
     _description = 'Portal Wizard'
-    
+
     _columns = {
         'portal_id': fields.many2one('res.portal', required=True,
             string='Portal',
             help="The portal in which new users must be added"),
-        'user_ids': fields.one2many('res.portal.wizard.user', 'wizard_id',
-            string='Users'),
+        'partner_ids': fields.many2many('res.partner', 'res_portal_wizard_res_partner_rel',
+            'wizard_id', 'partner_id', string='Partners'),
         'message': fields.text(string='Invitation message',
             help="This text is included in the welcome email sent to the users"),
     }
 
-    def _default_user_ids(self, cr, uid, context):
-        """ determine default user_ids from the active records """
-        def create_user_from_address(address):
-            if isinstance(address, int):
-                res_partner_obj = self.pool.get('res.partner')
-                address = res_partner_obj.browse(cr, uid, address, context=context)
-                lang = address.id and address.lang or 'en_US'
-                partner_id = address.id
-                
-            else:
-                lang = address.parent_id and address.parent_id.lang or 'en_US'
-                partner_id = address.parent_id and address.parent_id.id
-            
-            return{
-                   'name': address.name,
-                   'email': extract_email(address.email),
-                   'lang': lang,
-                   'partner_id': partner_id,
-                   }
-        
-        user_ids = []
+    def _get_default_portal_id(self, cr, uid, context=None):
+        """ Get default portal for the wizard:
+            - 'portal' portal (see portal data)
+        """
+        portal_ref = self.pool.get('ir.model.data').get_object_reference(cr, uid, 'portal', 'portal')
+        return portal_ref and portal_ref[1] or False
+
+    def _get_default_partner_ids(self, cr, uid, context=None):
+        """ Get default partner_ids from the active records:
+            - if active_model is res.partner (Add portal access wizard): check
+              all active_ids (records for the wizard), get their child_ids
+              for companies, or themselves for people.
+        """
+        partner_ids = []
         if context.get('active_model') == 'res.partner':
             partner_obj = self.pool.get('res.partner')
-            partner_ids = context.get('active_ids', [])
-            partners = partner_obj.browse(cr, uid, partner_ids, context)
-            for p in partners:
-                # add one user per contact, or one user if no contact
-                if p.child_ids:
-                    user_ids.extend(map(create_user_from_address, p.child_ids))
-                elif p.is_company == False and p.customer == True:
-                    user_ids.extend(map(create_user_from_address, [p.id]))
+            context_partner_ids = context.get('active_ids', [])
+            for partner in partner_obj.browse(cr, uid, context_partner_ids, context=context):
+                 # add one user per contact, or one user if no contact
+                if partner.child_ids:
+                    partner_ids.extend([child_partner.id for child_partner in partner.child_ids])
                 else:
-                    user_ids.append({'lang': p.lang or 'en_US', 'parent_id': p.id})
-        
-        return user_ids
+                    partner_ids.append(partner.id)
+        return partner_ids
 
     _defaults = {
-        'user_ids': _default_user_ids
+        'portal_id': _get_default_portal_id,
+        'partner_ids': _get_default_partner_ids,
     }
 
     def action_create(self, cr, uid, ids, context=None):
         """ create new users in portal(s), and notify them by email """
         # we copy the context to change the language for translating emails
-        context0 = context or {}
-        context0['noshortcut'] = True           # prevent shortcut creation
-        context = context0.copy()
-        
+        if context is None:
+            context = {}
+        context['noshortcut'] = True           # prevent shortcut creation
+        partner_context = context.copy()
+
         user_obj = self.pool.get('res.users')
-        user = user_obj.browse(cr, ROOT_UID, uid, context0)
-        if not user.email:
+        portal_obj = self.pool.get('res.portal')
+        mail_mail_obj = self.pool.get('mail.mail')
+
+        curent_user = user_obj.browse(cr, ROOT_UID, uid, context=context)
+        if not curent_user.user_email:
             raise osv.except_osv(_('Email required'),
                 _('You must have an email address in your User Preferences'
                   ' to send emails.'))
-        
-        portal_obj = self.pool.get('res.portal')
-        for wiz in self.browse(cr, uid, ids, context):
+
+        for wiz in self.browse(cr, uid, ids, context=context):
             # determine existing users
-            login_cond = [('login', 'in', [u.email for u in wiz.user_ids])]
-            existing_uids = user_obj.search(cr, ROOT_UID, login_cond)
-            existing_users = user_obj.browse(cr, ROOT_UID, existing_uids)
-            existing_logins = [u.login for u in existing_users]
-            
+            login_cond = [('login', 'in', [partner.email for partner in wiz.partner_ids])]
+            existing_uids = user_obj.search(cr, ROOT_UID, login_cond, context=context)
+            existing_users = user_obj.browse(cr, ROOT_UID, existing_uids, context=context)
+            existing_logins = [user.login for user in existing_users]
+
             # create new users in portal (skip existing logins)
-            new_users_data = [ {
-                    'name': u.name,
-                    'login': u.email,
-                    'password': random_password(),
-                    'email': u.email,
-                    'lang': u.lang,
-                    'share': True,
-                    'action_id': wiz.portal_id.home_action_id and wiz.portal_id.home_action_id.id or False,
-                    'partner_id': u.partner_id and u.partner_id.id,
-                    'groups_id': [(6, 0, [])],
-                } for u in wiz.user_ids if u.email not in existing_logins ]
+            new_users_data = [{
+                'partner_id': partner.id,
+                'login': partner.email,
+                'password': random_password(),
+                'share': True,
+                'action_id': wiz.portal_id.home_action_id and wiz.portal_id.home_action_id.id or False,
+                'groups_id': [(6, 0, [])],
+                } for partner in wiz.partner_ids if partner.email not in existing_logins]
             portal_obj.write(cr, ROOT_UID, [wiz.portal_id.id],
-                {'users': [(0, 0, data) for data in new_users_data]}, context0)
-            
+                {'users': [(0, 0, data) for data in new_users_data]}, context=context)
+
             # send email to all users (translated in their language)
             data = {
-                'company': user.company_id.name,
+                'company': curent_user.company_id.name,
                 'message': wiz.message or "",
                 'url': wiz.portal_id.url or _("(missing url)"),
                 'db': cr.dbname,
             }
-            mail_mail_obj = self.pool.get('mail.mail')
-            dest_uids = user_obj.search(cr, ROOT_UID, login_cond)
-            dest_users = user_obj.browse(cr, ROOT_UID, dest_uids)
+
+            dest_uids = user_obj.search(cr, ROOT_UID, login_cond, context=context)
+            dest_users = user_obj.browse(cr, ROOT_UID, dest_uids, context=context)
             for dest_user in dest_users:
-                context['lang'] = dest_user.lang
+                partner_context['lang'] = dest_user.lang
                 data['login'] = dest_user.login
                 data['password'] = dest_user.password
                 data['name'] = dest_user.name
-                
-                email_from = user.email
+                email_from = curent_user.email
                 email_to = dest_user.email
                 subject = _(WELCOME_EMAIL_SUBJECT) % data
                 body = _(WELCOME_EMAIL_BODY) % data
-                mail_id = mail_mail_obj.create(cr, uid, {
-                            'email_from': email_from ,
+                mail_mail_obj.create(cr, uid, {
+                            'email_from': email_from,
                             'email_to': email_to,
                             'subject': subject,
                             'state': 'outgoing',
-                            'body_html': '<pre>%s</pre>' % body}, context=context)
-        
+                            'body_html': '<pre>%s</pre>' % body}, context=partner_context)
+
         return {'type': 'ir.actions.act_window_close'}
 
-wizard()
-
-
-
-class wizard_user(osv.osv_memory):
-    """
-        A model to configure users in the portal wizard.
-    """
-    _name = 'res.portal.wizard.user'
-    _description = 'Portal User Config'
-
-    _columns = {
-        'wizard_id': fields.many2one('res.portal.wizard', required=True,
-            string='Wizard'),
-        'name': fields.char(size=64, required=True,
-            string='User Name',
-            help="The user's real name"),
-        'email': fields.char(size=64, required=True,
-            string='Email',
-            help="Will be used as user login.  "  
-                 "Also necessary to send the account information to new users"),
-        'lang': fields.selection(_lang_get, required=True,
-            string='Language',
-            help="The language for the user's user interface"),
-        'partner_id': fields.many2one('res.partner',
-            string='Partner'),
-    }
-
-    def _check_email(self, cr, uid, ids):
-        """ check syntax of email address """
-        for wuser in self.browse(cr, uid, ids):
-            if not email_re.match(wuser.email): return False
-        return True
-
-    _constraints = [
-        (_check_email, 'Invalid email address', ['email']),
-    ]
-
-wizard_user()
-
-
-
-
 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

=== modified file 'portal/wizard/portal_wizard_view.xml'
--- portal/wizard/portal_wizard_view.xml	2012-08-14 15:26:34 +0000
+++ portal/wizard/portal_wizard_view.xml	2012-09-10 09:31:26 +0000
@@ -16,10 +16,10 @@
             <field name="model">res.portal.wizard</field>
             <field name="arch" type="xml">
                 <form string="Add Portal Access" version="7.0">
-                    <group col="4">
+                    <group>
                         <field name="portal_id" widget="selection"/>
+                        <field name="partner_ids" widget="many2many_tags"/>
                     </group>
-                    <field name="user_ids"/>
                     <label string="The following text will be included in the welcome email sent to users."/>
                     <field name="message"/>
                     <footer>
@@ -32,35 +32,5 @@
             </field>
         </record>
 
-        <!-- wizard user list view -->
-        <record id="wizard_user_tree_view" model="ir.ui.view">
-            <field name="name">Portal Users</field>
-            <field name="model">res.portal.wizard.user</field>
-            <field name="arch" type="xml">
-                <!-- the attribute 'editable' is set below to make the elements
-                     editable in the web client 6.0 -->
-                <tree string="Portal Users" editable="bottom">
-                    <field name="name"/>
-                    <field name="email"/>
-                    <field name="partner_id"/>
-                </tree>
-            </field>
-        </record>
-
-        <!-- wizard user form view -->
-        <record id="wizard_user_form_view" model="ir.ui.view">
-            <field name="name">Portal User</field>
-            <field name="model">res.portal.wizard.user</field>
-            <field name="arch" type="xml">
-                <form string="Portal User" version="7.0">
-                    <group colspan="2" col="2">
-                        <field name="name"/>
-                        <field name="email"/>
-                        <field name="lang"/>
-                        <field name="partner_id"/>
-                    </group>
-                </form>
-            </field>
-        </record>
     </data>
 </openerp>

=== modified file 'portal/wizard/share_wizard.py'
--- portal/wizard/share_wizard.py	2012-06-29 13:51:35 +0000
+++ portal/wizard/share_wizard.py	2012-09-10 09:31:26 +0000
@@ -33,30 +33,30 @@
        menus in the selected portal upon sharing with a portal group."""
     _inherit = "share.wizard"
 
-    def _user_type_selection(self, cr, uid, context=None):
-        selection = super(share_wizard_portal, self)._user_type_selection(cr, uid, context=context)
-        selection.extend([('existing','Users you already shared with'),
-                          ('groups','Existing Groups (e.g Portal Groups)')])
-        return selection
-
-    _columns = {
-        'user_ids': fields.many2many('res.users', 'share_wizard_res_user_rel', 'share_id', 'user_id', 'Existing users', domain=[('share', '=', True)]),
-        'group_ids': fields.many2many('res.groups', 'share_wizard_res_group_rel', 'share_id', 'group_id', 'Existing groups', domain=[('share', '=', False)]),
-    }
-
-    def is_portal_manager(self, cr, uid, context=None):
-        return self.has_group(cr, uid, module='portal', group_xml_id='group_portal_manager', context=context)
-
-    def _check_preconditions(self, cr, uid, wizard_data, context=None):
-        if wizard_data.user_type == 'existing':
-            self._assert(wizard_data.user_ids,
-                     _('Please select at least one user to share with'),
-                     context=context)
-        elif wizard_data.user_type == 'groups':
-            self._assert(wizard_data.group_ids,
-                     _('Please select at least one group to share with'),
-                     context=context)
-        return super(share_wizard_portal, self)._check_preconditions(cr, uid, wizard_data, context=context)
+    # def _user_type_selection(self, cr, uid, context=None):
+    #     selection = super(share_wizard_portal, self)._user_type_selection(cr, uid, context=context)
+    #     selection.extend([('existing','Users you already shared with'),
+    #                       ('groups','Existing Groups (e.g Portal Groups)')])
+    #     return selection
+
+    # _columns = {
+    #     'user_ids': fields.many2many('res.users', 'share_wizard_res_user_rel', 'share_id', 'user_id', 'Existing users', domain=[('share', '=', True)]),
+    #     'group_ids': fields.many2many('res.groups', 'share_wizard_res_group_rel', 'share_id', 'group_id', 'Existing groups', domain=[('share', '=', False)]),
+    # }
+
+    # def is_portal_manager(self, cr, uid, context=None):
+    #     return self.has_group(cr, uid, module='portal', group_xml_id='group_portal_manager', context=context)
+
+    # def _check_preconditions(self, cr, uid, wizard_data, context=None):
+    #     if wizard_data.user_type == 'existing':
+    #         self._assert(wizard_data.user_ids,
+    #                  _('Please select at least one user to share with'),
+    #                  context=context)
+    #     elif wizard_data.user_type == 'groups':
+    #         self._assert(wizard_data.group_ids,
+    #                  _('Please select at least one group to share with'),
+    #                  context=context)
+    #     return super(share_wizard_portal, self)._check_preconditions(cr, uid, wizard_data, context=context)
 
     def _create_or_get_submenu_named(self, cr, uid, parent_menu_id, menu_name, context=None):
         if not parent_menu_id:

=== removed directory 'share/static/src/css'
=== removed file 'share/static/src/css/share.css'
--- share/static/src/css/share.css	2012-06-29 13:56:57 +0000
+++ share/static/src/css/share.css	1970-01-01 00:00:00 +0000
@@ -1,4 +0,0 @@
-/* Added invite button, hidden by default */
-button.oe_share_invite {
-    display: none;
-}

=== modified file 'share/static/src/js/share.js'
--- share/static/src/js/share.js	2012-08-24 18:27:43 +0000
+++ share/static/src/js/share.js	2012-09-10 09:31:26 +0000
@@ -1,9 +1,7 @@
 
 openerp.share = function(session) {
 
-    var has_action_id = false;
-
-    function launch_wizard(self, view, user_type, invite) {
+    function launch_wizard(self, view, user_type) {
         var action = view.getParent().action;
         var Share = new session.web.DataSet(self, 'share.wizard', view.dataset.get_context());
         var domain = new session.web.CompoundDomain(view.dataset.domain);
@@ -23,7 +21,6 @@
                 action_id: action.id,
                 user_type: user_type || 'embedded',
                 view_type: view.fields_view.type,
-                invite: invite || false,
             }, function(result) {
                 var share_id = result.result;
                 var step1 = Share.call('go_step_1', [[share_id],], function(result) {
@@ -78,46 +75,5 @@
             launch_wizard(this, view, 'embedded', false);
         },
     });
-
-    /**
-     * Extends mail (Chatter widget)
-     * - show the 'invite' button' only we came on the form view through
-     *   an action. We do this because 'invite' is based on the share
-     *   mechanism, and it tries to share an action.
-     */
-    session.mail.RecordThread.include( {
-        start: function() {
-            start_res = this._super.apply(this, arguments);
-            if (has_action_id) {
-                this.$el.find('button.oe_share_invite').show();
-            }
-            return start_res;
-        }
-    });
-
-    session.web.ViewManagerAction.include({
-        start: function() {
-            var self = this;
-            this.check_if_action_is_defined();
-            has_share(function() {
-                self.$el.delegate('button.oe_share_invite', 'click', self.on_click_share_invite);
-            });
-            return this._super.apply(this, arguments);
-        },
-    
-        check_if_action_is_defined: function() {
-            if (this.action && this.action.id) {
-                has_action_id = true;
-            }
-            else {
-                has_action_id = false;
-            }
-        },
-
-        on_click_share_invite: function(e) {
-            e.preventDefault();
-            launch_wizard(this, this.views[this.active_view].controller, 'emails', true);
-        },
-    });
 };
 

=== removed directory 'share/static/src/xml'
=== removed file 'share/static/src/xml/share.xml'
--- share/static/src/xml/share.xml	2012-06-29 15:10:20 +0000
+++ share/static/src/xml/share.xml	1970-01-01 00:00:00 +0000
@@ -1,13 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!-- vim:fdl=1:
--->
-<templates id="template" xml:space="preserve">
-
-    <!-- Extends Chatter widget in form view to add the invite button -->
-    <t t-extend="mail.RecordThread">
-        <t t-jquery="button.oe_mail_button_unfollow" t-operation="after">
-            <button type="button" class="oe_share_invite">Invite</button>
-        </t>
-    </t>
-
-</templates>

=== modified file 'share/wizard/share_wizard.py'
--- share/wizard/share_wizard.py	2012-09-04 16:19:56 +0000
+++ share/wizard/share_wizard.py	2012-09-10 09:31:26 +0000
@@ -18,10 +18,10 @@
 #    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 #
 ##############################################################################
+
 import logging
 import random
 import time
-from urllib import quote_plus
 import uuid
 from openerp import SUPERUSER_ID
 
@@ -72,16 +72,15 @@
     def has_share(self, cr, uid, context=None):
         return self.has_group(cr, uid, module='share', group_xml_id='group_share_user', context=context)
 
+    def has_email(self, cr, uid, context=None):
+        return bool(self.pool.get('res.users').browse(cr, uid, uid, context=context).email)
+
     def _user_type_selection(self, cr, uid, context=None):
         """Selection values may be easily overridden/extended via inheritance"""
-        return [('embedded', 'Direct link or embed code'), ('emails','Emails'), ]
-
-    """Override of create() to auto-compute the action name"""
-    def create(self, cr, uid, values, context=None):
-        if 'action_id' in values and not 'name' in values:
-            action = self.pool.get('ir.actions.actions').browse(cr, uid, values['action_id'], context=context)
-            values['name'] = action.name
-        return super(share_wizard,self).create(cr, uid, values, context=context)
+        return [('embedded', 'Direct link or embed code'),
+                ('emails', 'Emails'),
+                ('existing', 'Users you already shared with'),
+                ('groups', 'Existing Groups (e.g Portal Groups)')]
 
     def share_url_template(self, cr, uid, _ids, context=None):
         # NOTE: take _ids in parameter to allow usage through browse_record objects
@@ -90,10 +89,10 @@
             base_url += '/login?db=%(dbname)s&login=%(login)s&key=%(password)s'
             extra = context and context.get('share_url_template_extra_arguments')
             if extra:
-                base_url += '&' + '&'.join('%s=%%(%s)s' % (x,x) for x in extra)
+                base_url += '&' + '&'.join('%s=%%(%s)s' % (x, x) for x in extra)
             hash_ = context and context.get('share_url_template_hash_arguments')
             if hash_:
-                base_url += '#' + '&'.join('%s=%%(%s)s' % (x,x) for x in hash_)
+                base_url += '#' + '&'.join('%s=%%(%s)s' % (x, x) for x in hash_)
         return base_url
 
     def _share_root_url(self, cr, uid, ids, _fieldname, _args, context=None):
@@ -157,20 +156,15 @@
                 result[this.id] = this.share_url_template(context=ctx) % data
         return result
 
-
     _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."),
         'view_type': fields.char('Current View Type', size=32, required=True),
         'domain': fields.char('Domain', size=256, help="Optional domain for further data filtering"),
-        'user_type': fields.selection(lambda s, *a, **k: s._user_type_selection(*a, **k),'Sharing method', required=True,
+        'user_type': fields.selection(lambda s, *a, **k: s._user_type_selection(*a, **k), 'Sharing method', required=True,
                      help="Select the type of user(s) you would like to share data with."),
         'new_users': fields.text("Emails"),
-        'email_1': fields.char('New user email', size=64),
-        'email_2': fields.char('New user email', size=64),
-        'email_3': fields.char('New user email', size=64),
-        'invite': fields.boolean('Invite users to OpenSocial record'),
-        'access_mode': fields.selection([('readonly','Can view'),('readwrite','Can edit')],'Access Mode', required=True,
+        'access_mode': fields.selection([('readonly', 'Can view'), ('readwrite', 'Can edit')], 'Access Mode', required=True,
                                         help="Access rights to be granted on the shared documents."),
         'result_line_ids': fields.one2many('share.wizard.result.line', 'share_wizard_id', 'Summary', readonly=True),
         'share_root_url': fields.function(_share_root_url, string='Share Access URL', type='char', size=512, readonly=True,
@@ -178,17 +172,21 @@
         'name': fields.char('Share Title', size=64, required=True, help="Title for the share (displayed to users as menu and shortcut name)"),
         'record_name': fields.char('Record name', size=128, help="Name of the shared record, if sharing a precise record"),
         'message': fields.text("Personal Message", help="An optional personal message, to be included in the email notification."),
+        # embed options
         'embed_code': fields.function(_embed_code, type='text', string='Code',
             help="Embed this code in your documents to provide a link to the "\
                   "shared document."),
         'embed_option_title': fields.boolean('Display title'),
         'embed_option_search': fields.boolean('Display search view'),
         'embed_url': fields.function(_embed_url, string='Share URL', type='char', size=512, readonly=True),
+        # existing users option
+        'user_ids': fields.many2many('res.users', 'share_wizard_res_user_rel', 'share_id', 'user_id', 'Existing users', domain=[('share', '=', True)]),
+        # groups option
+        'group_ids': fields.many2many('res.groups', 'share_wizard_res_group_rel', 'share_id', 'group_id', 'Existing groups', domain=[('share', '=', False)]),
     }
     _defaults = {
         'view_type': 'page',
-        'user_type' : 'embedded',
-        'invite': False,
+        'user_type': 'embedded',
         'domain': lambda self, cr, uid, context, *a: context.get('domain', '[]'),
         'action_id': lambda self, cr, uid, context, *a: context.get('action_id'),
         'access_mode': 'readwrite',
@@ -196,11 +194,15 @@
         'embed_option_search': True,
     }
 
-    def has_email(self, cr, uid, context=None):
-        return bool(self.pool.get('res.users').browse(cr, uid, uid, context=context).email)
+    """Override of create() to auto-compute the action name"""
+    def create(self, cr, uid, values, context=None):
+        if 'action_id' in values and not 'name' in values:
+            action = self.pool.get('ir.actions.actions').browse(cr, uid, values['action_id'], context=context)
+            values['name'] = action.name
+        return super(share_wizard, self).create(cr, uid, values, context=context)
 
     def go_step_1(self, cr, uid, ids, context=None):
-        wizard_data = self.browse(cr,uid,ids,context)[0]
+        wizard_data = self.browse(cr, uid, ids, context)[0]
         if wizard_data.user_type == 'emails' and not self.has_email(cr, uid, context=context):
             raise osv.except_osv(_('No email address configured'),
                                  _('You must configure your email address in the user preferences before using the Share button.'))
@@ -212,7 +214,7 @@
 
     def _create_share_group(self, cr, uid, wizard_data, context=None):
         group_obj = self.pool.get('res.groups')
-        share_group_name = '%s: %s (%d-%s)' %('Shared', wizard_data.name, uid, time.time())
+        share_group_name = '%s: %s (%d-%s)' % ('Shared', wizard_data.name, uid, time.time())
         # create share group without putting admin in it
         return group_obj.create(cr, UID_ROOT, {'name': share_group_name, 'share': True}, {'noadmin': True})
 
@@ -233,7 +235,6 @@
         if wizard_data.user_type == 'emails':
             # get new user list from email data
             new_users = (wizard_data.new_users or '').split('\n')
-            new_users += [wizard_data.email_1 or '', wizard_data.email_2 or '', wizard_data.email_3 or '']
             for new_user in new_users:
                 # Ignore blank lines
                 new_user = new_user.strip()
@@ -661,9 +662,17 @@
                      _('You must be a member of the Share/User group to use the share wizard.'),
                      context=context)
         if wizard_data.user_type == 'emails':
-            self._assert((wizard_data.new_users or wizard_data.email_1 or wizard_data.email_2 or wizard_data.email_3),
+            self._assert((wizard_data.new_users),
                      _('Please indicate the emails of the persons to share with, one per line.'),
                      context=context)
+        elif wizard_data.user_type == 'existing':
+            self._assert(wizard_data.user_ids,
+                     _('Please select at least one user to share with'),
+                     context=context)
+        elif wizard_data.user_type == 'groups':
+            self._assert(wizard_data.group_ids,
+                     _('Please select at least one group to share with'),
+                     context=context)
 
     def _create_share_users_group(self, cr, uid, wizard_data, context=None):
         """Creates the appropriate share group and share users, and populates
@@ -777,37 +786,36 @@
             self.pool.get(model.model).message_subscribe(cr, uid, [res_id], new_ids + existing_ids, context=context)
             # self.send_invite_email(cr, uid, wizard_data, context=context)
             # self.send_invite_note(cr, uid, model.model, res_id, wizard_data, context=context)
-        
+
         # CLOSE
         #  A. Not invite: as before
         #  B. Invite: skip summary screen, get back to the record
-        
+
         # A.
-        if not wizard_data.invite:
-            dummy, step2_form_view_id = self.pool.get('ir.model.data').get_object_reference(cr, uid, 'share', 'share_step2_form')
-            return {
-                'name': _('Shared access created!'),
-                'view_type': 'form',
-                'view_mode': 'form',
-                'res_model': 'share.wizard',
-                'view_id': False,
-                'res_id': ids[0],
-                'views': [(step2_form_view_id, 'form'), (False, 'tree'), (False, 'calendar'), (False, 'graph')],
-                'type': 'ir.actions.act_window',
-                'target': 'new'
-            }
+        # if not wizard_data.invite:
+        dummy, step2_form_view_id = self.pool.get('ir.model.data').get_object_reference(cr, uid, 'share', 'share_step2_form')
+        return {
+            'name': _('Shared access created!'),
+            'view_type': 'form',
+            'view_mode': 'form',
+            'res_model': 'share.wizard',
+            'view_id': False,
+            'res_id': ids[0],
+            'views': [(step2_form_view_id, 'form'), (False, 'tree'), (False, 'calendar'), (False, 'graph')],
+            'type': 'ir.actions.act_window',
+            'target': 'new'
+        }
         # B.
-        else:
-            return {
-                'view_type': 'form',
-                'view_mode': 'form',
-                'res_model': model.model,
-                'view_id': False,
-                'res_id': res_id,
-                'views': [(False, 'form'), (False, 'tree'), (False, 'calendar'), (False, 'graph')],
-                'type': 'ir.actions.act_window',
-            }
-            
+        # else:
+        #     return {
+        #         'view_type': 'form',
+        #         'view_mode': 'form',
+        #         'res_model': model.model,
+        #         'view_id': False,
+        #         'res_id': res_id,
+        #         'views': [(False, 'form'), (False, 'tree'), (False, 'calendar'), (False, 'graph')],
+        #         'type': 'ir.actions.act_window',
+        #     }
 
     def send_invite_note(self, cr, uid, model_name, res_id, wizard_data, context=None):
         subject = _('Invitation')
@@ -899,13 +907,10 @@
         options = dict(title=opt_title, search=opt_search)
         return {'value': {'embed_code': self._generate_embedded_code(wizard, options)}}
 
-share_wizard()
-
 class share_result_line(osv.osv_memory):
     _name = 'share.wizard.result.line'
     _rec_name = 'user_id'
 
-
     def _share_url(self, cr, uid, ids, _fieldname, _args, context=None):
         result = dict.fromkeys(ids, '')
         for this in self.browse(cr, uid, ids, context=context):

=== modified file 'share/wizard/share_wizard_view.xml'
--- share/wizard/share_wizard_view.xml	2012-08-09 06:05:16 +0000
+++ share/wizard/share_wizard_view.xml	2012-09-10 09:31:26 +0000
@@ -31,24 +31,23 @@
                 <form string="Configuration" version="7.0">
                     <group>
                         <field name="user_type" invisible="1"/>
-                        <field name="invite" invisible="1"/>
                     </group>
                     <group>
-                        <group colspan="4" name="emails_group" attrs="{'invisible':['|', ('user_type', '!=', 'emails'), ('invite', '=', True)]}"
+                        <group colspan="4" name="emails_group" attrs="{'invisible':[('user_type', '!=', 'emails')]}"
                             string="Share with these People (one email per line)">
-                            <field nolabel="1" name="new_users" attrs="{'required':[('user_type','=','emails'), ('invite', '!=', True)]}"/>
+                            <field nolabel="1" name="new_users" attrs="{'required':[('user_type','=','emails')]}"/>
                         </group>
-                        <group colspan="4" name="email_lines" attrs="{'invisible':['|', ('invite', '!=', True), ('user_type', '!=', 'emails')]}"
+                        <group colspan="4" name="email_lines" attrs="{'invisible':[('user_type', '!=', 'emails')]}"
                             string="Share with these People (one email per line)">
-                            <field name="email_1"/>
+<!--                             <field name="email_1"/>
                             <field name="email_2"/>
-                            <field name="email_3"/>
+                            <field name="email_3"/> -->
                         </group>
                         <group colspan="4" attrs="{'invisible':[('user_type', '=', 'embedded')]}"
                             string="Include an Optional Personal Message">
                             <field name="message" colspan="2" nolabel="1"/>
                         </group>
-                        <group attrs="{'invisible':[('invite', '=', True)]}" string="Sharing Options">
+                        <group string="Sharing Options">
                             <field name="name"/>
                             <field name="access_mode"/>
                         </group>

_______________________________________________
Mailing list: https://launchpad.net/~openerp-dev-gtk
Post to     : [email protected]
Unsubscribe : https://launchpad.net/~openerp-dev-gtk
More help   : https://help.launchpad.net/ListHelp

Reply via email to