[MERGE] Merged OpenChatter part 1/2. This revision adds a social messaging system inside OpenERP, that will be used by addons to display notifications (such as status changes), user comments, and emails. All message types are managed in a unified system. Social aspects are also enforced, by an easy invite system based on share, and a subscription mechanism allowing to follow messages post on records users want to follow. res.logs are removed from OpenERP and replaced by OpenChatter.

This revision adds the server-side of OpenChatter part 1/22, that is mainly composed of res.log removal as the need_action mechanism and user avatar feature, developed during OpenChatter, have already be merged.

bzr revid: tde@openerp.com-20120406115731-fm6duz1drtme3k7k
This commit is contained in:
Thibault Delavallée 2012-04-06 13:57:31 +02:00
commit 776c0cd2c4
13 changed files with 43 additions and 207 deletions

View File

@ -58,7 +58,6 @@
'module/wizard/base_update_translations_view.xml',
'res/res_request_view.xml',
'res/res_lang_view.xml',
'res/res_log_view.xml',
'res/res_partner_report.xml',
'res/res_partner_view.xml',
'res/res_partner_shortcut_data.xml',

View File

@ -85,7 +85,7 @@
<field name="name" readonly="1"/>
<newline/>
<group colspan="2" col="3">
<group col="2" colspan="2">
<group col="2" colspan="2" name="preferences">
<separator string="Preferences" colspan="2"/>
<field name="view" readonly="0"/>
<field name="context_lang" readonly="0"/>
@ -94,7 +94,7 @@
</group>
<group col="2" colspan="1">
<separator string="Avatar" colspan="2"/>
<field name="avatar" widget='image' nolabel="1" colspan="2" on_change="onchange_avatar(avatar)"/>
<field name="avatar" widget='image' nolabel="1" colspan="2" on_change="onchange_avatar(avatar)" readonly="0"/>
</group>
</group>
<group name="default_filters" colspan="2" col="2">
@ -128,11 +128,11 @@
<!-- Second nested group to avoid misalignment with email prefs groups
in simplified view -->
<group colspan="7" col="7">
<group col="2" colspan="1">
<group col="2" colspan="1" name="avatar">
<separator string="Avatar" colspan="2"/>
<field name="avatar" widget='image' nolabel="1" colspan="2" on_change="onchange_avatar(avatar)"/>
</group>
<group col="3" colspan="2">
<group col="3" colspan="2" name="preferences">
<separator string="Preferences" colspan="3"/>
<field name="context_lang"/>
<field name="context_tz"/>

View File

@ -683,7 +683,7 @@
<field name="view_mode">tree,form</field>
</record>
<menuitem id="menu_needaction_users" name="Need actions" parent="base.menu_users" sequence="20" action="action_view_needaction_users" groups="base.group_extended"/>
<menuitem id="menu_needaction_users" name="Need actions" parent="base.menu_users" sequence="20" action="action_view_needaction_users" groups="base.group_no_one"/>
<!-- Companies -->
<menuitem id="menu_res_company_global"
@ -2071,8 +2071,8 @@
<field name="search_view_id" ref="view_ir_mail_server_search"/>
</record>
<menuitem id="menu_email" name="Email" parent="base.menu_config" sequence="22" groups="base.group_extended"/>
<menuitem id="menu_mail_servers" parent="menu_email" action="action_ir_mail_server_list" sequence="15"/>
<menuitem id="menu_email" name="Email" parent="base.menu_config" sequence="22"/>
<menuitem id="menu_mail_servers" parent="menu_email" action="action_ir_mail_server_list" sequence="15" groups="base.group_no_one"/>
</data>
</openerp>

View File

@ -717,8 +717,8 @@ class ir_model_data(osv.osv):
model_obj = self.pool.get(model)
if not context:
context = {}
# records created during module install should result in res.log entries that are already read!
context = dict(context, res_log_read=True)
# records created during module install should not display the messages of OpenChatter
context = dict(context, install_mode=True)
if xml_id and ('.' in xml_id):
assert len(xml_id.split('.'))==2, _("'%s' contains too many dots. XML ids should not contain dots ! These are used to refer to other modules data, as in module.reference_id") % (xml_id)
module, xml_id = xml_id.split('.')

