From a3de5c872f7c26ec085dc62b95cfc62382ab970a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Tue, 9 Apr 2013 13:11:58 +0200 Subject: [REF] [IMP] mail_alias improvement alias_name is not required anymore crm, hr_job, project, mail_group, res_users: alias creation is now different and done more like other inherits, except an alias_model_name that is given to the context to find the alias alias_model_id. crm, jr_job, project, mail_group, res_users: updated form views using aliases mail_alias: added a filter on 'inactive' aliases (alias_name False) and added a button to redirect to the related document if any bzr revid: tde@openerp.com-20130409111158-bv04n5o01z9l3c17 --- addons/mail/res_users.py | 23 +++++++---------------- 1 file changed, 7 insertions(+), 16 deletions(-) (limited to 'addons/mail/res_users.py') diff --git a/addons/mail/res_users.py b/addons/mail/res_users.py index f7c91939b98..0f4e5af64e6 100644 --- a/addons/mail/res_users.py +++ b/addons/mail/res_users.py @@ -23,6 +23,7 @@ from openerp.osv import fields, osv from openerp import SUPERUSER_ID from openerp.tools.translate import _ + class res_users(osv.Model): """ Update of res.users class - add a preference about sending emails about notifications @@ -64,20 +65,16 @@ class res_users(osv.Model): self._columns['alias_id'], 'login', alias_force_key='id', context=context) def create(self, cr, uid, data, context=None): - # create default alias same as the login if not data.get('login', False): raise osv.except_osv(_('Invalid Action!'), _('You may not create a user. To create new users, you should use the "Settings > Users" menu.')) + if context is None: + context = {} - mail_alias = self.pool.get('mail.alias') - alias_id = mail_alias.create_unique_alias(cr, uid, {'alias_name': data['login']}, model_name=self._name, context=context) - data['alias_id'] = alias_id - data.pop('alias_name', None) # prevent errors during copy() - - # create user - user_id = super(res_users, self).create(cr, uid, data, context=context) + create_context = dict(context, alias_model_name=self._name) + user_id = super(res_users, self).create(cr, uid, data, context=create_context) user = self.browse(cr, uid, user_id, context=context) - # alias - mail_alias.write(cr, SUPERUSER_ID, [alias_id], {"alias_force_thread_id": user_id}, context) + self.pool.get('mail.alias').write(cr, SUPERUSER_ID, [user.alias_id.id], {"alias_force_thread_id": user_id}, context) + # create a welcome message self._create_welcome_message(cr, uid, user, context=context) return user_id @@ -91,12 +88,6 @@ class res_users(osv.Model): return self.pool.get('res.partner').message_post(cr, SUPERUSER_ID, [user.partner_id.id], body=body, context=context) - def write(self, cr, uid, ids, vals, context=None): - # User alias is sync'ed with login - if vals.get('login'): - vals['alias_name'] = vals['login'] - return super(res_users, self).write(cr, uid, ids, vals, context=context) - def unlink(self, cr, uid, ids, context=None): # Cascade-delete mail aliases as well, as they should not exist without the user. alias_pool = self.pool.get('mail.alias') -- cgit v1.2.3 From 88e3505554038350ae0274e9359bbffff342b9d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Thu, 16 May 2013 18:42:07 +0200 Subject: [IMP] mail_alias: added reference to the parent record. The parent record is the record that holds the alias. It is different from the record updated or created using the alias. For example projects have aliases whose parent is the given projet, and that creates new task inside the project. Updated alias creation and management accordingly. This ownership concept is used to compute the 'followers' contact settings of aliases. bzr revid: tde@openerp.com-20130516164207-1zr0q6abw6a34ndf --- addons/mail/res_users.py | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) (limited to 'addons/mail/res_users.py') diff --git a/addons/mail/res_users.py b/addons/mail/res_users.py index 87a625877bc..3a21fce1849 100644 --- a/addons/mail/res_users.py +++ b/addons/mail/res_users.py @@ -40,10 +40,6 @@ class res_users(osv.Model): "emails will appear in the user's notifications."), } - _defaults = { - 'alias_domain': False, # always hide alias during creation - } - def __init__(self, pool, cr): """ Override of __init__ to add access rights on notification_email_send and alias fields. Access rights are disabled by default, but allowed @@ -62,7 +58,7 @@ class res_users(osv.Model): """ Installation hook: aliases, partner following themselves """ # create aliases for all users and avoid constraint errors res = self.pool.get('mail.alias').migrate_to_alias(cr, self._name, self._table, super(res_users, self)._auto_init, - self._columns['alias_id'], 'login', alias_force_key='id', context=context) + self._name, self._columns['alias_id'], 'login', alias_force_key='id', context=context) return res def create(self, cr, uid, data, context=None): @@ -71,10 +67,10 @@ class res_users(osv.Model): if context is None: context = {} - create_context = dict(context, alias_model_name=self._name) + create_context = dict(context, alias_model_name=self._name, alias_parent_model_name=self._name) user_id = super(res_users, self).create(cr, uid, data, context=create_context) user = self.browse(cr, uid, user_id, context=context) - self.pool.get('mail.alias').write(cr, SUPERUSER_ID, [user.alias_id.id], {"alias_force_thread_id": user_id}, context) + self.pool.get('mail.alias').write(cr, SUPERUSER_ID, [user.alias_id.id], {"alias_force_thread_id": user_id, "alias_parent_thread_id": user_id}, context) # create a welcome message self._create_welcome_message(cr, uid, user, context=context) -- cgit v1.2.3