From 15e686e1b071ed55792d97a8580581955a333371 Mon Sep 17 00:00:00 2001 From: Olivier Dony Date: Tue, 22 Feb 2011 18:21:47 +0100 Subject: [PATCH 01/68] [FIX] share(web): action_id should be passed as an integer bzr revid: odo@openerp.com-20110222172147-wirqzv14fta1af2q --- addons/share/web/controllers.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/addons/share/web/controllers.py b/addons/share/web/controllers.py index bac7a607cf0..4b723f225da 100644 --- a/addons/share/web/controllers.py +++ b/addons/share/web/controllers.py @@ -17,7 +17,7 @@ class ShareWizardController(openerp.controllers.SecuredController): if not action_id: # This should not be needed anymore, but just in case users are - # running the module with an order version of the web client... + # running the module with an older version of the web client... # to remove soon-ish action_id = rpc.RPCProxy('ir.actions.act_window').search( @@ -44,7 +44,7 @@ class ShareWizardController(openerp.controllers.SecuredController): Share = rpc.RPCProxy('share.wizard') sharing_view_id = Share.create({ 'domain': str(domain), - 'action_id':action_id + 'action_id': action_id and int(action_id) }, context) return openerp.controllers.actions.execute( Share.go_step_1([sharing_view_id], context), From 8877996161a36d8fc9179ad1e518d9f91ece965f Mon Sep 17 00:00:00 2001 From: Raphael Collet Date: Tue, 22 Mar 2011 15:38:25 +0100 Subject: [PATCH 02/68] first sketch of module portal bzr revid: rco@openerp.com-20110322143825-swyxasmu0apui9k5 --- addons/portal/__init__.py | 23 +++++++++++++++++ addons/portal/__openerp__.py | 49 ++++++++++++++++++++++++++++++++++++ addons/portal/portal.py | 31 +++++++++++++++++++++++ 3 files changed, 103 insertions(+) create mode 100644 addons/portal/__init__.py create mode 100644 addons/portal/__openerp__.py create mode 100644 addons/portal/portal.py diff --git a/addons/portal/__init__.py b/addons/portal/__init__.py new file mode 100644 index 00000000000..0d6d510dbe6 --- /dev/null +++ b/addons/portal/__init__.py @@ -0,0 +1,23 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# Copyright (C) 2004-2011 Tiny SPRL (). +# +# 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 . +# +############################################################################## + +import portal + diff --git a/addons/portal/__openerp__.py b/addons/portal/__openerp__.py new file mode 100644 index 00000000000..351fd5c5ae9 --- /dev/null +++ b/addons/portal/__openerp__.py @@ -0,0 +1,49 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# Copyright (C) 2004-2011 Tiny SPRL (). +# +# 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 . +# +############################################################################## + + +{ + "name" : "Portal", + "version" : "0.1", + "depends" : ["base"], + "author" : "OpenERP SA", + "category": 'Tools', + "description": """ +This module defines 'portals' to customize the access to your OpenERP database. + +A portal defines customized user menu and access rights for a group of users +(the ones associated to that portal). Portals are convenient to provide a +specific access to your OpenERP instance for external users. + +It also associates user groups to the portal users (adding a group in the +portal automatically adds it to the portal users, etc). That feature is very +handy when used in combination with the module 'share'. + """, + 'website': 'http://www.openerp.com', + 'demo_xml': [], + 'data': [], + 'installable': True, + 'web': True, + 'certificate' : '', + 'images': [], +} + +# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/addons/portal/portal.py b/addons/portal/portal.py new file mode 100644 index 00000000000..b7f4e660e5c --- /dev/null +++ b/addons/portal/portal.py @@ -0,0 +1,31 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# Copyright (C) 2004-2011 Tiny SPRL (). +# +# 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 . +# +############################################################################## + +from osv import osv, fields +from tools.translate import _ + +class portal(osv.osv): + _name = 'res.portal' + _description = _('Portal') + _columns = { + 'name': fields.char(_('Name'), size=64, required=True), + } + From 8c32a45d291f3ff762f64215fe0c492219f2caed Mon Sep 17 00:00:00 2001 From: Raphael Collet Date: Wed, 23 Mar 2011 09:16:41 +0100 Subject: [PATCH 03/68] define relations between portals, users and groups bzr revid: rco@openerp.com-20110323081641-se0ipthrjwt1ejeh --- addons/portal/portal.py | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/addons/portal/portal.py b/addons/portal/portal.py index b7f4e660e5c..ebba75c0ff9 100644 --- a/addons/portal/portal.py +++ b/addons/portal/portal.py @@ -20,12 +20,27 @@ ############################################################################## from osv import osv, fields -from tools.translate import _ class portal(osv.osv): _name = 'res.portal' - _description = _('Portal') + _description = 'Portal' _columns = { - 'name': fields.char(_('Name'), size=64, required=True), + 'name': fields.char(string='Name', size=64, required=True), + 'user_ids': fields.one2many('res.users', 'portal_id', string='Portal users', + help='Gives the set of users associated to this portal'), + 'group_ids': field.many2many('res.groups', 'portal_group', 'portal_id', 'group_id', + string='Groups', help='Users of this portal automatically belong to those groups'), } +portal() + +class users(osv.osv): + _name = 'res.users' + _inherit = 'res.users' + _columns = { + 'portal_id': fields.many2one('res.portal', string='Portal', + help='If given, the portal defines customized menu and access rules'), + } + +users() + From 013d6896e883845aebf03ea5830b518c918f8b1a Mon Sep 17 00:00:00 2001 From: Raphael Collet Date: Wed, 23 Mar 2011 13:56:01 +0100 Subject: [PATCH 04/68] fix typo bzr revid: rco@openerp.com-20110323125601-qsyfjys82t4eqdhw --- addons/portal/portal.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/portal/portal.py b/addons/portal/portal.py index ebba75c0ff9..a96a3d94641 100644 --- a/addons/portal/portal.py +++ b/addons/portal/portal.py @@ -28,7 +28,7 @@ class portal(osv.osv): 'name': fields.char(string='Name', size=64, required=True), 'user_ids': fields.one2many('res.users', 'portal_id', string='Portal users', help='Gives the set of users associated to this portal'), - 'group_ids': field.many2many('res.groups', 'portal_group', 'portal_id', 'group_id', + 'group_ids': fields.many2many('res.groups', 'portal_group', 'portal_id', 'group_id', string='Groups', help='Users of this portal automatically belong to those groups'), } From 9ae71a441637b0dd0858fc2316a8eb1bd70908dc Mon Sep 17 00:00:00 2001 From: Raphael Collet Date: Wed, 23 Mar 2011 13:56:25 +0100 Subject: [PATCH 05/68] add portal form view bzr revid: rco@openerp.com-20110323125625-rmtw8aa1yizbo3eh --- addons/portal/__openerp__.py | 15 +++++++-------- addons/portal/portal_view.xml | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 8 deletions(-) create mode 100644 addons/portal/portal_view.xml diff --git a/addons/portal/__openerp__.py b/addons/portal/__openerp__.py index 351fd5c5ae9..58b383b5092 100644 --- a/addons/portal/__openerp__.py +++ b/addons/portal/__openerp__.py @@ -27,19 +27,18 @@ "author" : "OpenERP SA", "category": 'Tools', "description": """ -This module defines 'portals' to customize the access to your OpenERP database. +This module defines 'portals' to customize the access to your OpenERP database +for external users. A portal defines customized user menu and access rights for a group of users -(the ones associated to that portal). Portals are convenient to provide a -specific access to your OpenERP instance for external users. - -It also associates user groups to the portal users (adding a group in the -portal automatically adds it to the portal users, etc). That feature is very -handy when used in combination with the module 'share'. +(the ones associated to that portal). It also associates user groups to the +portal users (adding a group in the portal automatically adds it to the portal +users, etc). That feature is very handy when used in combination with the +module 'share'. """, 'website': 'http://www.openerp.com', 'demo_xml': [], - 'data': [], + 'data': ['portal_view.xml'], 'installable': True, 'web': True, 'certificate' : '', diff --git a/addons/portal/portal_view.xml b/addons/portal/portal_view.xml new file mode 100644 index 00000000000..c58f7bc2c5f --- /dev/null +++ b/addons/portal/portal_view.xml @@ -0,0 +1,34 @@ + + + + + + + + + Portals + res.portal + form + tree,form + + + + + + Portal Form + res.portal + form + + +
+ + + + + + + +
+
+
From e531a2b4423ff34e9a0a9b4d1b045f89f0cf5ebc Mon Sep 17 00:00:00 2001 From: Raphael Collet Date: Thu, 24 Mar 2011 10:41:29 +0100 Subject: [PATCH 06/68] add menu_id to portal, and adapt views bzr revid: rco@openerp.com-20110324094129-wtuxe65fa86o43oe --- addons/portal/portal.py | 11 ++++++--- addons/portal/portal_view.xml | 44 +++++++++++++++++++++++++++++++---- 2 files changed, 47 insertions(+), 8 deletions(-) diff --git a/addons/portal/portal.py b/addons/portal/portal.py index a96a3d94641..ff50a1ddcf3 100644 --- a/addons/portal/portal.py +++ b/addons/portal/portal.py @@ -26,10 +26,15 @@ class portal(osv.osv): _description = 'Portal' _columns = { 'name': fields.char(string='Name', size=64, required=True), - 'user_ids': fields.one2many('res.users', 'portal_id', string='Portal users', + 'menu_id': fields.many2one('ir.ui.menu', + string='Portal Menu', + help="The customized menu of the portal's users"), + 'user_ids': fields.one2many('res.users', 'portal_id', + string='Users', help='Gives the set of users associated to this portal'), - 'group_ids': fields.many2many('res.groups', 'portal_group', 'portal_id', 'group_id', - string='Groups', help='Users of this portal automatically belong to those groups'), + 'group_ids': fields.many2many('res.groups', 'res_portals_groups_rel', 'pid', 'gid', + string='Groups', + help='Users of this portal automatically belong to those groups'), } portal() diff --git a/addons/portal/portal_view.xml b/addons/portal/portal_view.xml index c58f7bc2c5f..af9a3a1d61b 100644 --- a/addons/portal/portal_view.xml +++ b/addons/portal/portal_view.xml @@ -22,13 +22,47 @@
- - - - - + + + + + + + + + + + + + + + + + menu_tree_view + ir.ui.menu + tree + child_id + + + + + + + + Menu Structure + ir.actions.act_window + ir.ui.menu + [('parent_id','=',False)] + tree + + + + From bccc450f5465f14d4b60a618b4622e648a6e1b7e Mon Sep 17 00:00:00 2001 From: Raphael Collet Date: Thu, 24 Mar 2011 12:52:10 +0100 Subject: [PATCH 07/68] extend the user form view to include the portal bzr revid: rco@openerp.com-20110324115210-cc170tsoc8rmhnmt --- addons/portal/portal_view.xml | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/addons/portal/portal_view.xml b/addons/portal/portal_view.xml index af9a3a1d61b..170ec9eedf7 100644 --- a/addons/portal/portal_view.xml +++ b/addons/portal/portal_view.xml @@ -39,6 +39,21 @@ + + + view_users_form + res.users + form + + + + + + + + + + From 3a791662feae8f8de694d2862f7e67fcffca67a1 Mon Sep 17 00:00:00 2001 From: Raphael Collet Date: Fri, 25 Mar 2011 12:12:06 +0100 Subject: [PATCH 08/68] override create() and write() to assign menu and groups to users bzr revid: rco@openerp.com-20110325111206-q9fy02xw4yep25rd --- addons/portal/portal.py | 49 +++++++++++++++++++++++++++++++++-- addons/portal/portal_view.xml | 2 +- 2 files changed, 48 insertions(+), 3 deletions(-) diff --git a/addons/portal/portal.py b/addons/portal/portal.py index ff50a1ddcf3..3b1448f3b2e 100644 --- a/addons/portal/portal.py +++ b/addons/portal/portal.py @@ -26,8 +26,8 @@ class portal(osv.osv): _description = 'Portal' _columns = { 'name': fields.char(string='Name', size=64, required=True), - 'menu_id': fields.many2one('ir.ui.menu', - string='Portal Menu', + 'menu_id': fields.many2one('ir.actions.actions', required="True", + string='Menu Action', help="The customized menu of the portal's users"), 'user_ids': fields.one2many('res.users', 'portal_id', string='Users', @@ -36,6 +36,42 @@ class portal(osv.osv): string='Groups', help='Users of this portal automatically belong to those groups'), } + + def create(self, cr, uid, values, context=None): + """ extend create() to assign the portal menu and groups to users """ + # as 'user_ids' is a many2one relation, values['user_ids'] must be a + # list of tuples of the form (0, 0, {values}) + for op, _, user_values in values['user_ids']: + assert op == 0 + user_values['menu_id'] = values['menu_id'] + user_values['groups_id'] = values['group_ids'] + + return super(portal, self).create(cr, uid, values, context) + + def write(self, cr, uid, ids, values, context=None): + """ extend write() to assign the portal menu and groups to users """ + user_object = self.pool.get('res.users') + + # first apply changes on the portals themselves + super(portal, self).write(cr, uid, ids, values, context) + + # then reflect changes on the users of each portal + # + # PERFORMANCE NOTE. The loop below performs N write() operations, where + # N=len(ids). This may seem inefficient, but in practice it is not, + # because: (1) N is pretty small (typically N=1), and (2) it is too + # complex (read: bug-prone) to write those updates as a single batch. + # + plist = self.browse(cr, uid, ids, context) + for p in plist: + user_ids = get_browse_ids(p.user_ids) + user_values = { + 'menu_id': get_browse_id(p.menu_id), + 'groups_id': [(6, 0, get_browse_ids(p.group_ids))], + } + user_object.write(cr, uid, user_ids, user_values, context) + + return True portal() @@ -49,3 +85,12 @@ class users(osv.osv): users() +# utils +def get_browse_id(obj): + """ return the id of a browse() object, or None """ + return (obj and obj.id or None) + +def get_browse_ids(objs): + """ return the ids of a list of browse() objects """ + return [(obj and obj.id or default) for obj in objs] + diff --git a/addons/portal/portal_view.xml b/addons/portal/portal_view.xml index 170ec9eedf7..c0608f29d06 100644 --- a/addons/portal/portal_view.xml +++ b/addons/portal/portal_view.xml @@ -23,7 +23,7 @@
- + From 160c47f80be303b695384c7c90aca098fc417f3e Mon Sep 17 00:00:00 2001 From: Raphael Collet Date: Fri, 25 Mar 2011 15:42:27 +0100 Subject: [PATCH 09/68] constrain portal name to be unique, and override method copy() bzr revid: rco@openerp.com-20110325144227-08wwe4mq1wn2195p --- addons/portal/portal.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/addons/portal/portal.py b/addons/portal/portal.py index 3b1448f3b2e..9790731eaf3 100644 --- a/addons/portal/portal.py +++ b/addons/portal/portal.py @@ -20,6 +20,7 @@ ############################################################################## from osv import osv, fields +import random class portal(osv.osv): _name = 'res.portal' @@ -36,6 +37,21 @@ class portal(osv.osv): string='Groups', help='Users of this portal automatically belong to those groups'), } + _sql_constraints = [ + ('unique_name', 'UNIQUE(name)', 'Portals must have different names.') + ] + + def copy(self, cr, uid, id, defaults, context=None): + """ override copy() to not copy the portal users """ + # find an unused name of the form "old_name [N]" for some random N + old_name = self.browse(cr, uid, id, context).name + new_name = copy_random(old_name) + while self.search(cr, uid, [('name', '=', new_name)], limit=1, context=context): + new_name = copy_random(old_name) + + defaults['name'] = new_name + defaults['user_ids'] = [] + return super(portal, self).copy(cr, uid, id, defaults, context) def create(self, cr, uid, values, context=None): """ extend create() to assign the portal menu and groups to users """ @@ -94,3 +110,7 @@ def get_browse_ids(objs): """ return the ids of a list of browse() objects """ return [(obj and obj.id or default) for obj in objs] +def copy_random(name): + """ return "name [N]" for some random integer N """ + return "%s [%s]" % (name, random.choice(xrange(1000000))) + From 95d72eada8dbb714364dd8c038397784473aed50 Mon Sep 17 00:00:00 2001 From: Raphael Collet Date: Fri, 25 Mar 2011 16:06:38 +0100 Subject: [PATCH 10/68] add tooltip bzr revid: rco@openerp.com-20110325150638-oicizdgr3wt8v3lc --- addons/portal/portal_view.xml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/addons/portal/portal_view.xml b/addons/portal/portal_view.xml index c0608f29d06..cc3b68c9de7 100644 --- a/addons/portal/portal_view.xml +++ b/addons/portal/portal_view.xml @@ -10,6 +10,11 @@ res.portal form tree,form + +A portal defines customized views and rules for a particular set of users. A +user may belong to at most one portal. A portal is associated to a menu and a +set of user groups, and those are automatically assigned to the portal's users. + @@ -39,7 +44,7 @@ - + view_users_form res.users From fe6f5abaf872c1c69ce15d95c39e61c32a7eb030 Mon Sep 17 00:00:00 2001 From: Raphael Collet Date: Mon, 28 Mar 2011 14:20:29 +0200 Subject: [PATCH 11/68] modify portal.write() to only perform diffs on users' groups bzr revid: rco@openerp.com-20110328122029-cz5k0vd3t44ggsnk --- addons/portal/portal.py | 78 +++++++++++++++++++++++++++++++---------- 1 file changed, 59 insertions(+), 19 deletions(-) diff --git a/addons/portal/portal.py b/addons/portal/portal.py index 9790731eaf3..1532eb2ee2a 100644 --- a/addons/portal/portal.py +++ b/addons/portal/portal.py @@ -65,27 +65,67 @@ class portal(osv.osv): return super(portal, self).create(cr, uid, values, context) def write(self, cr, uid, ids, values, context=None): - """ extend write() to assign the portal menu and groups to users """ - user_object = self.pool.get('res.users') + """ extend write() to reflect menu and groups changes on users """ - # first apply changes on the portals themselves + # analyse groups changes, and determine how to change users + groups_diff = [] + for change in values.get('group_ids', []): + if change[0] in [0, 5, 6]: # change creates or sets groups, + groups_diff = None # must compute per-portal diff + break + if change[0] in [3, 4]: # change add or remove group, + groups_diff.append(change) # add or remove group on users + + if groups_diff is None: + return self._write_compute_diff(cr, uid, ids, values, context) + else: + return self._write_diff(cr, uid, ids, values, groups_diff, context) + + def _write_diff(self, cr, uid, ids, values, groups_diff, context=None): + """ perform write() and apply groups_diff on users """ + # first apply portal changes super(portal, self).write(cr, uid, ids, values, context) - # then reflect changes on the users of each portal - # - # PERFORMANCE NOTE. The loop below performs N write() operations, where - # N=len(ids). This may seem inefficient, but in practice it is not, - # because: (1) N is pretty small (typically N=1), and (2) it is too - # complex (read: bug-prone) to write those updates as a single batch. - # - plist = self.browse(cr, uid, ids, context) - for p in plist: - user_ids = get_browse_ids(p.user_ids) - user_values = { - 'menu_id': get_browse_id(p.menu_id), - 'groups_id': [(6, 0, get_browse_ids(p.group_ids))], - } - user_object.write(cr, uid, user_ids, user_values, context) + # then apply menu and group changes on their users + user_values = {} + if 'menu_id' in values: + user_values['menu_id'] = values['menu_id'] + if groups_diff: + user_values['groups_id'] = groups_diff + + if user_values: + user_ids = [] + for p in self.browse(cr, uid, ids, context): + user_ids += get_browse_ids(p.user_ids) + self.pool.get('res.users').write(cr, uid, user_ids, user_values, context) + + return True + + def _write_compute_diff(self, cr, uid, ids, values, context=None): + """ perform write(), then compute and apply groups_diff on each portal """ + # read group_ids before write() to compute groups_diff + old_group_ids = {} + for p in self.browse(cr, uid, ids, context): + old_group_ids[p.id] = get_browse_ids(p.group_ids) + + # apply portal changes + super(portal, self).write(cr, uid, ids, values, context) + + # the changes to apply on users + user_values = {} + if 'menu_id' in values: + user_values['menu_id'] = values['menu_id'] + + # compute groups_diff on each portal, and apply them on users + for p in self.browse(cr, uid, ids, context): + old_groups = set(old_group_ids[p.id]) + new_groups = set(get_browse_ids(p.group_ids)) + # groups_diff: [(3, UNLINKED_ID), ..., (4, LINKED_ID), ...] + user_values['groups_id'] = \ + [(3, g) for g in (old_groups - new_groups)] + \ + [(4, g) for g in (new_groups - old_groups)] + user_ids = get_browse_ids(p.user_ids) + self.pool.get('res.users').write(cr, uid, user_ids, user_values, context) return True @@ -108,7 +148,7 @@ def get_browse_id(obj): def get_browse_ids(objs): """ return the ids of a list of browse() objects """ - return [(obj and obj.id or default) for obj in objs] + return map(get_browse_id, objs) def copy_random(name): """ return "name [N]" for some random integer N """ From e52ebf44986ce669dde5a60fa12300710825f809 Mon Sep 17 00:00:00 2001 From: Raphael Collet Date: Mon, 28 Mar 2011 14:26:02 +0200 Subject: [PATCH 12/68] adapt tooltip to recent changes bzr revid: rco@openerp.com-20110328122602-somnoycu3wfzikh6 --- addons/portal/portal_view.xml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/addons/portal/portal_view.xml b/addons/portal/portal_view.xml index cc3b68c9de7..ad86af95621 100644 --- a/addons/portal/portal_view.xml +++ b/addons/portal/portal_view.xml @@ -13,7 +13,9 @@ A portal defines customized views and rules for a particular set of users. A user may belong to at most one portal. A portal is associated to a menu and a -set of user groups, and those are automatically assigned to the portal's users. +set of user groups. When changed, the portal menu is assigned to the portal's +users. When groups are added to (resp. removed from) a portal, they are also +added to (resp. removed from) the portal's users. Date: Mon, 28 Mar 2011 14:30:30 +0200 Subject: [PATCH 13/68] remove a call to self.pool.get() from inside a loop bzr revid: rco@openerp.com-20110328123030-m09d6g7adh33ejc0 --- addons/portal/portal.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/addons/portal/portal.py b/addons/portal/portal.py index 1532eb2ee2a..c616605c42d 100644 --- a/addons/portal/portal.py +++ b/addons/portal/portal.py @@ -112,6 +112,7 @@ class portal(osv.osv): super(portal, self).write(cr, uid, ids, values, context) # the changes to apply on users + user_object = self.pool.get('res.users') user_values = {} if 'menu_id' in values: user_values['menu_id'] = values['menu_id'] @@ -125,7 +126,7 @@ class portal(osv.osv): [(3, g) for g in (old_groups - new_groups)] + \ [(4, g) for g in (new_groups - old_groups)] user_ids = get_browse_ids(p.user_ids) - self.pool.get('res.users').write(cr, uid, user_ids, user_values, context) + user_object.write(cr, uid, user_ids, user_values, context) return True From 842d5919dd901f407841b23e718995a52e0487e0 Mon Sep 17 00:00:00 2001 From: Raphael Collet Date: Mon, 28 Mar 2011 16:58:54 +0200 Subject: [PATCH 14/68] new portal users get the portal menu and groups as defaults bzr revid: rco@openerp.com-20110328145854-qc20llamomvv46o4 --- addons/portal/portal.py | 21 +++++++++++++++++++++ addons/portal/portal_view.xml | 3 ++- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/addons/portal/portal.py b/addons/portal/portal.py index c616605c42d..9a3af894007 100644 --- a/addons/portal/portal.py +++ b/addons/portal/portal.py @@ -139,6 +139,22 @@ class users(osv.osv): 'portal_id': fields.many2one('res.portal', string='Portal', help='If given, the portal defines customized menu and access rules'), } + + def default_get(self, cr, uid, fields, context=None): + """ override default values of menu_id and groups_id for portal users """ + others = {} + # How it works: the values of 'menu_id' and 'groups_id' are passed in + # context by the portal form view + if ('menu_id' in context) and ('menu_id' in fields): + fields.remove('menu_id') + others['menu_id'] = context['menu_id'] + if ('groups_id' in context) and ('groups_id' in fields): + fields.remove('groups_id') + others['groups_id'] = get_many2many(context['groups_id']) + # the remaining fields use inherited defaults + defs = super(users, self).default_get(cr, uid, fields, context) + defs.update(others) + return defs users() @@ -151,6 +167,11 @@ def get_browse_ids(objs): """ return the ids of a list of browse() objects """ return map(get_browse_id, objs) +def get_many2many(arg): + """ get the list of ids from a many2many 'values' field """ + assert len(arg) == 1 and arg[0][0] == 6 # arg = [(6, _, IDs)] + return arg[0][2] + def copy_random(name): """ return "name [N]" for some random integer N """ return "%s [%s]" % (name, random.choice(xrange(1000000))) diff --git a/addons/portal/portal_view.xml b/addons/portal/portal_view.xml index ad86af95621..d51a85ffd8b 100644 --- a/addons/portal/portal_view.xml +++ b/addons/portal/portal_view.xml @@ -32,7 +32,8 @@ added to (resp. removed from) the portal's users. - + From 899504690209b2e54e86fc2bdf92d2ac9cf908e0 Mon Sep 17 00:00:00 2001 From: Raphael Collet Date: Tue, 29 Mar 2011 12:24:04 +0200 Subject: [PATCH 15/68] add button to create portal menu bzr revid: rco@openerp.com-20110329102404-0exwdwpcfpai4oyk --- addons/portal/portal.py | 36 +++++++++++++++++++++++++++++++++++ addons/portal/portal_view.xml | 5 +++++ 2 files changed, 41 insertions(+) diff --git a/addons/portal/portal.py b/addons/portal/portal.py index 9a3af894007..c628b09b1bc 100644 --- a/addons/portal/portal.py +++ b/addons/portal/portal.py @@ -129,6 +129,42 @@ class portal(osv.osv): user_object.write(cr, uid, user_ids, user_values, context) return True + + def action_create_menu(self, cr, uid, ids, context=None): + """ create a menu for this portal """ + if len(ids) != 1: + raise ValueError("portal.action_create_menu() applies to one portal only") + portal_name = self.browse(cr, uid, ids[0], context).name + + # create a menuitem under 'portal.portal_menu_tree' + item_data = { + 'name': portal_name, + 'parent_id': self._get_res_id(cr, uid, 'portal', 'portal_menu_tree'), + } + item_id = self.pool.get('ir.ui.menu').create(cr, uid, item_data, context) + + # create an action to open the menuitems under item_id + action_data = { + 'name': portal_name, + 'type': 'ir.actions.act_window', + 'usage': 'menu', + 'res_model': 'ir.ui.menu', + 'view_type': 'tree', + 'view_id': self._get_res_id(cr, uid, 'base', 'view_menu'), + 'domain': [('parent_id', '=', item_id)], + } + action_id = self.pool.get('ir.actions.act_window').create(cr, uid, action_data, context) + + # set the portal menu_id to action_id + return self.write(cr, uid, ids, {'menu_id': action_id}, context) + + def _get_res_id(self, cr, uid, module, xml_id): + """ return the resource id associated to the given xml_id """ + ir_model_data_obj = self.pool.get('ir.model.data') + record_id = ir_model_data_obj._get_id(cr, uid, module, xml_id) + record_data = ir_model_data_obj.read(cr, uid, [record_id], ['res_id']) + assert (len(record_data) == 1) and ('res_id' in record_data[0]) + return record_data[0]['res_id'] portal() diff --git a/addons/portal/portal_view.xml b/addons/portal/portal_view.xml index d51a85ffd8b..4a440296db2 100644 --- a/addons/portal/portal_view.xml +++ b/addons/portal/portal_view.xml @@ -21,6 +21,9 @@ added to (resp. removed from) the portal's users. + + + Portal Form @@ -31,6 +34,8 @@ added to (resp. removed from) the portal's users. +