2012-02-22 11:59:24 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
##############################################################################
|
|
|
|
#
|
|
|
|
# OpenERP, Open Source Management Solution
|
|
|
|
# Copyright (C) 2009-Today OpenERP SA (<http://www.openerp.com>)
|
|
|
|
#
|
|
|
|
# This program is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU Affero General Public License as
|
|
|
|
# published by the Free Software Foundation, either version 3 of the
|
|
|
|
# License, or (at your option) any later version
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU Affero General Public License for more details
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU Affero General Public License
|
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>
|
|
|
|
#
|
|
|
|
##############################################################################
|
|
|
|
|
2012-03-26 13:38:52 +00:00
|
|
|
from osv import osv, fields
|
|
|
|
from tools.translate import _
|
2012-02-22 11:59:24 +00:00
|
|
|
|
|
|
|
class res_users(osv.osv):
|
2012-04-04 14:15:38 +00:00
|
|
|
""" Update of res.users class
|
2012-07-20 13:29:04 +00:00
|
|
|
- add a preference about sending emails about notifications
|
2012-04-04 14:15:38 +00:00
|
|
|
- make a new user follow itself
|
2012-07-20 13:29:04 +00:00
|
|
|
- add a welcome message
|
2012-04-04 14:15:38 +00:00
|
|
|
"""
|
2012-02-22 11:59:24 +00:00
|
|
|
_name = 'res.users'
|
|
|
|
_inherit = ['res.users', 'mail.thread']
|
|
|
|
|
2012-03-26 13:38:52 +00:00
|
|
|
_columns = {
|
2012-04-04 07:46:52 +00:00
|
|
|
'notification_email_pref': fields.selection([
|
2012-07-03 12:20:20 +00:00
|
|
|
('all', 'All feeds'),
|
|
|
|
('comments', 'Only comments'),
|
|
|
|
('to_me', 'Only when sent directly to me'),
|
|
|
|
('none', 'Never')
|
|
|
|
], 'Receive Feeds by Email', required=True,
|
|
|
|
help="Choose in which case you want to receive an email when you "\
|
|
|
|
"receive new feeds."),
|
2012-03-26 13:38:52 +00:00
|
|
|
}
|
|
|
|
|
2012-04-04 12:27:38 +00:00
|
|
|
_defaults = {
|
2012-05-03 13:49:16 +00:00
|
|
|
'notification_email_pref': 'to_me',
|
2012-03-26 13:38:52 +00:00
|
|
|
}
|
|
|
|
|
2012-04-06 07:40:18 +00:00
|
|
|
def __init__(self, pool, cr):
|
|
|
|
""" Override of __init__ to add access rights on notification_email_pref
|
|
|
|
field. Access rights are disabled by default, but allowed on
|
|
|
|
fields defined in self.SELF_WRITEABLE_FIELDS.
|
|
|
|
"""
|
|
|
|
init_res = super(res_users, self).__init__(pool, cr)
|
|
|
|
# duplicate list to avoid modifying the original reference
|
|
|
|
self.SELF_WRITEABLE_FIELDS = list(self.SELF_WRITEABLE_FIELDS)
|
|
|
|
self.SELF_WRITEABLE_FIELDS.append('notification_email_pref')
|
|
|
|
return init_res
|
|
|
|
|
2012-02-22 11:59:24 +00:00
|
|
|
def create(self, cr, uid, data, context=None):
|
|
|
|
user_id = super(res_users, self).create(cr, uid, data, context=context)
|
2012-03-29 10:11:13 +00:00
|
|
|
user = self.browse(cr, uid, [user_id], context=context)[0]
|
2012-02-22 11:59:24 +00:00
|
|
|
# make user follow itself
|
|
|
|
self.message_subscribe(cr, uid, [user_id], [user_id], context=context)
|
2012-07-20 13:29:04 +00:00
|
|
|
# create a welcome message
|
2012-03-29 10:11:13 +00:00
|
|
|
company_name = user.company_id.name if user.company_id else 'the company'
|
2012-07-20 13:29:04 +00:00
|
|
|
message = _('%s has joined %s! Welcome in OpenERP !') % (user.name, company_name)
|
|
|
|
self.message_append_note(cr, uid, [user_id], subject='Welcom to OpenERP', body=message, type='comment', context=context)
|
2012-02-22 11:59:24 +00:00
|
|
|
return user_id
|
|
|
|
|
2012-07-03 12:20:20 +00:00
|
|
|
def message_search_get_domain(self, cr, uid, ids, context=None):
|
|
|
|
""" Override of message_search_get_domain for partner discussion page.
|
|
|
|
The purpose is to add messages directly sent to user using
|
|
|
|
@user_login.
|
2012-04-05 21:04:12 +00:00
|
|
|
"""
|
2012-07-04 09:45:47 +00:00
|
|
|
initial_domain = super(res_users, self).message_search_get_domain(cr, uid, ids, context=context)
|
2012-07-03 12:20:20 +00:00
|
|
|
custom_domain = []
|
2012-04-05 21:04:12 +00:00
|
|
|
for user in self.browse(cr, uid, ids, context=context):
|
2012-07-03 12:20:20 +00:00
|
|
|
if custom_domain:
|
|
|
|
custom_domain += ['|']
|
|
|
|
custom_domain += ['|', ('body_text', 'like', '@%s' % (user.login)), ('body_html', 'like', '@%s' % (user.login))]
|
2012-07-04 09:45:47 +00:00
|
|
|
return ['|'] + initial_domain + custom_domain
|
2012-07-19 12:00:26 +00:00
|
|
|
|
|
|
|
class res_users_mail_group(osv.osv):
|
|
|
|
""" Update of res.groups class
|
|
|
|
- if adding/removing users from a group, check mail.groups linked to
|
|
|
|
this user group, and subscribe / unsubscribe them from the discussion
|
|
|
|
group. This is done by overriding the write method.
|
|
|
|
"""
|
|
|
|
_name = 'res.users'
|
|
|
|
_inherit = ['res.users', 'mail.thread']
|
|
|
|
|
|
|
|
def write(self, cr, uid, ids, vals, context=None):
|
|
|
|
write_res = super(res_users_mail_group, self).write(cr, uid, ids, vals, context=context)
|
|
|
|
if vals.get('groups_id'):
|
2012-07-19 12:34:39 +00:00
|
|
|
# form: {'group_ids': [(3, 10), (3, 3), (4, 10), (4, 3)]} or {'group_ids': [(6, 0, [ids]}
|
2012-07-19 12:00:26 +00:00
|
|
|
user_group_ids = [command[1] for command in vals['groups_id'] if command[0] == 4]
|
2012-07-19 12:34:39 +00:00
|
|
|
user_group_ids += [id for command in vals['groups_id'] if command[0] == 6 for id in command[2]]
|
2012-07-19 12:00:26 +00:00
|
|
|
mail_group_obj = self.pool.get('mail.group')
|
|
|
|
mail_group_ids = mail_group_obj.search(cr, uid, [('group_ids', 'in', user_group_ids)], context=context)
|
|
|
|
mail_group_obj.message_subscribe(cr, uid, mail_group_ids, ids, context=context)
|
|
|
|
return write_res
|
|
|
|
|
|
|
|
|
|
|
|
class res_groups_mail_group(osv.osv):
|
|
|
|
""" Update of res.groups class
|
|
|
|
- if adding/removing users from a group, check mail.groups linked to
|
|
|
|
this user group, and subscribe / unsubscribe them from the discussion
|
|
|
|
group. This is done by overriding the write method.
|
|
|
|
"""
|
|
|
|
_name = 'res.groups'
|
|
|
|
_inherit = 'res.groups'
|
|
|
|
|
|
|
|
def write(self, cr, uid, ids, vals, context=None):
|
|
|
|
if vals.get('users'):
|
2012-07-19 12:34:39 +00:00
|
|
|
# form: {'group_ids': [(3, 10), (3, 3), (4, 10), (4, 3)]} or {'group_ids': [(6, 0, [ids]}
|
|
|
|
user_ids = [command[1] for command in vals['users'] if command[0] == 4]
|
|
|
|
user_ids += [id for command in vals['users'] if command[0] == 6 for id in command[2]]
|
2012-07-19 12:00:26 +00:00
|
|
|
mail_group_obj = self.pool.get('mail.group')
|
|
|
|
mail_group_ids = mail_group_obj.search(cr, uid, [('group_ids', 'in', ids)], context=context)
|
|
|
|
mail_group_obj.message_subscribe(cr, uid, mail_group_ids, user_ids, context=context)
|
|
|
|
return super(res_groups_mail_group, self).write(cr, uid, ids, vals, context=context)
|