View File

@ -263,11 +263,14 @@ class ir_ui_menu(osv.osv):
res[menu.id] = {}
if menu.action and menu.action.type == 'ir.actions.act_window' and menu.action.res_model:
menu_needaction_res = self.pool.get(menu.action.res_model).get_needaction_info(cr, uid, uid, domain=menu.action.domain, context=context)
# TODO: find the addon that causes a bug on runbot, not on local
if not isinstance(menu_needaction_res[1], (int, long)): menu_needaction_res[1] = 0
else:
menu_needaction_res = [False, 0, ()]
res[menu.id]['needaction_enabled'] = menu_needaction_res[0]
res[menu.id]['needaction_counter'] = menu_needaction_res[1]
res[menu.id]['needaction_record_ids'] = menu_needaction_res[2]
# not used currently, therefore set to a void list
res[menu.id]['needaction_record_ids'] = []
return res
_columns = {

View File

@ -187,21 +187,21 @@ class publisher_warranty_contract(osv.osv):
limit_date = (datetime.datetime.now() - _PREVIOUS_LOG_CHECK).strftime(misc.DEFAULT_SERVER_DATETIME_FORMAT)
for message in result["messages"]:
ids = self.pool.get("res.log").search(cr, uid, [("res_model", "=", "publisher_warranty.contract"),
("create_date", ">=", limit_date),
("name", "=", message)])
if ids:
continue
self.pool.get('res.log').create(cr, uid,
{
'name': message,
'res_model': "publisher_warranty.contract",
"read": True,
"user_id": False,
},
context=context
)
# old behavior based on res.log; now on mail.message, that is not necessarily installed
mail_message_obj = self.pool.get('mail.message')
if mail_message_obj:
for message in result["messages"]:
ids = mail_message_obj.search(cr, uid, [("model", "=", "publisher_warranty.contract"),
("create_date", ">=", limit_date),
("body_text", "=", message)])
if ids:
continue
mail_message_obj.create(cr, uid, {
'name': message,
'model': "publisher_warranty.contract",
'user_id': False,
}, context=context)
except Exception:
if cron_mode:
return False # we don't want to see any stack trace in cron
@ -215,22 +215,15 @@ class publisher_warranty_contract(osv.osv):
@return: A list of html messages with ids, can be False or empty.
@rtype: list of tuples(int,string)
"""
ids = self.pool.get('res.log').search(cr, uid, [("res_model", "=", "publisher_warranty.contract")]
, order="create_date desc", limit=limit)
if not self.pool.get('mail.message'):
return []
ids = self.pool.get('mail.message').search(cr, uid, [("model", "=", "publisher_warranty.contract")]
, order="create_date desc", limit=limit, context=context)
if not ids:
return []
messages = [(x.id, x.name) for x in self.pool.get('res.log').browse(cr, uid, ids)]
messages = [(x.id, x.name) for x in self.pool.get('mail.message').browse(cr, uid, ids, context=context)]
return messages
def del_user_message(self, cr, uid, id, context=None):
"""
Delete a message.
"""
self.pool.get('res.log').unlink(cr, uid, [id])
return True
_columns = {
'name' : fields.char('Serial Key', size=384, required=True, help="Your OpenERP Publisher's Warranty Contract unique key, also called serial number."),
'date_start' : fields.date('Starting Date', readonly=True),

View File

@ -32,7 +32,6 @@ import res_company
import res_users
import res_request
import res_lang
import res_log
import res_widget
import ir_property

View File

@ -1,80 +0,0 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>).
#
# 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/>.
#
##############################################################################
from osv import fields, osv
class res_log(osv.osv):
_name = 'res.log'
_columns = {
'name': fields.char('Message', size=250, help='The logging message.', required=True, select=1),
'user_id': fields.many2one('res.users','User'),
'res_model': fields.char('Object', size=128, select=1),
'context': fields.char('Context', size=250),
'res_id': fields.integer('Object ID'),
'secondary': fields.boolean('Secondary Log', help='Do not display this log if it belongs to the same object the user is working on'),
'create_date': fields.datetime('Creation Date', readonly=True, select=1),
'read': fields.boolean('Read', help="If this log item has been read, get() should not send it to the client"),
}
_defaults = {
'user_id': lambda self,cr,uid,ctx: uid,
'context': "{}",
'read': False,
}
_order='create_date desc'
_index_name = 'res_log_uid_read'
def _auto_init(self, cr, context=None):
super(res_log, self)._auto_init(cr, context)
cr.execute('SELECT 1 FROM pg_indexes WHERE indexname=%s',
(self._index_name,))
if not cr.fetchone():
cr.execute('CREATE INDEX %s ON res_log (user_id, read)' %
self._index_name)
def create(self, cr, uid, vals, context=None):
create_context = context and dict(context) or {}
if 'res_log_read' in create_context:
vals['read'] = create_context.pop('res_log_read')
if create_context and not vals.get('context'):
vals['context'] = create_context
return super(res_log, self).create(cr, uid, vals, context=context)
# TODO: do not return secondary log if same object than in the model (but unlink it)
def get(self, cr, uid, context=None):
unread_log_ids = self.search(cr, uid,
[('user_id','=',uid), ('read', '=', False)], context=context)
res = self.read(cr, uid, unread_log_ids,
['name','res_model','res_id','context'],
context=context)
res.reverse()
result = []
res_dict = {}
for r in res:
t = (r['res_model'], r['res_id'])
if t not in res_dict:
res_dict[t] = True
result.insert(0,r)
self.write(cr, uid, unread_log_ids, {'read': True}, context=context)
return result
res_log()
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

View File

@ -1,65 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<record id="res_log_search" model="ir.ui.view">
<field name="name">res.log.search</field>
<field name="model">res.log</field>
<field name="type">search</field>
<field name="arch" type="xml">
<search string="Logs">
<filter icon="terp-camera_test" string="Read" domain="[('read','=',True)]" name="read"/>
<filter icon="terp-gtk-jump-to-ltr" string="Unread" domain="[('read','&lt;&gt;',True)]" name="unread"/>
<separator orientation="vertical"/>
<filter icon="terp-personal" string="My Logs" domain="[('user_id','=',uid)]" name="my"/>
<filter icon="terp-stock_align_left_24" string="System Logs"
domain="[('res_model','=','publisher_warranty.contract')]" name="sys"/>
<separator orientation="vertical"/>
<field name="name"/>
<field name="user_id"/>
<field name="res_model"/>
<field name="create_date"/>
</search>
</field>
</record>
<record id="res_log_tree" model="ir.ui.view">
<field name="name">res.log.tree</field>
<field name="model">res.log</field>
<field name="type">tree</field>
<field name="arch" type="xml">
<tree string="Logs">
<field name="create_date"/>
<field name="user_id"/>
<field name="name"/>
</tree>
</field>
</record>
<record id="res_log_form" model="ir.ui.view">
<field name="name">res.log.form</field>
<field name="model">res.log</field>
<field name="type">form</field>
<field name="arch" type="xml">
<form string="Logs">
<group colspan="4" col="6">
<field name="name"/>
<field name="create_date"/>
<field name="read"/>
<field name="user_id" />
<field name="res_model"/>
<field name="res_id"/>
</group>
</form>
</field>
</record>
<record id="res_log_act_window" model="ir.actions.act_window">
<field name="name">Client Logs</field>
<field name="res_model">res.log</field>
<field name="view_type">form</field>
<field name="context">{'search_default_my': 1}</field>
</record>
<menuitem
action="res_log_act_window"
id="menu_res_log_act_window"
parent="base.menu_audit"/>
</data>
</openerp>

View File

@ -40,7 +40,6 @@ from service import security
import tools
from tools.translate import _
_logger = logging.getLogger(__name__)
class groups(osv.osv):
@ -205,7 +204,7 @@ class users(osv.osv):
img_stream = StringIO.StringIO()
img.save(img_stream, "PNG")
return img_stream.getvalue().encode('base64')
def _get_avatar(self, cr, uid, ids, name, args, context=None):
result = dict.fromkeys(ids, False)
for user in self.browse(cr, uid, ids, context=context):
@ -376,7 +375,7 @@ class users(osv.osv):
}
# User can write to a few of her own fields (but not her groups for example)
SELF_WRITEABLE_FIELDS = ['menu_tips','view', 'password', 'signature', 'action_id', 'company_id', 'user_email', 'name']
SELF_WRITEABLE_FIELDS = ['menu_tips','view', 'password', 'signature', 'action_id', 'company_id', 'user_email', 'name', 'avatar', 'avatar_big']
def write(self, cr, uid, ids, values, context=None):
if not hasattr(ids, '__iter__'):

View File

@ -117,9 +117,10 @@
"access_ir_filters","ir_filters_all","model_ir_filters",,1,1,1,1
"access_res_widget","res.widget","model_res_widget","group_erp_manager",1,1,1,1
"access_res_widget_user","res.widget.user","model_res_widget",,1,0,0,0
"access_res_log_all","res.log","model_res_log",,1,1,1,1
"access_ir_config_parameter","ir_config_parameter","model_ir_config_parameter",,1,0,0,0
"access_ir_mail_server_all","ir_mail_server","model_ir_mail_server",,1,0,0,0
"access_ir_actions_todo_category","ir_actions_todo_category","model_ir_actions_todo_category","group_system",1,1,1,1
"access_ir_actions_client","ir_actions_client all","model_ir_actions_client",,1,0,0,0
"access_ir_needaction_users","ir_needaction_users","model_ir_needaction_users",,1,1,1,1
"access_ir_needaction_mixin","ir_needaction_mixin","model_ir_needaction_mixin",,1,1,1,1

1 id name model_id:id group_id:id perm_read perm_write perm_create perm_unlink
117 access_ir_filters ir_filters_all model_ir_filters 1 1 1 1
118 access_res_widget res.widget model_res_widget group_erp_manager 1 1 1 1
119 access_res_widget_user res.widget.user model_res_widget 1 0 0 0
access_res_log_all res.log model_res_log 1 1 1 1
120 access_ir_config_parameter ir_config_parameter model_ir_config_parameter 1 0 0 0
121 access_ir_mail_server_all ir_mail_server model_ir_mail_server 1 0 0 0
122 access_ir_actions_todo_category ir_actions_todo_category model_ir_actions_todo_category group_system 1 1 1 1
123 access_ir_actions_client ir_actions_client all model_ir_actions_client 1 0 0 0
124 access_ir_needaction_users ir_needaction_users model_ir_needaction_users 1 1 1 1
125 access_ir_needaction_mixin ir_needaction_mixin model_ir_needaction_mixin 1 1 1 1
126

View File

@ -212,10 +212,7 @@ def load_module_graph(cr, graph, status=None, perform_checks=True, skip_modules=
delattr(package, kind)
cr.commit()
# mark new res_log records as read
cr.execute("update res_log set read=True where create_date >= %s", (dt_before_load,))
cr.commit()
return loaded_modules, processed_modules

View File

@ -709,17 +709,7 @@ class BaseModel(object):
CONCURRENCY_CHECK_FIELD = '__last_update'
def log(self, cr, uid, id, message, secondary=False, context=None):
if context and context.get('disable_log'):
return True
return self.pool.get('res.log').create(cr, uid,
{
'name': message,
'res_model': self._name,
'secondary': secondary,
'res_id': id,
},
context=context
)
return _logger.warning("log() is deprecated. Please use OpenChatter notification system instead of the res.log mechanism.")
def view_init(self, cr, uid, fields_list, context=None):
"""Override this method to do specific things when a view on the object is opened."""
@ -4895,14 +4885,14 @@ class BaseModel(object):
if hasattr(self, 'needaction_get_record_ids'):
ids = self.needaction_get_record_ids(cr, uid, user_id, limit=8192, context=context)
if not ids:
return (True, 0, [])
return [True, 0, []]
if domain:
new_domain = eval(domain) + [('id', 'in', ids)]
new_domain = eval(domain, locals_dict={'uid': user_id}) + [('id', 'in', ids)]
else:
new_domain = [('id', 'in', ids)]
return (True, self.search(cr, uid, new_domain, limit=limit, order=order, count=True, context=context), ids)
return [True, self.search(cr, uid, new_domain, limit=limit, order=order, count=True, context=context), ids]
else:
return (False, 0, [])
return [False, 0, []]
# Transience
def is_transient(self):