[MERGE] mail groups improvements

better form view
    security on groups: public, private, selected groups (for employees)
    menu automatically created/filtered
    action to open a specific group inline
    small fix in composition: new msg not linked to current user

bzr revid: fp@openerp.com-20120814112942-8wo9owa14hk5xqbj
This commit is contained in:
Fabien Pinckaers 2012-08-14 13:29:42 +02:00
commit ff9cbe0673
9 changed files with 131 additions and 107 deletions

View File

@ -30,6 +30,7 @@ import res_partner
import report
import wizard
import res_config
import mail_group_menu
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

View File

@ -2,49 +2,22 @@
<openerp>
<data noupdate="1">
<record id="message_blogpost0_attachment0" model="ir.attachment">
<field name="name">A cool attachment</field>
<field name="datas">PT1Tb21lIGNvb2wgYXR0YWNobWVudD09ClByYWVzZW50IHZlbCBtYXNzYSBzZWQgbWFzc2EgY29uc2VxdWF0IGVnZXN0YXMgaW4gdHJpc3RpcXVlIG9yY2ku</field>
<field name="datas_fname">a_cool_attachment</field>
<field name="description"></field>
<field name="res_name">Mail group</field>
<field name="res_model">mail.group</field>
<field name="res_id" ref="group_all_company"/>
<field name="type">binary</field>
</record>
<record id="message_blogpost0_attachment1" model="ir.attachment">
<field name="name">Another clean attachment</field>
<field name="datas">PT1Tb21lIGNsZWFuIGF0dGFjaG1lbnQ9PQpOdWxsYSB0dXJwaXMgbGVvLCByaG9uY3VzIHV0IGVnZXN0YXMgc2l0IGFtZXQsIGNvbnNlY3RldHVyIHZpdGFlIHVybmEu</field>
<field name="datas_fname">a_clean_attachment</field>
<field name="description"></field>
<field name="res_name">Mail group</field>
<field name="res_model">mail.group</field>
<field name="res_id" ref="group_all_company"/>
<field name="type">binary</field>
</record>
<record id="message_blogpost0" model="mail.message">
<field name="subject">Internal company announce</field>
<field name="model">mail.group</field>
<field name="res_id" ref="group_all_company"/>
<field name="res_id" ref="group_all_employees"/>
<field name="content_subtype">html</field>
<field name="body_html"><![CDATA[Lorem ipsum dolor <b>sit amet</b>, consectetur <em>adipiscing elit</em>. Pellentesque et quam sapien, in sagittis tellus.
Praesent vel massa sed massa consequat egestas in tristique orci. Praesent iaculis libero et neque vehicula iaculis. Vivamus placerat tincidunt orci ac ornare. Proin ut dolor fringilla velit ultricies consequat. Maecenas sit amet ipsum non leo interdum imperdiet. Donec sapien mi, varius a consequat id, consectetur sit amet nulla.
Fusce tempus elit volutpat mi auctor adipiscing. Nam congue luctus suscipit. Duis vestibulum dapibus enim vitae dignissim. Sed tellus libero, venenatis ut mollis ut, luctus quis dui. Sed rhoncus pulvinar orci in consectetur.
Nulla turpis leo, rhoncus ut egestas sit amet, consectetur vitae urna. Mauris in dolor in sapien tempus vehicula.]]></field>
<field name="body_html"><![CDATA[Your monthly meal vouchers arrived. You can get them at Christine's office.
This month you also have 250 EUR of eco-checks for all employees that worked with us since 1 year minimum.]]></field>
<field name="type">comment</field>
<field name="user_id" ref="base.user_root"/>
<field name="attachment_ids" eval="[(6,0,[ref('message_blogpost0_attachment0'),ref('message_blogpost0_attachment1')])]"/>
</record>
<record id="message_blogpost0_comment0" model="mail.message">
<field name="model">mail.group</field>
<field name="res_id" ref="group_all_company"/>
<field name="res_id" ref="group_all_employees"/>
<field name="content_subtype">html</field>
<field name="body_html"><![CDATA[That was such a <b>tremendous</b> blogpost ! (first comment)]]></field>
<field name="body_html"><![CDATA[Great.]]></field>
<field name="parent_id" ref="message_blogpost0"/>
<field name="type">comment</field>
<field name="user_id" ref="base.user_root"/>
@ -52,29 +25,17 @@ Nulla turpis leo, rhoncus ut egestas sit amet, consectetur vitae urna. Mauris in
<record id="message_blogpost0_comment1" model="mail.message">
<field name="model">mail.group</field>
<field name="res_id" ref="group_all_company"/>
<field name="res_id" ref="group_all_employees"/>
<field name="content_subtype">html</field>
<field name="body_html"><![CDATA[Agreed !
Would it be possible to learn more about the author ? (second comment)]]></field>
<field name="body_html"><![CDATA[Yes, that's a good news.]]></field>
<field name="parent_id" ref="message_blogpost0"/>
<field name="type">comment</field>
<field name="user_id" ref="base.user_demo"/>
</record>
<record id="message_blogpost0_comment2_attachment0" model="ir.attachment">
<field name="name">Author's full biography</field>
<field name="datas">PT1BYm91dCB0aGUgYXV0aG9yPT0KSW50ZWdlciBzb2RhbGVzIGRvbG9yIGV1IGVsaXQgZnJpbmdpbGxhIGJsYW5kaXQu</field>
<field name="datas_fname">blogpost_author_biography</field>
<field name="description"></field>
<field name="res_name">Mail group</field>
<field name="res_model">mail.group</field>
<field name="res_id" ref="group_all_company"/>
<field name="type">binary</field>
</record>
<record id="message_blogpost0_comment2" model="mail.message">
<field name="model">mail.group</field>
<field name="res_id" ref="group_all_company"/>
<field name="res_id" ref="group_all_employees"/>
<field name="content_subtype">html</field>
<field name="body_html"><![CDATA[Sure: Curabitur tempor bibendum diam, et euismod ante rutrum vel.
@ -85,7 +46,6 @@ Check the file in attachment for more information ! (third comment)]]></field>
<field name="parent_id" ref="message_blogpost0"/>
<field name="type">comment</field>
<field name="user_id" ref="base.user_root"/>
<field name="attachment_ids" eval="[(4,ref('message_blogpost0_comment2_attachment0'))]"/>
</record>
<record model="ir.config_parameter" id="user_mail_alias">

View File

@ -2,16 +2,14 @@
<openerp>
<data noupdate="1">
<record model="mail.group" id="group_all_company">
<field name="name">All Company</field>
<field name="description">All company users can come here and discuss.</field>
</record>
<record model="mail.group" id="group_sales">
<field name="name">Sales</field>
<field name="description">Discussion about best sales practices and deals.</field>
</record>
<record model="mail.group" id="group_all_employees">
<field name="name">All Employees</field>
<field name="group_ids" eval="[(4, ref('base.group_user'))]"/>
<field name="description">Discussion about best sales practices and deals.</field>
</record>
<!-- notify all employees of module installation -->

View File

@ -46,7 +46,7 @@ class mail_group(osv.osv):
_description = 'Discussion group'
_name = 'mail.group'
_inherit = ['mail.thread']
_inherits = {'mail.alias': 'alias_id'}
_inherits = {'mail.alias': 'alias_id', 'ir.ui.menu': 'menu_id'}
def _get_image(self, cr, uid, ids, name, args, context=None):
result = dict.fromkeys(ids, False)
@ -89,15 +89,18 @@ class mail_group(osv.osv):
return tools.image_resize_image_big(open(image_path, 'rb').read().encode('base64'))
_columns = {
'name': fields.char('Name', size=64, required=True),
#'name': fields.char('Group Name', size=64, required=True),
'description': fields.text('Description'),
'menu_id': fields.many2one('ir.ui.menu', string='Related Menu', required=True, ondelete="cascade"),
'responsible_id': fields.many2one('res.users', string='Responsible',
ondelete='set null', required=True, select=1,
help="Responsible of the group that has all rights on the record."),
'public': fields.boolean('Visible by non members', help='This group is visible by non members. \
'public': fields.selection([('public','Public'),('private','Private'),('groups','Selected Group Only')], 'Privacy', required=True,
help='This group is visible by non members. \
Invisible groups can add members through the invite button.'),
'group_public_id': fields.many2one('res.groups', string='Authorized Group'),
'group_ids': fields.many2many('res.groups', rel='mail_group_res_group_rel',
id1='mail_group_id', id2='groups_id', string='Linked groups',
id1='mail_group_id', id2='groups_id', string='Auto Subscription',
help="Members of those groups will automatically added as followers. "\
"Note that they will be able to manage their subscription manually "\
"if necessary."),
@ -131,15 +134,25 @@ class mail_group(osv.osv):
string='Joined', multi='get_member_ids'),
'last_month_msg_nbr': fields.function(get_last_month_msg_nbr, type='integer',
string='Messages count for last month'),
'alias_id': fields.many2one('mail.alias', 'Alias', ondelete="cascade", required=True,
'alias_id': fields.many2one('mail.alias', 'Alias', ondelete="cascade",
help="The email address associated with this group. New emails received will automatically "
"create new topics."),
}
def _get_default_employee_group(self, cr, uid, context=None):
ref = self.pool.get('ir.model.data').get_object_reference(cr, uid, 'base', 'group_user')
return ref and ref[1] or False
def _get_menu_parent(self, cr, uid, context=None):
ref = self.pool.get('ir.model.data').get_object_reference(cr, uid, 'mail', 'mail_group_root')
return ref and ref[1] or False
_defaults = {
'public': True,
'public': 'groups',
'group_public_id': _get_default_employee_group,
'responsible_id': (lambda s, cr, uid, ctx: uid),
'image': _get_default_image,
'parent_id': _get_menu_parent,
}
def _subscribe_user_with_group_m2m_command(self, cr, uid, ids, group_ids_command, context=None):
@ -162,9 +175,25 @@ class mail_group(osv.osv):
{'alias_name': "group_"+name},
model_name=self._name, context=context)
vals['alias_id'] = alias_id
mail_group_id = super(mail_group, self).create(cr, uid, vals, context)
# Create client action for this group and link the menu to it
ref = self.pool.get('ir.model.data').get_object_reference(cr, uid, 'mail', 'action_mail_group_feeds')
if ref:
search_ref = self.pool.get('ir.model.data').get_object_reference(cr, uid, 'mail', 'view_message_search_wall')
params = {
'search_view_id': search_ref and search_ref[1] or False,
'domain': [('model','=','mail.group'),('res_id','=',mail_group_id)],
'res_model': 'mail.group',
'res_id': mail_group_id,
'thread_level': 2
}
cobj = self.pool.get('ir.actions.client')
newref = cobj.copy(cr, uid, ref[1], default={'params': str(params), 'name': vals['name']}, context=context)
self.write(cr, uid, [mail_group_id], {'action': 'ir.actions.client,'+str(newref), 'mail_group_id': mail_group_id}, context=context)
alias_pool.write(cr, uid, [vals['alias_id']], {"alias_force_thread_id": mail_group_id}, context)
if vals.get('group_ids'):
self._subscribe_user_with_group_m2m_command(cr, uid, [mail_group_id], vals.get('group_ids'), context=context)

View File

@ -0,0 +1,44 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2010-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/>
#
##############################################################################
from osv import osv
from osv import fields
from tools.translate import _
class ir_ui_menu(osv.osv):
_inherit = 'ir.ui.menu'
_columns = {
'mail_group_id': fields.many2one('mail.group', 'Mail Group')
}
def search(self, cr, uid, args, offset=0, limit=None, order=None, context=None, count=False):
ids = super(ir_ui_menu, self).search(cr, uid, args, offset=0, limit=None, order=order, context=context, count=False)
subs = self.pool.get('mail.subscription')
for menu in self.browse(cr, uid, ids, context=context):
if menu.mail_group_id:
sub_ids = subs.search(cr, uid, [
('user_id','=',uid),('res_model','=','mail.group'),
('res_id','=',menu.mail_group_id.id)
], context=context)
if not sub_ids:
ids.remove(menu.id)
return ids

View File

@ -1,6 +1,11 @@
<?xml version="1.0"?>
<openerp>
<data>
<record id="action_mail_group_feeds" model="ir.actions.client">
<field name="name">Discussion Group</field>
<field name="tag">mail.wall</field>
<field name="params" eval="{'search_view_id': ref('view_message_search_wall')}"/>
</record>
<!-- Group Kanban View !-->
<record model="ir.ui.view" id="view_group_kanban">
@ -51,35 +56,29 @@
<field name="arch" type="xml">
<form string="Group Form" version="7.0">
<sheet class="openerp_mail_group_sheet">
<group colspan="4" col="8">
<group colspan="1" col="2">
<field name="image_small" widget='image' class="oe_image_small" nolabel="1"/>
<field name="image_small" widget='image' class="oe_avatar oe_left"/>
<div class="oe_title">
<div class="oe_edit_only">
<label for="name" string="Group Name"/>
</div>
<h1><field name="name"/></h1>
<field name="description" placeholder="Topics discussed in this group..."/>
</div>
<div class="oe_clear"/>
<group col="1">
<group class="oe_edit_only">
<field name="public" class="oe_inline"/>
<field name="group_public_id" class="oe_inline"
attrs="{'invisible': [('public','&lt;&gt;','groups')], 'required': [('public','=','groups')]}"
/>
<field name="group_ids" widget="many2many_tags" class="oe_inline"/>
</group>
<group colspan="7" col="6">
<div class="oe_edit_only">
<label for="name"/>
</div>
<div>
<h2><field name="name" colspan="4"/></h2>
<div name="alias_box" colspan="4" attrs="{'invisible': [('alias_domain', '=', False)]}" class="oe_edit_only">
<field name="alias_id" invisible="1"/>
<label for="alias_name" class="oe_edit_only"/>
<field name="alias_name" nolabel="1" class="oe_inline" attrs="{'required': [('alias_id', '!=', False)]}"/>@<field name="alias_domain" nolabel="1" class="oe_inline"/>
</div>
</div>
<newline/>
<group colspan="4" col="4">
<field name="description" colspan="4" nolabel="1"/>
<field name="group_ids" colspan="4" widget="many2many_tags" class="oe_edit_only"/>
</group>
<group colspan="2" col="2" class="oe_edit_only">
<field name="responsible_id" colspan="2"/>
<field name="public" colspan="2"/>
</group>
<group class="oe_edit_only">
<field name="responsible_id" class="oe_inline"/>
</group>
</group>
</sheet>
<div class="oe_chatter oe_mail_group_footer">
<div class="oe_chatter">
<field name="message_ids" widget="mail_thread"
options='{"thread_level": 1}'/>
</div>
@ -95,7 +94,7 @@
<field name="priority" eval="10"/>
<field name="arch" type="xml">
<tree string="Groups">
<field name="name"/>
<field name="name" string="Group Name"/>
<field name="responsible_id"/>
</tree>
</field>
@ -125,6 +124,7 @@
</record>
<!-- left-side menu: Groups !-->
<menuitem id="mail_allgroups" name="All Groups" parent="mail_feeds" sequence="12" action="action_view_groups"/>
<menuitem id="mail_group_root" parent="mail_feeds_main" sequence="12" name="My Groups"/>
<menuitem id="mail_allgroups" parent="mail_feeds" sequence="12" action="action_view_groups"/>
</data>
</openerp>

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data noupdate="1">
<data>
<!-- CATEGORY -->
<record model="ir.module.category" id="module_category_social">
@ -20,23 +20,8 @@
<record id="group_rule_public_and_joined" model="ir.rule">
<field name="name">Mail.group: access only public and joined groups</field>
<field name="model_id" ref="model_mail_group"/>
<field name="domain_force">['|', ('public', '=', True), ('member_ids', 'in', user.id)]</field>
<field name="perm_create" eval="False"/>
<field name="perm_unlink" eval="False"/>
</record>
<record id="group_rule_delete_mygroup" model="ir.rule">
<field name="name">Mail.group: delete my groups only</field>
<field name="model_id" ref="model_mail_group"/>
<field name="domain_force">[('responsible_id', '=', user.id)]</field>
<field name="perm_read" eval="False"/>
<field name="perm_write" eval="False"/>
<field name="perm_create" eval="False"/>
</record>
<record id="group_rule_all" model="ir.rule">
<field name="name">Mail.group: all groups</field>
<field name="model_id" ref="model_mail_group"/>
<field name="domain_force">[(1,'=',1)]</field>
<field name="groups" eval="[(4, ref('group_mail_manager'))]"/>
<!-- This rule has to be improved for employee only groups -->
<field name="domain_force">['|', '|', ('public', '=', 'public'), ('member_ids', 'in', [user.id]), '&amp;', ('public','=','groups'), ('group_public_id','in', [x.id for x in user.groups_id])]</field>
</record>
</data>

View File

@ -972,8 +972,11 @@ openerp.mail = function(session) {
this.params.limit = params.limit || 25;
this.params.domain = params.domain || [];
this.params.context = params.context || {};
this.params.res_model = params.res_model || false;
this.params.res_id = params.res_id || false;
this.params.search_view_id = params.search_view_id || false;
this.params.thread_level = params.thread_level || 1;
this.params.title = params.title || false;
this.comments_structure = {'root_ids': [], 'new_root_ids': [], 'msgs': {}, 'tree_struct': {}, 'model_to_root_ids': {}};
this.display_show_more = true;
this.thread_list = [];
@ -1018,9 +1021,10 @@ openerp.mail = function(session) {
if (this.compose_message_widget) {
this.compose_message_widget.destroy();
}
debugger;
this.compose_message_widget = new mail.ComposeMessage(this, {
'extended_mode': false, 'uid': this.session.uid, 'res_model': 'res.users',
'res_id': this.session.uid, 'mode': mode || 'comment', 'msg_id': msg_id });
'extended_mode': false, 'uid': this.session.uid, 'res_model': this.params.res_model,
'res_id': this.params.res_id, 'mode': mode || 'comment', 'msg_id': msg_id });
var composition_node = this.$element.find('div.oe_mail_wall_action');
composition_node.empty();
var compose_done = this.compose_message_widget.appendTo(composition_node);

View File

@ -16,7 +16,10 @@
<tr class="oe_header_row oe_header_row_top">
<td colspan="2">
<h2 class="oe_view_title">
<span class="oe_view_title_text">All Feeds</span>
<span class="oe_view_title_text">
<t t-if="! widget.params.res_model">News Feeds</t>
<t t-if="widget.params.res_model" t-esc="widget.params.res_model"/>
</span>
</h2>
</td>
<td><div class="oe_view_manager_view_search" t-opentag="true"/></td>