[IMP] portal: inherit share wizard to auto-create the menu

bzr revid: odo@openerp.com-20110408150951-q41mksjz1khb5zp8
This commit is contained in:
Olivier Dony
2011-04-08 17:09:51 +02:00
parent b1bd44df42
commit 0a6b44e6ca
6 changed files with 136 additions and 20 deletions
+2 -3
View File
@@ -2,7 +2,7 @@
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2004-2011 Tiny SPRL (<http://tiny.be>).
# Copyright (C) 2004-2011 OpenERP S.A (<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
@@ -20,5 +20,4 @@
##############################################################################
import portal
import wizard
import wizard
+8 -5
View File
@@ -2,7 +2,7 @@
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2004-2011 Tiny SPRL (<http://tiny.be>).
# Copyright (C) 2004-2011 OpenERP S.A (<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
@@ -22,8 +22,8 @@
{
"name" : "Portal",
"version" : "0.2",
"depends" : ["base"],
"version" : "0.3",
"depends" : ["base", "share"],
"author" : "OpenERP SA",
"category": 'Tools',
"description": """
@@ -37,8 +37,11 @@ users, etc). That feature is very handy when used in combination with the
module 'share'.
""",
'website': 'http://www.openerp.com',
'demo_xml': [],
'data': ['portal_view.xml', 'wizard_view.xml'],
'data': ['security/portal_security.xml',
'security/ir.model.access.csv',
'portal_view.xml',
'wizard_view.xml',
],
'installable': True,
'certificate' : '',
}
+23
View File
@@ -0,0 +1,23 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2004-2011 OpenERP S.A (<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/>.
#
##############################################################################
import share_wizard
import groups_wizard
@@ -2,7 +2,7 @@
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2004-2011 Tiny SPRL (<http://tiny.be>).
# Copyright (C) 2004-2011 OpenERP S.A (<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
+90
View File
@@ -0,0 +1,90 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2004-2011 OpenERP S.A (<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
UID_ROOT = 1
SHARED_DOCS_MENU = "Shared Documents"
class share_wizard_portal(osv.osv_memory):
"""Inherited share wizard to automatically create appropriate
menus in the selected portal upon sharing with a portal group."""
_inherit = "share.wizard"
def _sharing_root_menu_id(self, cr, uid, portal, context=None):
"""Create or retrieve root ID of sharing menu in portal menu
:param portal: browse_record of portal, constructed with a context WITHOUT language
"""
if not portal.parent_menu_id:
# no specific parent menu, cannot create the sharing menu at all.
return
# look for an existing SHARED_DOCS_MENU
sharing_root_menu_id = None
for child_menu in portal.parent_menu_id.child_id:
if child_menu.name == SHARED_DOCS_MENU:
sharing_root_menu_id = child_menu.id
break
if not sharing_root_menu_id:
# not found, create it
sharing_root_menu_id = self.pool.get('ir.ui.menu').create(cr, UID_ROOT,
{'name': SHARED_DOCS_MENU,
'parent_id': portal.parent_menu_id.id,
'sequence': 999, # at the bottom
})
return sharing_root_menu
def _create_shared_data_menu(self, cr, uid, wizard_data, portal, context=None):
"""Create sharing menus in portal menu according to share wizard options.
:param wizard_data: browse_record of share.wizard
:param portal: browse_record of portal, constructed with a context WITHOUT language
"""
root_menu_id = self._sharing_root_menu_id(cr, uid, portal, context=context)
if not root_menu_id:
# no specific parent menu, cannot create the sharing menu at all.
return
# Create the shared action and menu
action_def = self._shared_action_def(cr, uid, wizard_data, context=None)
action_id = self.pool.get('ir.actions.act_window').create(cr, UID_ROOT, action_def)
menu_data = {'name': action_def['name'],
'sequence': 10,
'action': 'ir.actions.act_window,'+str(action_id),
'parent_id': root_menu_id,
'icon': 'STOCK_JUSTIFY_FILL'}
menu_id = self.pool.get('ir.ui.menu').create(cr, UID_ROOT, menu_data)
return menu_id
def _create_share_users_groups(self, cr, uid, wizard_data, context=None):
"""Create sharing menus in portal menu after sharing"""
group_ids = super(share_wizard_portal,self)._create_share_users_groups(cr, uid, wizard_data, context=context)
if wizard_data.user_type == "groups":
# get the list of portals and the related groups
Portals = self.pool.get('res.portal')
all_portals = Portals.browse(cr, UID_ROOT, Portals.search(cr, UID_ROOT, [])) #no context!
all_portal_group_ids = [p.group_id.id for p in all_portals]
for group in wizard_data.group_ids:
if group.id in all_portal_group_ids:
portal = all_portals[all_portal_group_ids.index(group.id)]
self._create_shared_data_menu(cr, uid, wizard_data, portal, context=context)
return group_ids
share_wizard_portal()
+12 -11
View File
@@ -46,7 +46,6 @@ def generate_random_pass():
random.shuffle(pass_chars)
return ''.join(pass_chars[0:10])
class share_create(osv.osv_memory):
__logger = logging.getLogger('share.wizard')
_name = 'share.wizard'
@@ -181,7 +180,6 @@ class share_create(osv.osv_memory):
menu_obj._cache[key] = True
return action_id
def _cleanup_action_context(self, context_str, user_id):
"""Returns a dict representing the context_str evaluated (literal_eval) as
a dict where items that are not useful for shared actions
@@ -207,21 +205,24 @@ class share_create(osv.osv_memory):
result = context_str
return result
def _shared_action_def(self, cr, uid, wizard_data, context=None):
return {
'name': (_('%s (Shared)') % wizard_data.action_id.name)[:64],
'domain': wizard_data.domain,
'context': self._cleanup_action_context(wizard_data.action_id.context, uid),
'res_model': wizard_data.action_id.res_model,
'view_mode': wizard_data.action_id.view_mode,
'view_type': wizard_data.action_id.view_type,
'search_view_id': wizard_data.action_id.search_view_id.id,
}
def _setup_action_and_shortcut(self, cr, uid, wizard_data, user_ids, new_users, context=None):
"""Create a shortcut to reach the shared data, as well as the corresponding action, for
each user in ``user_ids``, and assign it as their home action."""
user_obj = self.pool.get('res.users')
menu_action_id = user_obj._get_menu(cr, uid, context=context)
for user_id in user_ids:
values = {
'name': (_('%s (Shared)') % wizard_data.action_id.name)[:64],
'domain': wizard_data.domain,
'context': self._cleanup_action_context(wizard_data.action_id.context, user_id),
'res_model': wizard_data.action_id.res_model,
'view_mode': wizard_data.action_id.view_mode,
'view_type': wizard_data.action_id.view_type,
'search_view_id': wizard_data.action_id.search_view_id.id,
}
values = self._shared_action_def(cr, uid, wizard_data, context=None)
action_id = self._create_shortcut(cr, user_id, values)
if new_users:
user_obj.write(cr, UID_ROOT, [user_id], {'action_id': action_id})