add wizard to add/remove groups to portal users
bzr revid: rco@openerp.com-20110405101712-knepwhu9b0c3vlaj
This commit is contained in:
@@ -20,4 +20,5 @@
|
||||
##############################################################################
|
||||
|
||||
import portal
|
||||
import wizard
|
||||
|
||||
|
||||
@@ -38,7 +38,7 @@ module 'share'.
|
||||
""",
|
||||
'website': 'http://www.openerp.com',
|
||||
'demo_xml': [],
|
||||
'data': ['portal_view.xml'],
|
||||
'data': ['portal_view.xml', 'wizard_view.xml'],
|
||||
'installable': True,
|
||||
'certificate' : '',
|
||||
}
|
||||
|
||||
@@ -31,8 +31,10 @@ portal's users.
|
||||
<field name="group_id" on_change="onchange_group(group_id)"/>
|
||||
<notebook>
|
||||
<page string="Users">
|
||||
<field name="user_ids" nolabel="1" colspan="4"
|
||||
<field name="user_ids" nolabel="1" colspan="3"
|
||||
context="{'menu_id': menu_action_id}"/>
|
||||
<group name="user_panel" colspan="1"/>
|
||||
<!-- wizards insert buttons inside the group 'user_panel' -->
|
||||
</page>
|
||||
<page string="Menu">
|
||||
<field name="menu_action_id"/>
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
##############################################################################
|
||||
#
|
||||
# OpenERP, Open Source Management Solution
|
||||
# Copyright (C) 2004-2011 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 osv, fields
|
||||
from tools.translate import _
|
||||
|
||||
class groups_wizard(osv.osv_memory):
|
||||
_name = 'res.portal.groups'
|
||||
_description = 'Portal Groups Wizard'
|
||||
_columns = {
|
||||
'portal_id': fields.many2one('res.portal', required=True, readonly=True,
|
||||
string='Portal'),
|
||||
'add_group_ids': fields.many2many('res.groups',
|
||||
'portal_groups_add', 'portal_groups_id', 'group_ids',
|
||||
string='Add Groups'),
|
||||
'remove_group_ids': fields.many2many('res.groups',
|
||||
'portal_groups_remove', 'portal_groups_id', 'group_ids',
|
||||
string='Remove Groups'),
|
||||
}
|
||||
_defaults = {
|
||||
'portal_id': (lambda self,cr,uid,context: context and context.get('active_id'))
|
||||
}
|
||||
|
||||
def do_apply(self, cr, uid, ids, context=None, *args):
|
||||
assert len(ids) == 1
|
||||
wizard = self.browse(cr, uid, ids[0], context)
|
||||
|
||||
# select all portal users except admin
|
||||
user_ids = [u.id for u in wizard.portal_id.user_ids if u.id != 1]
|
||||
|
||||
# apply group adds and removals to portal users
|
||||
add_gids = [(4, g.id) for g in wizard.add_group_ids]
|
||||
rem_gids = [(3, g.id) for g in wizard.remove_group_ids]
|
||||
user_values = {'groups_id': add_gids + rem_gids}
|
||||
self.pool.get('res.users').write(cr, uid, user_ids, user_values, context)
|
||||
|
||||
# return an empty dictionary to close the wizard window
|
||||
return {}
|
||||
|
||||
groups_wizard()
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<openerp>
|
||||
<data>
|
||||
<!-- groups wizard action -->
|
||||
<record id="groups_wizard_action" model="ir.actions.act_window">
|
||||
<field name="name">Add/Remove Groups</field>
|
||||
<field name="res_model">res.portal.groups</field>
|
||||
<field name="view_type">form</field>
|
||||
<field name="view_mode">form</field>
|
||||
<field name="target">new</field>
|
||||
</record>
|
||||
|
||||
<!-- groups wizard form -->
|
||||
<record id="groups_wizard_form" model="ir.ui.view">
|
||||
<field name="name">Portal Groups Wizard</field>
|
||||
<field name="model">res.portal.groups</field>
|
||||
<field name="type">form</field>
|
||||
<field name="priority" eval="16"/>
|
||||
<field name="arch" type="xml">
|
||||
<form string="Portal Groups Wizard">
|
||||
<group colspan="4">
|
||||
<field name="portal_id"/>
|
||||
</group>
|
||||
<separator string="Add Groups" colspan="2"/>
|
||||
<separator string="Remove Groups" colspan="2"/>
|
||||
<field name="add_group_ids" nolabel="1" colspan="2"/>
|
||||
<field name="remove_group_ids" nolabel="1" colspan="2"/>
|
||||
<separator colspan="4"/>
|
||||
<label colspan="2"/>
|
||||
<button special="cancel"
|
||||
string="Cancel" icon="gtk-cancel"/>
|
||||
<button name="do_apply" type="object"
|
||||
string="Apply" icon="gtk-apply"/>
|
||||
</form>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<!-- add a button in the portal form view -->
|
||||
<record id="portal_form_with_groups_wizard" model="ir.ui.view">
|
||||
<field name="name">Portal Form</field>
|
||||
<field name="model">res.portal</field>
|
||||
<field name="inherit_id" ref="portal_form"/>
|
||||
<field name="arch" type="xml">
|
||||
<xpath expr="//group[@name='user_panel']" position="inside">
|
||||
<button name="%(groups_wizard_action)d" type="action"
|
||||
string="Add/Remove Groups"/>
|
||||
</xpath>
|
||||
</field>
|
||||
</record>
|
||||
</data>
|
||||
</openerp>
|
||||
Reference in New Issue
Block a user