[IMP] Improved share-invite mechanism. Also slighty refactored code in emails sending.
bzr revid: tde@openerp.com-20120328090052-v73mn3tdnjat4kkb
This commit is contained in:
parent
a945ee82c9
commit
3d6c40394a
|
@ -8,12 +8,15 @@ function launch_wizard(self, view, user_type, invite) {
|
|||
if (view.fields_view.type == 'form') {
|
||||
domain = new session.web.CompoundDomain(domain, [['id', '=', view.datarecord.id]]);
|
||||
}
|
||||
if (view.fields_view.type == 'form') rec_name = view.datarecord.name;
|
||||
else rec_name = '';
|
||||
self.rpc('/web/session/eval_domain_and_context', {
|
||||
domains: [domain],
|
||||
contexts: [view.dataset.context]
|
||||
}, function (result) {
|
||||
Share.create({
|
||||
name: action.name,
|
||||
record_name: rec_name,
|
||||
domain: result.domain,
|
||||
action_id: action.id,
|
||||
user_type: user_type || 'embedded',
|
||||
|
@ -78,11 +81,11 @@ session.web.ViewManagerAction.include({
|
|||
},
|
||||
on_click_share_link: function(e) {
|
||||
e.preventDefault();
|
||||
launch_wizard(this, this.views[this.active_view].controller);
|
||||
launch_wizard(this, this.views[this.active_view].controller, 'embedded', false);
|
||||
},
|
||||
on_click_share: function(e) {
|
||||
e.preventDefault();
|
||||
launch_wizard(this, this.views[this.active_view].controller, 'emails');
|
||||
launch_wizard(this, this.views[this.active_view].controller, 'emails', false);
|
||||
},
|
||||
on_click_share_mail: function(e) {
|
||||
e.preventDefault();
|
||||
|
|
|
@ -175,6 +175,7 @@ class share_wizard(osv.osv_memory):
|
|||
'share_root_url': fields.function(_share_root_url, string='Share Access URL', type='char', size=512, readonly=True,
|
||||
help='Main access page for users that are granted shared access'),
|
||||
'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 e-mail notification."),
|
||||
|
||||
'embed_code': fields.function(_embed_code, type='text'),
|
||||
|
@ -201,10 +202,7 @@ class share_wizard(osv.osv_memory):
|
|||
if wizard_data.user_type == 'emails' and not self.has_email(cr, uid, context=context):
|
||||
raise osv.except_osv(_('No e-mail address configured'),
|
||||
_('You must configure your e-mail address in the user preferences before using the Share button.'))
|
||||
if wizard_data.invite:
|
||||
model, res_id = self.pool.get('ir.model.data').get_object_reference(cr, uid, 'share', 'action_share_wizard_step1_mail')
|
||||
else:
|
||||
model, res_id = self.pool.get('ir.model.data').get_object_reference(cr, uid, 'share', 'action_share_wizard_step1')
|
||||
model, res_id = self.pool.get('ir.model.data').get_object_reference(cr, uid, 'share', 'action_share_wizard_step1')
|
||||
action = self.pool.get(model).read(cr, uid, res_id, context=context)
|
||||
action['res_id'] = ids[0]
|
||||
action.pop('context', '')
|
||||
|
@ -257,6 +255,7 @@ class share_wizard(osv.osv_memory):
|
|||
'user_email': new_user,
|
||||
'groups_id': [(6,0,[group_id])],
|
||||
'share': True,
|
||||
'message_email_pref': 'all',
|
||||
'company_id': current_user.company_id.id
|
||||
}, context)
|
||||
new_line = { 'user_id': user_id,
|
||||
|
@ -746,75 +745,140 @@ class share_wizard(osv.osv_memory):
|
|||
# refresh wizard_data
|
||||
wizard_data = self.browse(cr, uid, ids[0], context=context)
|
||||
|
||||
# Invite (OpenSocial): automatically subscribe users to the record
|
||||
res_id = 0
|
||||
for cond in safe_eval(main_domain):
|
||||
if cond[0] == 'id':
|
||||
res_id = cond[2]
|
||||
if wizard_data.invite and res_id > 0:
|
||||
# EMAILS AND NOTIFICATIONS
|
||||
# A. Not invite: as before
|
||||
# -> send emails to destination users
|
||||
# B. Invite (OpenSocial)
|
||||
# -> subscribe all users (existing and new) to the record
|
||||
# -> send a notification with a summary to the current record
|
||||
# -> send a notification to all users; users allowing to receive
|
||||
# emails in preferences will receive it
|
||||
# new users by default receive all notifications by email
|
||||
|
||||
# A.
|
||||
if not wizard_data.invite:
|
||||
self.send_emails(cr, uid, wizard_data, context=context)
|
||||
# B.
|
||||
else:
|
||||
# Invite (OpenSocial): automatically subscribe users to the record
|
||||
res_id = 0
|
||||
for cond in safe_eval(main_domain):
|
||||
if cond[0] == 'id':
|
||||
res_id = cond[2]
|
||||
# Record id not found: issue
|
||||
if res_id <= 0:
|
||||
raise osv.except_osv(_('Record id not found'), _('The share engine has not been able to fetch a record_id for your invitation.'))
|
||||
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'
|
||||
}
|
||||
# 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',
|
||||
}
|
||||
|
||||
|
||||
# send the confirmation emails:
|
||||
self.send_emails(cr, uid, wizard_data, context=context)
|
||||
|
||||
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'
|
||||
}
|
||||
|
||||
def send_invite_note(self, cr, uid, model_name, res_id, wizard_data, context=None):
|
||||
subject = _('Invitation')
|
||||
body = 'has been <b>shared</b> with'
|
||||
tmp_idx = 0
|
||||
for result_line in wizard_data.result_line_ids:
|
||||
body += ' @%s' % (result_line.user_id.login)
|
||||
if tmp_idx < len(wizard_data.result_line_ids)-2:
|
||||
body += ','
|
||||
elif tmp_idx == len(wizard_data.result_line_ids)-2:
|
||||
body += ' and'
|
||||
body += '.'
|
||||
return self.pool.get(model_name).message_append_note(cr, uid, [res_id], _('System Notification'), body, context=context)
|
||||
|
||||
def send_invite_email(self, cr, uid, wizard_data, context=None):
|
||||
message_obj = self.pool.get('mail.message')
|
||||
notification_obj = self.pool.get('mail.notification')
|
||||
user = self.pool.get('res.users').browse(cr, UID_ROOT, uid)
|
||||
if not user.user_email:
|
||||
raise osv.except_osv(_('Email required'), _('The current user must have an email address configured in User Preferences to be able to send outgoing emails.'))
|
||||
|
||||
# TODO: also send an HTML version of this mail
|
||||
for result_line in wizard_data.result_line_ids:
|
||||
email_to = result_line.user_id.user_email
|
||||
if not email_to:
|
||||
continue
|
||||
subject = _('Invitation to collaborate about %s') % (wizard_data.record_name)
|
||||
body = _("Hello,\n\n")
|
||||
body += _("I have shared %s (%s) with you!\n\n") % (wizard_data.record_name, wizard_data.name)
|
||||
if wizard_data.message:
|
||||
body += "%s\n\n" % (wizard_data.message)
|
||||
if result_line.newly_created:
|
||||
body += _("The documents are not attached, you can view them online directly on my OpenERP server at:\n %s\n\n") % (result_line.share_url)
|
||||
body += _("These are your credentials to access this protected area:\n")
|
||||
body += "%s: %s" % (_("Username"), result_line.user_id.login) + "\n"
|
||||
body += "%s: %s" % (_("Password"), result_line.password) + "\n"
|
||||
body += "%s: %s" % (_("Database"), cr.dbname) + "\n"
|
||||
body += _("The documents have been automatically added to your subscriptions.\n\n")
|
||||
body += '%s\n\n' % ((user.signature or ''))
|
||||
body += "--\n"
|
||||
body += _("OpenERP is a powerful and user-friendly suite of Business Applications (CRM, Sales, HR, etc.)\n"
|
||||
"It is open source and can be found on http://www.openerp.com.")
|
||||
msg_id = message_obj.schedule_with_attach(cr, uid, user.user_email, [email_to], subject, body, model='', context=context)
|
||||
notification_obj.create(cr, uid, {'user_id': result_line.user_id.id, 'message_id': msg_id}, context=context)
|
||||
|
||||
def send_emails(self, cr, uid, wizard_data, context=None):
|
||||
self._logger.info('Sending share notifications by email...')
|
||||
mail_message = self.pool.get('mail.message')
|
||||
user = self.pool.get('res.users').browse(cr, UID_ROOT, uid)
|
||||
|
||||
if not user.user_email:
|
||||
raise osv.except_osv(_('Email required'), _('The current user must have an email address configured in User Preferences to be able to send outgoing emails.'))
|
||||
|
||||
# TODO: also send an HTML version of this mail
|
||||
msg_ids = []
|
||||
for result_line in wizard_data.result_line_ids:
|
||||
email_to = result_line.user_id.user_email
|
||||
if not email_to:
|
||||
continue
|
||||
if not user.user_email:
|
||||
raise osv.except_osv(_('Email required'), _('The current user must have an email address configured in User Preferences to be able to send outgoing emails.'))
|
||||
subject = wizard_data.name
|
||||
body = _("Hello,")
|
||||
body += "\n\n"
|
||||
body += _("I've shared %s with you!") % wizard_data.name
|
||||
body += "\n\n"
|
||||
body += _("The documents are not attached, you can view them online directly on my OpenERP server at:")
|
||||
body += "\n " + result_line.share_url
|
||||
body += "\n\n"
|
||||
body = _("Hello,\n\n")
|
||||
body += _("I've shared %s with you!\n\n") % wizard_data.name
|
||||
body += _("The documents are not attached, you can view them online directly on my OpenERP server at:\n %s\n\n") % (result_line.share_url)
|
||||
if wizard_data.message:
|
||||
body += wizard_data.message
|
||||
body += "\n\n"
|
||||
body += '%s\n\n' % (wizard_data.message)
|
||||
if result_line.newly_created:
|
||||
body += _("These are your credentials to access this protected area:\n")
|
||||
body += "%s: %s" % (_("Username"), result_line.user_id.login) + "\n"
|
||||
body += "%s: %s" % (_("Password"), result_line.password) + "\n"
|
||||
body += "%s: %s" % (_("Database"), cr.dbname) + "\n"
|
||||
body += "%s: %s\n" % (_("Username"), result_line.user_id.login)
|
||||
body += "%s: %s\n" % (_("Password"), result_line.password)
|
||||
body += "%s: %s\n" % (_("Database"), cr.dbname)
|
||||
else:
|
||||
body += _("The documents have been automatically added to your current OpenERP documents.\n")
|
||||
body += _("You may use your current login (%s) and password to view them.\n") % result_line.user_id.login
|
||||
body += "\n\n"
|
||||
body += (user.signature or '')
|
||||
body += "\n\n"
|
||||
body += "\n\n%s\n\n" % ( (user.signature or '') )
|
||||
body += "--\n"
|
||||
body += _("OpenERP is a powerful and user-friendly suite of Business Applications (CRM, Sales, HR, etc.)\n"
|
||||
"It is open source and can be found on http://www.openerp.com.")
|
||||
msg_ids.append(mail_message.schedule_with_attach(cr, uid,
|
||||
user.user_email,
|
||||
[email_to],
|
||||
subject,
|
||||
body,
|
||||
model='share.wizard',
|
||||
context=context))
|
||||
msg_ids.append(mail_message.schedule_with_attach(cr, uid, user.user_email, [email_to], subject, body, model='share.wizard', context=context))
|
||||
# force direct delivery, as users expect instant notification
|
||||
mail_message.send(cr, uid, msg_ids, context=context)
|
||||
self._logger.info('%d share notification(s) sent.', len(msg_ids))
|
||||
|
|
|
@ -30,47 +30,23 @@
|
|||
<field name="arch" type="xml">
|
||||
<form>
|
||||
<field name="user_type" invisible="1"/>
|
||||
<group colspan="4" name="emails_group" attrs="{'invisible':[('user_type', '!=', 'emails')]}">
|
||||
<field name="invite" invisible="1"/>
|
||||
<group colspan="4" name="emails_group" attrs="{'invisible':['|', ('user_type', '!=', 'emails'), ('invite', '=', True)]}">
|
||||
<separator colspan="4" string="Share with these people (one e-mail per line)"/>
|
||||
<field colspan="4" nolabel="1" name="new_users" attrs="{'required':[('user_type','=','emails')]}"/>
|
||||
<field colspan="4" nolabel="1" name="new_users" attrs="{'required':[('user_type','=','emails'), ('invite', '!=', True)]}"/>
|
||||
</group>
|
||||
<group colspan="4" col="4" attrs="{'invisible':[('user_type', '=', 'embedded')]}">
|
||||
<separator colspan="4" string="Optional: include a personal message"/>
|
||||
<field name="message" colspan="4" nolabel="1"/>
|
||||
</group>
|
||||
<separator colspan="4" string="Sharing Options"/>
|
||||
<group colspan="4" col="4">
|
||||
<field name="name" colspan="4"/>
|
||||
<field name="access_mode" colspan="4"/>
|
||||
</group>
|
||||
<separator colspan="4"/>
|
||||
<group colspan="4">
|
||||
<button special="cancel" string="Cancel" icon='gtk-cancel'/>
|
||||
<button name="go_step_2" string="Share" colspan="1" type="object" icon="gtk-go-forward"/>
|
||||
</group>
|
||||
</form>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record id="share_step1_mail_form" model="ir.ui.view">
|
||||
<field name="name">share.step1_mail.form</field>
|
||||
<field name="model">share.wizard</field>
|
||||
<field name="type">form</field>
|
||||
<field name="arch" type="xml">
|
||||
<form>
|
||||
<field name="user_type" invisible="1"/>
|
||||
<group colspan="4" name="emails_group" attrs="{'invisible':[('user_type', '!=', 'emails')]}">
|
||||
<group colspan="4" col="2" name="email_lines" attrs="{'invisible':[('invite', '!=', True)]}">
|
||||
<separator colspan="4" string="Share with these people (one e-mail per line)"/>
|
||||
<field name="email_1"/>
|
||||
<field name="email_2"/>
|
||||
<field name="email_3"/>
|
||||
</group>
|
||||
<group colspan="4" col="4" attrs="{'invisible':[('user_type', '=', 'embedded')]}">
|
||||
<separator colspan="4" string="Optional: include a personal message"/>
|
||||
<separator colspan="4" string="Include an optional personal message"/>
|
||||
<field name="message" colspan="4" nolabel="1"/>
|
||||
</group>
|
||||
<separator colspan="4" string="Sharing Options"/>
|
||||
<group colspan="4" col="4">
|
||||
<group colspan="4" col="4" attrs="{'invisible':[('invite', '=', True)]}">
|
||||
<separator colspan="4" string="Sharing Options"/>
|
||||
<field name="name" colspan="4"/>
|
||||
<field name="access_mode" colspan="4"/>
|
||||
</group>
|
||||
|
@ -152,16 +128,5 @@
|
|||
<field name="context">False</field>
|
||||
</record>
|
||||
|
||||
<record id="action_share_wizard_step1_mail" model="ir.actions.act_window">
|
||||
<field name="name">Share your documents</field>
|
||||
<field name="type">ir.actions.act_window</field>
|
||||
<field name="res_model">share.wizard</field>
|
||||
<field name="view_type">form</field>
|
||||
<field name="view_mode">form</field>
|
||||
<field name="view_id" ref="share_step1_mail_form"/>
|
||||
<field name="target">new</field>
|
||||
<field name="context">False</field>
|
||||
</record>
|
||||
|
||||
</data>
|
||||
</openerp>
|
||||
|
|
Loading…
Reference in New Issue