[REF] mail: remove required alias on users
This commit remove required alias on res.users model. It also removes the inheritance of mail.alias.mixin. The field alias_id is kept and allow people to use aliases on users if they want. However there is no default void alias created for each user anymore. Default from of mail.message does not use user alias anymore. Indeed this creates issues with aliases not being correctly configured and can be confusing compared to private channels. Using user aliases is therefore now done manually instead of being a default behavior.
This commit is contained in:
@@ -9,8 +9,6 @@
|
||||
<field name="active" eval="False"/>
|
||||
<!-- Avoid auto-including this user in any default group, just like a typical portal member -->
|
||||
<field name="groups_id" eval="[(6, 0, [ref('base.group_portal')])]"/>
|
||||
<!-- allow signuped users to have a alias -->
|
||||
<field name="alias_name">_usertemplate</field>
|
||||
</record>
|
||||
|
||||
<record id="default_template_user_config" model="ir.config_parameter">
|
||||
|
||||
@@ -18,7 +18,6 @@ class TestCrm(TestMail):
|
||||
cls.user_salesman_all = Users.create({
|
||||
'name': 'Riton La Chignole',
|
||||
'login': 'riton',
|
||||
'alias_name': 'riton',
|
||||
'email': 'riton.salesman_all@example.com',
|
||||
'groups_id': [(6, 0, [user_group_employee.id, user_group_salesman_all.id])]
|
||||
})
|
||||
|
||||
@@ -27,7 +27,6 @@ class TestEventCommon(common.TransactionCase):
|
||||
self.user_eventuser = self.Users.with_context({'no_reset_password': True}).create({
|
||||
'name': 'Armande EventUser',
|
||||
'login': 'Armande',
|
||||
'alias_name': 'armande',
|
||||
'email': 'armande.eventuser@example.com',
|
||||
'tz': 'Europe/Brussels',
|
||||
'groups_id': [(6, 0, [self.group_employee_id, self.group_event_user_id])]
|
||||
@@ -35,7 +34,6 @@ class TestEventCommon(common.TransactionCase):
|
||||
self.user_eventmanager = self.Users.with_context({'no_reset_password': True}).create({
|
||||
'name': 'Bastien EventManager',
|
||||
'login': 'bastien',
|
||||
'alias_name': 'bastien',
|
||||
'email': 'bastien.eventmanager@example.com',
|
||||
'tz': 'Europe/Brussels',
|
||||
'groups_id': [(6, 0, [
|
||||
|
||||
@@ -18,21 +18,18 @@ class TestHrHolidaysBase(common.TransactionCase):
|
||||
self.user_hruser_id = Users.create({
|
||||
'name': 'Armande HrUser',
|
||||
'login': 'Armande',
|
||||
'alias_name': 'armande',
|
||||
'email': 'armande.hruser@example.com',
|
||||
'groups_id': [(6, 0, [group_employee_id, self.ref('base.group_hr_user')])]
|
||||
}).id
|
||||
self.user_hrmanager_id = Users.create({
|
||||
'name': 'Bastien HrManager',
|
||||
'login': 'bastien',
|
||||
'alias_name': 'bastien',
|
||||
'email': 'bastien.hrmanager@example.com',
|
||||
'groups_id': [(6, 0, [group_employee_id, self.ref('base.group_hr_manager')])]
|
||||
}).id
|
||||
self.user_employee_id = Users.create({
|
||||
'name': 'David Employee',
|
||||
'login': 'david',
|
||||
'alias_name': 'david',
|
||||
'email': 'david.employee@example.com',
|
||||
'groups_id': [(6, 0, [group_employee_id])]
|
||||
}).id
|
||||
|
||||
@@ -26,11 +26,9 @@ class Message(models.Model):
|
||||
|
||||
@api.model
|
||||
def _get_default_from(self):
|
||||
if self.env.user.alias_name and self.env.user.alias_domain:
|
||||
return formataddr((self.env.user.name, '%s@%s' % (self.env.user.alias_name, self.env.user.alias_domain)))
|
||||
elif self.env.user.email:
|
||||
if self.env.user.email:
|
||||
return formataddr((self.env.user.name, self.env.user.email))
|
||||
raise UserError(_("Unable to send email, please configure the sender's email address or alias."))
|
||||
raise UserError(_("Unable to send email, please configure the sender's email address."))
|
||||
|
||||
@api.model
|
||||
def _get_default_author(self):
|
||||
|
||||
@@ -14,11 +14,15 @@ class Users(models.Model):
|
||||
group, and the user. This is done by overriding the write method.
|
||||
"""
|
||||
_name = 'res.users'
|
||||
_inherit = ['mail.alias.mixin', 'res.users']
|
||||
_inherit = ['res.users']
|
||||
|
||||
alias_id = fields.Many2one('mail.alias', 'Alias', ondelete="restrict", required=True,
|
||||
alias_id = fields.Many2one('mail.alias', 'Alias', ondelete="set null", required=False,
|
||||
help="Email address internally associated with this user. Incoming "\
|
||||
"emails will appear in the user's notifications.", copy=False, auto_join=True)
|
||||
alias_contact = fields.Selection([
|
||||
('everyone', 'Everyone'),
|
||||
('partners', 'Authenticated Partners'),
|
||||
('followers', 'Followers only')], string='Alias Contact Security', related='alias_id.alias_contact')
|
||||
|
||||
def __init__(self, pool, cr):
|
||||
""" Override of __init__ to add access rights on notification_email_send
|
||||
@@ -31,17 +35,9 @@ class Users(models.Model):
|
||||
type(self).SELF_WRITEABLE_FIELDS.extend(['notify_email'])
|
||||
# duplicate list to avoid modifying the original reference
|
||||
type(self).SELF_READABLE_FIELDS = list(self.SELF_READABLE_FIELDS)
|
||||
type(self).SELF_READABLE_FIELDS.extend(['notify_email', 'alias_domain', 'alias_name'])
|
||||
type(self).SELF_READABLE_FIELDS.extend(['notify_email'])
|
||||
return init_res
|
||||
|
||||
def get_alias_model_name(self, vals):
|
||||
return self._name
|
||||
|
||||
def get_alias_values(self):
|
||||
values = super(Users, self).get_alias_values()
|
||||
values['alias_force_thread_id'] = self.id
|
||||
return values
|
||||
|
||||
@api.model
|
||||
def create(self, values):
|
||||
if not values.get('login', False):
|
||||
@@ -65,13 +61,6 @@ class Users(models.Model):
|
||||
self.env['mail.channel'].search([('group_ids', 'in', user_group_ids)])._subscribe_users()
|
||||
return write_res
|
||||
|
||||
@api.multi
|
||||
def copy_data(self, default=None):
|
||||
data = super(Users, self).copy_data(default)[0]
|
||||
if data and data.get('alias_name'):
|
||||
data['alias_name'] = data['login']
|
||||
return [data]
|
||||
|
||||
def _create_welcome_message(self):
|
||||
self.ensure_one()
|
||||
if not self.has_group('base.group_user'):
|
||||
|
||||
@@ -56,7 +56,6 @@ class TestMail(common.SavepointCase):
|
||||
cls.user_employee = Users.create({
|
||||
'name': 'Ernest Employee',
|
||||
'login': 'ernest',
|
||||
'alias_name': 'ernest',
|
||||
'email': 'e.e@example.com',
|
||||
'signature': '--\nErnest',
|
||||
'notify_email': 'always',
|
||||
@@ -64,7 +63,6 @@ class TestMail(common.SavepointCase):
|
||||
cls.user_public = Users.create({
|
||||
'name': 'Bert Tartignole',
|
||||
'login': 'bert',
|
||||
'alias_name': 'bert',
|
||||
'email': 'b.t@example.com',
|
||||
'signature': 'SignBert',
|
||||
'notify_email': 'always',
|
||||
@@ -72,7 +70,6 @@ class TestMail(common.SavepointCase):
|
||||
cls.user_portal = Users.create({
|
||||
'name': 'Chell Gladys',
|
||||
'login': 'chell',
|
||||
'alias_name': 'chell',
|
||||
'email': 'chell@gladys.portal',
|
||||
'signature': 'SignChell',
|
||||
'notify_email': 'always',
|
||||
|
||||
@@ -9,22 +9,8 @@ class TestMailFeatures(TestMail):
|
||||
# TDE TODO: tests on the redirection controller
|
||||
|
||||
def test_alias_setup(self):
|
||||
Users = self.env['res.users'].with_context({'no_reset_password': True})
|
||||
|
||||
user_valentin = Users.create({
|
||||
'name': 'Valentin Cognito', 'email': 'valentin.cognito@gmail.com',
|
||||
'login': 'valentin.cognito', 'alias_name': 'valentin.cognito'})
|
||||
self.assertEqual(user_valentin.alias_name, user_valentin.login, "Login should be used as alias")
|
||||
|
||||
user_pagan = Users.create({
|
||||
'name': 'Pagan Le Marchant', 'email': 'plmarchant@gmail.com',
|
||||
'login': 'plmarchant@gmail.com', 'alias_name': 'plmarchant@gmail.com'})
|
||||
self.assertEqual(user_pagan.alias_name, 'plmarchant', "If login is an email, the alias should keep only the local part")
|
||||
|
||||
user_barty = Users.create({
|
||||
'name': 'Bartholomew Ironside', 'email': 'barty@gmail.com',
|
||||
'login': 'b4r+_#_R3wl$$', 'alias_name': 'b4r+_#_R3wl$$'})
|
||||
self.assertEqual(user_barty.alias_name, 'b4r+_-_r3wl-', 'Disallowed chars should be replaced by hyphens')
|
||||
alias = self.env['mail.alias'].with_context(alias_model_name='mail.channel').create({'alias_name': 'b4r+_#_R3wl$$'})
|
||||
self.assertEqual(alias.alias_name, 'b4r+_-_r3wl-', 'Disallowed chars should be replaced by hyphens')
|
||||
|
||||
@mute_logger('openerp.addons.mail.models.mail_mail')
|
||||
def test_needaction(self):
|
||||
@@ -138,8 +124,8 @@ class TestMessagePost(TestMail):
|
||||
|
||||
# notification emails: followers + recipients - notify_email=none (partner_2) - author (user_employee)
|
||||
self.assertEqual(set(m['email_from'] for m in self._mails),
|
||||
set(['%s <%s@%s>' % (self.user_employee.name, self.user_employee.alias_name, _domain)]),
|
||||
'message_post: notification email wrong email_from: should use alias of sender')
|
||||
set(['%s <%s>' % (self.user_employee.name, self.user_employee.email)]),
|
||||
'message_post: notification email wrong email_from: should use sender email')
|
||||
self.assertEqual(set(m['email_to'][0] for m in self._mails),
|
||||
set(['%s <%s>' % (self.partner_1.name, self.partner_1.email),
|
||||
'%s <%s>' % (self.env.user.name, self.env.user.email)]))
|
||||
|
||||
@@ -49,8 +49,8 @@ class TestMailMessage(TestMail):
|
||||
|
||||
msg = self.env['mail.message'].sudo(self.user_employee).create({})
|
||||
self.assertIn('-private', msg.message_id, 'mail_message: message_id for a void message should be a "private" one')
|
||||
self.assertEqual(msg.reply_to, '%s <%s@%s>' % (self.user_employee.name, self.user_employee.alias_name, alias_domain))
|
||||
self.assertEqual(msg.email_from, '%s <%s@%s>' % (self.user_employee.name, self.user_employee.alias_name, alias_domain))
|
||||
self.assertEqual(msg.reply_to, '%s <%s>' % (self.user_employee.name, self.user_employee.email))
|
||||
self.assertEqual(msg.email_from, '%s <%s>' % (self.user_employee.name, self.user_employee.email))
|
||||
|
||||
def test_mail_message_values_alias_catchall(self):
|
||||
alias_domain = 'example.com'
|
||||
@@ -61,7 +61,7 @@ class TestMailMessage(TestMail):
|
||||
msg = self.env['mail.message'].sudo(self.user_employee).create({})
|
||||
self.assertIn('-private', msg.message_id, 'mail_message: message_id for a void message should be a "private" one')
|
||||
self.assertEqual(msg.reply_to, '%s <%s@%s>' % (self.env.user.company_id.name, alias_catchall, alias_domain))
|
||||
self.assertEqual(msg.email_from, '%s <%s@%s>' % (self.user_employee.name, self.user_employee.alias_name, alias_domain))
|
||||
self.assertEqual(msg.email_from, '%s <%s>' % (self.user_employee.name, self.user_employee.email))
|
||||
|
||||
def test_mail_message_values_document_no_alias(self):
|
||||
self.env['ir.config_parameter'].search([('key', '=', 'mail.catchall.domain')]).unlink()
|
||||
@@ -85,7 +85,7 @@ class TestMailMessage(TestMail):
|
||||
})
|
||||
self.assertIn('-openerp-%d-mail.channel' % self.group_pigs.id, msg.message_id, 'mail_message: message_id for a void message should be a "private" one')
|
||||
self.assertEqual(msg.reply_to, '%s %s <%s@%s>' % (self.env.user.company_id.name, self.group_pigs.name, self.group_pigs.alias_name, alias_domain))
|
||||
self.assertEqual(msg.email_from, '%s <%s@%s>' % (self.user_employee.name, self.user_employee.alias_name, alias_domain))
|
||||
self.assertEqual(msg.email_from, '%s <%s>' % (self.user_employee.name, self.user_employee.email))
|
||||
|
||||
def test_mail_message_values_document_alias_catchall(self):
|
||||
alias_domain = 'example.com'
|
||||
@@ -99,7 +99,7 @@ class TestMailMessage(TestMail):
|
||||
})
|
||||
self.assertIn('-openerp-%d-mail.channel' % self.group_pigs.id, msg.message_id, 'mail_message: message_id for a void message should be a "private" one')
|
||||
self.assertEqual(msg.reply_to, '%s %s <%s@%s>' % (self.env.user.company_id.name, self.group_pigs.name, self.group_pigs.alias_name, alias_domain))
|
||||
self.assertEqual(msg.email_from, '%s <%s@%s>' % (self.user_employee.name, self.user_employee.alias_name, alias_domain))
|
||||
self.assertEqual(msg.email_from, '%s <%s>' % (self.user_employee.name, self.user_employee.email))
|
||||
|
||||
def test_mail_message_values_no_auto_thread(self):
|
||||
msg = self.env['mail.message'].sudo(self.user_employee).create({
|
||||
|
||||
@@ -27,17 +27,8 @@
|
||||
<field name="notify_email" widget="radio"/>
|
||||
</field>
|
||||
<field name="signature" position="before">
|
||||
<label for="alias_id" string="Messaging Alias" class="oe_read_only"
|
||||
attrs="{'invisible': [('alias_domain', '=', False)]}"/>
|
||||
<field name="alias_id" class="oe_read_only" required="0" nolabel="1"
|
||||
attrs="{'invisible': [('alias_domain', '=', False)]}"/>
|
||||
<label for="alias_name" string="Messaging Alias" class="oe_edit_only"
|
||||
attrs="{'invisible': [('alias_domain', '=', False)]}"/>
|
||||
<div class="oe_edit_only" attrs="{'invisible': [('alias_domain', '=', False)]}">
|
||||
<field name="alias_name" class="oe_inline"/>@<field name="alias_domain" class="oe_inline" readonly="1"/>
|
||||
</div>
|
||||
<field name="alias_contact" string="Alias Accepts Emails From"
|
||||
attrs="{'invisible': [('alias_domain', '=', False)]}"/>
|
||||
<field name="alias_id"/>
|
||||
<field name="alias_contact" attrs="{'invisible': [('alias_id', '=', False)]}"/>
|
||||
</field>
|
||||
</data>
|
||||
</field>
|
||||
|
||||
@@ -13,7 +13,6 @@ class TestPortalProjectBase(TestProjectBase):
|
||||
self.user_noone = self.env['res.users'].with_context({'no_reset_password': True, 'mail_create_nosubscribe': True}).create({
|
||||
'name': 'Noemie NoOne',
|
||||
'login': 'noemie',
|
||||
'alias_name': 'noemie',
|
||||
'email': 'n.n@example.com',
|
||||
'signature': '--\nNoemie',
|
||||
'notify_email': 'always',
|
||||
|
||||
@@ -18,14 +18,12 @@ class TestProjectBase(TestMail):
|
||||
cls.user_projectuser = Users.create({
|
||||
'name': 'Armande ProjectUser',
|
||||
'login': 'Armande',
|
||||
'alias_name': 'armande',
|
||||
'email': 'armande.projectuser@example.com',
|
||||
'groups_id': [(6, 0, [user_group_employee.id, user_group_project_user.id])]
|
||||
})
|
||||
cls.user_projectmanager = Users.create({
|
||||
'name': 'Bastien ProjectManager',
|
||||
'login': 'bastien',
|
||||
'alias_name': 'bastien',
|
||||
'email': 'bastien.projectmanager@example.com',
|
||||
'groups_id': [(6, 0, [user_group_employee.id, user_group_project_manager.id])]})
|
||||
|
||||
|
||||
@@ -13,7 +13,6 @@ class TestSale(AccountingTestCase):
|
||||
self.manager = self.env['res.users'].create({
|
||||
'name': 'Andrew Manager',
|
||||
'login': 'manager',
|
||||
'alias_name': 'andrew',
|
||||
'email': 'a.m@example.com',
|
||||
'signature': '--\nAndreww',
|
||||
'notify_email': 'always',
|
||||
@@ -22,7 +21,6 @@ class TestSale(AccountingTestCase):
|
||||
self.user = self.env['res.users'].create({
|
||||
'name': 'Mark User',
|
||||
'login': 'user',
|
||||
'alias_name': 'mark',
|
||||
'email': 'm.u@example.com',
|
||||
'signature': '--\nMark',
|
||||
'notify_email': 'always',
|
||||
|
||||
@@ -20,15 +20,15 @@ class TestSurvey(TransactionCase):
|
||||
User = self.env['res.users'].with_context({'no_reset_password': True})
|
||||
(group_survey_user, group_employee) = (self.ref('base.group_survey_user'), self.ref('base.group_user'))
|
||||
self.survey_manager = User.create({
|
||||
'name': 'Gustave Doré', 'login': 'Gustav', 'alias_name': 'gustav', 'email': 'gustav.dore@example.com',
|
||||
'name': 'Gustave Doré', 'login': 'Gustav','email': 'gustav.dore@example.com',
|
||||
'groups_id': [(6, 0, [self.ref('base.group_survey_manager'), group_survey_user, group_employee])]})
|
||||
|
||||
self.survey_user = User.create({
|
||||
'name': 'Lukas Peeters', 'login': 'Lukas', 'alias_name': 'lukas', 'email': 'lukas.petters@example.com',
|
||||
'name': 'Lukas Peeters', 'login': 'Lukas', 'email': 'lukas.petters@example.com',
|
||||
'groups_id': [(6, 0, [group_survey_user, group_employee])]})
|
||||
|
||||
self.user_public = User.create({
|
||||
'name': 'Wout Janssens', 'login': 'Wout', 'alias_name': 'wout', 'email': 'wout.janssens@example.com',
|
||||
'name': 'Wout Janssens', 'login': 'Wout', 'email': 'wout.janssens@example.com',
|
||||
'groups_id': [(6, 0, [self.ref('base.group_public')])]})
|
||||
|
||||
self.survey1 = self.env['survey.survey'].sudo(self.survey_manager).create({'title': "S0", 'page_ids': [(0, 0, {'title': "P0"})]})
|
||||
|
||||
@@ -17,7 +17,6 @@ class TestWebsiteBlogCommon(common.TransactionCase):
|
||||
self.user_employee = Users.with_context({'no_reset_password': True}).create({
|
||||
'name': 'Armande Employee',
|
||||
'login': 'armande',
|
||||
'alias_name': 'armande',
|
||||
'email': 'armande.employee@example.com',
|
||||
'notify_email': 'none',
|
||||
'groups_id': [(6, 0, [group_employee_id])]
|
||||
@@ -25,7 +24,6 @@ class TestWebsiteBlogCommon(common.TransactionCase):
|
||||
self.user_blogmanager = Users.with_context({'no_reset_password': True}).create({
|
||||
'name': 'Bastien BlogManager',
|
||||
'login': 'bastien',
|
||||
'alias_name': 'bastien',
|
||||
'email': 'bastien.blogmanager@example.com',
|
||||
'notify_email': 'none',
|
||||
'groups_id': [(6, 0, [group_blog_manager_id, group_employee_id])]
|
||||
@@ -33,7 +31,6 @@ class TestWebsiteBlogCommon(common.TransactionCase):
|
||||
self.user_public = Users.with_context({'no_reset_password': True}).create({
|
||||
'name': 'Cedric Public',
|
||||
'login': 'cedric',
|
||||
'alias_name': 'cedric',
|
||||
'email': 'cedric.public@example.com',
|
||||
'notify_email': 'none',
|
||||
'groups_id': [(6, 0, [group_public_id])]
|
||||
|
||||
@@ -35,7 +35,6 @@ class TestForumCommon(common.SavepointCase):
|
||||
cls.user_employee = TestUsersEnv.create({
|
||||
'name': 'Armande Employee',
|
||||
'login': 'Armande',
|
||||
'alias_name': 'armande',
|
||||
'email': 'armande.employee@example.com',
|
||||
'karma': 0,
|
||||
'groups_id': [(6, 0, [group_employee_id])]
|
||||
@@ -43,7 +42,6 @@ class TestForumCommon(common.SavepointCase):
|
||||
cls.user_portal = TestUsersEnv.create({
|
||||
'name': 'Beatrice Portal',
|
||||
'login': 'Beatrice',
|
||||
'alias_name': 'beatrice',
|
||||
'email': 'beatrice.employee@example.com',
|
||||
'karma': 0,
|
||||
'groups_id': [(6, 0, [group_portal_id])]
|
||||
@@ -51,7 +49,6 @@ class TestForumCommon(common.SavepointCase):
|
||||
cls.user_public = TestUsersEnv.create({
|
||||
'name': 'Cedric Public',
|
||||
'login': 'Cedric',
|
||||
'alias_name': 'cedric',
|
||||
'email': 'cedric.employee@example.com',
|
||||
'karma': 0,
|
||||
'groups_id': [(6, 0, [group_public_id])]
|
||||
|
||||
Reference in New Issue
Block a user