diff options
| author | Raphael Collet <rco@openerp.com> | 2012-09-14 16:46:33 +0200 |
|---|---|---|
| committer | Raphael Collet <rco@openerp.com> | 2012-09-14 16:46:33 +0200 |
| commit | 941cb76283aa05bc7e255c2af68251bd39b7ca78 (patch) | |
| tree | 7a491743c6aa680477ae7d0924f8268bf08c0206 | |
| parent | 95d5ff7332344ce5d263acede7ede714b2a7eb9d (diff) | |
[IMP] portal: replace model 'res.portal' by 'res.groups' where field 'is_portal' is True
bzr revid: rco@openerp.com-20120914144633-z3xpe7392egz3640
| -rw-r--r-- | addons/portal/mail_mail.py | 2 | ||||
| -rw-r--r-- | addons/portal/portal.py | 190 | ||||
| -rw-r--r-- | addons/portal/portal_data.xml | 8 | ||||
| -rw-r--r-- | addons/portal/portal_demo.xml | 2 | ||||
| -rw-r--r-- | addons/portal/portal_view.xml | 71 | ||||
| -rw-r--r-- | addons/portal/security/portal_security.xml | 4 | ||||
| -rw-r--r-- | addons/portal/tests/test_portal.py | 2 | ||||
| -rw-r--r-- | addons/portal/wizard/portal_wizard.py | 14 | ||||
| -rw-r--r-- | addons/portal/wizard/share_wizard.py | 8 |
9 files changed, 35 insertions, 266 deletions
diff --git a/addons/portal/mail_mail.py b/addons/portal/mail_mail.py index 72c8469c042..5b149c1146a 100644 --- a/addons/portal/mail_mail.py +++ b/addons/portal/mail_mail.py @@ -43,7 +43,7 @@ class mail_mail_portal(osv.Model): :param partner: browse_record of the specific recipient partner """ if partner: - portal_ref = self.pool.get('ir.model.data').get_object_reference(cr, uid, 'portal', 'portal') + portal_ref = self.pool.get('ir.model.data').get_object_reference(cr, uid, 'portal', 'portal_group') portal_id = portal_ref and portal_ref[1] or False url = self._generate_signin_url(cr, uid, partner.id, portal_id, 1234, context=context) body = tools.append_content_to_html(mail.body_html, url) diff --git a/addons/portal/portal.py b/addons/portal/portal.py index 3672d87cf30..13cde80f849 100644 --- a/addons/portal/portal.py +++ b/addons/portal/portal.py @@ -20,196 +20,14 @@ ############################################################################## from osv import osv, fields -from tools.translate import _ - class portal(osv.osv): + """ A portal is simply a group of users with the flag 'is_portal' set to True. + The flag 'is_portal' makes a user group usable as a portal. """ - A portal is a group of users with specific menu, widgets, and typically - restricted access rights. - """ - _name = 'res.portal' - _description = 'Portal' - _inherits = {'res.groups': 'group_id'} - - _columns = { - 'group_id': fields.many2one('res.groups', required=True, ondelete='cascade', - string='Group', - help='The group corresponding to this portal'), - 'url': fields.char('URL', - help="The url where portal users can connect to the server"), - 'home_action_id': fields.many2one('ir.actions.actions', - string='Home Action', - help="if set, replaces the standard home action (first screen after loggin) for the portal's users"), - 'menu_action_id': fields.many2one('ir.actions.act_window', readonly=True, - # ISSUE: 'ondelete' constraints do not seem effective on this field... - string='Menu Action', - help="If set, replaces the standard menu for the portal's users"), - 'parent_menu_id': fields.many2one('ir.ui.menu', ondelete='restrict', - string='Parent Menu', - help='The menu action opens the submenus of this menu item'), - 'widget_ids': fields.one2many('res.portal.widget', 'portal_id', - string='Widgets', - help='Widgets assigned to portal users'), - } - - def copy(self, cr, uid, id, values, context=None): - """ override copy(): menu_action_id must be different """ - values['menu_action_id'] = None - return super(portal, self).copy(cr, uid, id, values, context) - - def create(self, cr, uid, values, context=None): - """ extend create() to assign the portal menu to users """ - if context is None: - context = {} - - # create portal (admin should not be included) - context['noadmin'] = True - portal_id = super(portal, self).create(cr, uid, values, context) - - # assign menu action and widgets to users - if values.get('users') or values.get('menu_action_id'): - self._assign_menu(cr, uid, [portal_id], context) - if values.get('users') or values.get('widget_ids'): - self._assign_widgets(cr, uid, [portal_id], context) - - return portal_id - - def write(self, cr, uid, ids, values, context=None): - """ extend write() to reflect changes on users """ - # first apply portal changes - super(portal, self).write(cr, uid, ids, values, context) - - # assign menu action and widgets to users - if values.get('users') or values.get('menu_action_id'): - self._assign_menu(cr, uid, ids, context) - if values.get('users') or values.get('widget_ids'): - self._assign_widgets(cr, uid, ids, context) - - # if parent_menu_id has changed, apply the change on menu_action_id - if 'parent_menu_id' in values: - act_window_obj = self.pool.get('ir.actions.act_window') - portals = self.browse(cr, uid, ids, context) - action_ids = [p.menu_action_id.id for p in portals if p.menu_action_id] - if action_ids: - action_values = {'domain': [('parent_id', '=', values['parent_menu_id'])]} - act_window_obj.write(cr, uid, action_ids, action_values, context) - - return True - - def _assign_menu(self, cr, uid, ids, context=None): - """ assign portal_menu_settings to users of portals (ids) """ - user_obj = self.pool.get('res.users') - for p in self.browse(cr, uid, ids, context): - # user menu action = portal menu action if set in portal - if p.menu_action_id: - user_ids = [u.id for u in p.users if u.id != 1] - user_values = {'menu_id': p.menu_action_id.id} - user_obj.write(cr, uid, user_ids, user_values, context) - - def _assign_widgets(self, cr, uid, ids, context=None): - """ assign portal widgets to users of portals (ids) """ - widget_user_obj = self.pool.get('res.widget.user') - for p in self.browse(cr, uid, ids, context): - for w in p.widget_ids: - values = {'sequence': w.sequence, 'widget_id': w.widget_id.id} - for u in p.users: - if u.id == 1: continue - values['user_id'] = u.id - widget_user_obj.create(cr, uid, values, context) - - def _res_xml_id(self, cr, uid, module, xml_id): - """ return the resource id associated to the given xml_id """ - data_obj = self.pool.get('ir.model.data') - data_id = data_obj._get_id(cr, uid, module, xml_id) - return data_obj.browse(cr, uid, data_id).res_id - -portal() - - - -class portal_override_menu(osv.osv): - """ - Extend res.portal with a boolean field 'Override Users Menu', that - triggers the creation or removal of menu_action_id - """ - _name = 'res.portal' - _inherit = 'res.portal' - - def _get_override_menu(self, cr, uid, ids, field_name, arg, context=None): - assert field_name == 'override_menu' - result = {} - for p in self.browse(cr, uid, ids, context): - result[p.id] = bool(p.menu_action_id) - return result - - def _set_override_menu(self, cr, uid, id, field_name, field_value, arg, context=None): - assert field_name == 'override_menu' - if field_value: - self.create_menu_action(cr, uid, id, context) - else: - self.write(cr, uid, [id], {'menu_action_id': False}, context) - - def create_menu_action(self, cr, uid, id, context=None): - """ create, if necessary, a menu action that opens the menu items below - parent_menu_id """ - p = self.browse(cr, uid, id, context) - if not p.menu_action_id: - actions_obj = self.pool.get('ir.actions.act_window') - parent_id = p.parent_menu_id.id if p.parent_menu_id else False - action_values = { - 'name': _('%s Menu') % p.name, - 'type': 'ir.actions.act_window', - 'usage': 'menu', - 'res_model': 'ir.ui.menu', - 'view_type': 'tree', - 'view_id': self._res_xml_id(cr, uid, 'base', 'view_menu'), - 'domain': [('parent_id', '=', parent_id)], - } - action_id = actions_obj.create(cr, uid, action_values, context) - self.write(cr, uid, [id], {'menu_action_id': action_id}, context) - - _columns = { - 'override_menu': fields.function( - _get_override_menu, fnct_inv=_set_override_menu, - type='boolean', string='Override Menu Action of Users', - help='Enable this option to override the Menu Action of portal users'), - } - -portal_override_menu() - - - -class portal_widget(osv.osv): - """ - Similar to res.widget.user (res_widget.py), but with a portal instead. - New users in a portal are assigned the portal's widgets. - """ - _name='res.portal.widget' - _description = 'Portal Widgets' - _order = 'sequence' + _inherit = 'res.groups' _columns = { - 'sequence': fields.integer('Sequence'), - 'portal_id': fields.many2one('res.portal', select=1, ondelete='cascade', - string='Portal'), - 'widget_id': fields.many2one('res.widget', required=True, ondelete='cascade', - string='Widget'), + 'is_portal': fields.boolean('Portal', help="If checked, this group is usable as a portal."), } - def create(self, cr, uid, values, context=None): - domain = [('portal_id', '=', values.get('portal_id')), - ('widget_id', '=', values.get('widget_id'))] - existing = self.search(cr, uid, domain, context=context) - if existing: - res = existing[0] - else: - res = super(portal_widget, self).create(cr, uid, values, context=context) - return res - -portal_widget() - - - - -# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/addons/portal/portal_data.xml b/addons/portal/portal_data.xml index 5edb4bed8c7..a980552a854 100644 --- a/addons/portal/portal_data.xml +++ b/addons/portal/portal_data.xml @@ -2,14 +2,6 @@ <openerp> <data noupdate="1"> - <record id="portal" model="res.portal"> - <field name="name">Portal</field> - <field name="group_id" ref="group_portal"/> - <field name="override_menu" eval="False"/> - <!-- Insert the template user from auth_signup in the portal members group --> - <field name="users" eval="[(4,ref('auth_signup.default_template_user'))]"/> - </record> - <!-- Mail group for the company's news --> <record id="company_news_feed" model="mail.group"> <field name="name">Company's news</field> diff --git a/addons/portal/portal_demo.xml b/addons/portal/portal_demo.xml index 1ace02f3d7d..f4ba8fe2192 100644 --- a/addons/portal/portal_demo.xml +++ b/addons/portal/portal_demo.xml @@ -13,7 +13,7 @@ </record> <!-- Add the demo user to the portal (and therefore to the portal member group) --> - <record id="portal" model="res.portal"> + <record id="group_portal" model="res.groups"> <field name="users" eval="[(4,ref('demo_user0'))]"/> </record> diff --git a/addons/portal/portal_view.xml b/addons/portal/portal_view.xml index 5241d7cf54f..abd013d719c 100644 --- a/addons/portal/portal_view.xml +++ b/addons/portal/portal_view.xml @@ -21,71 +21,30 @@ <menuitem name="Projects" id="portal_projects" parent="portal_menu" sequence="40"/> <menuitem name="After Sale Services" id="portal_after_sales" parent="portal_menu" sequence="50"/> - <!-- portal tree view --> - <record id="portal_list_view" model="ir.ui.view"> - <field name="name">Portal List</field> - <field name="model">res.portal</field> + <!-- extend res.groups search view --> + <record id="group_search_view" model="ir.ui.view"> + <field name="name">Group Search</field> + <field name="model">res.groups</field> + <field name="inherit_id" ref="base.view_groups_search"/> <field name="arch" type="xml"> - <tree string="Portals"> - <field name="name" string="Portal Name"/> - </tree> + <field name="name" position="after"> + <filter string="Portal" help="Portal groups" name="portal_groups" + domain="[('is_portal','=',True)]"/> + </field> </field> </record> - <!-- portal form view --> - <record id="portal_form_view" model="ir.ui.view"> + <!-- extend res.groups form view --> + <record id="group_form_view" model="ir.ui.view"> <field name="name">Portal Form</field> - <field name="model">res.portal</field> + <field name="model">res.groups</field> <field name="inherit_id" ref="base.view_groups_form"/> <field name="arch" type="xml"> - <page string="Users" position="before"> - <page string="Portal"> - <group> - <group> - <field name="url" widget="url" string="Portal URL"/> - <field name="home_action_id"/> - </group> - <group> - <field name="override_menu"/> - <field name="parent_menu_id" - context="{'ir.ui.menu.full_list': True}"/> - <label for="partent_menu_id" colspan="1"/> - </group> - <separator string="Widgets Assigned to Users" colspan="2"/> - <field name="widget_ids" nolabel="1" colspan="2"> - <tree string="Widgets" editable="bottom"> - <field name="sequence"/> - <field name="widget_id"/> - </tree> - </field> - </group> - </page> - </page> + <field name="name" position="after"> + <field name="is_portal"/> + </field> </field> </record> - <!-- action Administration/Portals/Portals --> - <record id="portal_list_action" model="ir.actions.act_window"> - <field name="name">Portals</field> - <field name="res_model">res.portal</field> - <field name="view_type">form</field> - <field name="view_mode">tree,form</field> - <!-- a context is necessary to get the right portal form view --> - <field name="context">{'form_view_ref': 'portal.portal_form_view'}</field> - <field name="help" type="html"> - <p class="oe_view_nocontent_create"> - Click to create a new portal. - </p><p> - A portal helps defining specific views and rules for a group of - users (the portal group). A portal menu, widgets and specific - groups may be assigned to the portal's users. - </p> - </field> - </record> - - <!-- menu Administration/Portals/Portals --> - <menuitem name="Portals Settings" id="portal_menu_settings" parent="base.menu_administration"/> - <menuitem name="Portals" id="portal_list_menu" parent="portal_menu_settings" action="portal_list_action"/> - </data> </openerp> diff --git a/addons/portal/security/portal_security.xml b/addons/portal/security/portal_security.xml index 0bf4cb2dcfc..3d5cf47b0be 100644 --- a/addons/portal/security/portal_security.xml +++ b/addons/portal/security/portal_security.xml @@ -6,7 +6,9 @@ <record id="group_portal" model="res.groups"> <field name="name">Portal</field> <field name="comment">Portal members can access information through the portal menu. Also, they are chrooted in this specific menu.</field> - <!-- Don't use any implied_ids here; this group's behavior is particular --> + <field name="is_portal" eval="True"/> + <!-- Insert the template user from auth_signup in the portal members group --> + <field name="users" eval="[(4,ref('auth_signup.default_template_user'))]"/> </record> </data> diff --git a/addons/portal/tests/test_portal.py b/addons/portal/tests/test_portal.py index 2c301228859..809bc131034 100644 --- a/addons/portal/tests/test_portal.py +++ b/addons/portal/tests/test_portal.py @@ -42,7 +42,7 @@ class test_portal(test_mail.TestMailMockups): user_admin = self.res_users.browse(cr, uid, uid) self.mail_invite = self.registry('mail.wizard.invite') base_url = self.registry('ir.config_parameter').get_param(cr, uid, 'web.base.url', default='') - portal_ref = self.registry('ir.model.data').get_object_reference(cr, uid, 'portal', 'portal') + portal_ref = self.registry('ir.model.data').get_object_reference(cr, uid, 'portal', 'portal_group') portal_id = portal_ref and portal_ref[1] or False # 0 - Admin diff --git a/addons/portal/wizard/portal_wizard.py b/addons/portal/wizard/portal_wizard.py index da9d9b4e18d..969f74b5bd8 100644 --- a/addons/portal/wizard/portal_wizard.py +++ b/addons/portal/wizard/portal_wizard.py @@ -78,7 +78,7 @@ class wizard(osv.osv_memory): _columns = { 'partner_id': fields.many2one('res.partner', required=True, string="Partner"), - 'portal_id': fields.many2one('res.portal', required=True, + 'portal_id': fields.many2one('res.groups', domain=[('is_portal', '=', True)], required=True, string='Portal', help="The portal in which new users must be added"), 'user_ids': fields.one2many('res.portal.wizard.user', 'wizard_id', @@ -157,7 +157,7 @@ class wizard(osv.osv_memory): for address in partner.child_ids: _portal_user(address) partner_user_ids = self._search_partner_user(cr, uid, partner.id, context=context) - portal_users = [u.id for u in self.pool.get('res.portal').browse(cr, uid, portal_id, context=context).group_id.users] + portal_users = [u.id for u in self.pool.get('res.groups').browse(cr, uid, portal_id, context=context).users] for user in res_user.browse(cr, uid, partner_user_ids, context=context): email = user and user.email or False has_portal_user = False @@ -302,17 +302,17 @@ class wizard_user(osv.osv_memory): return user_id def link_portal_user(self, cr, uid, portal_id, user_id, context=None): - res_portal = self.pool.get('res.portal') - portal = res_portal.browse(cr, uid, portal_id, context=context) - portal_user_ids = [u.id for u in portal.group_id.users] + res_groups = self.pool.get('res.groups') + portal = res_groups.browse(cr, uid, portal_id, context=context) + portal_user_ids = [u.id for u in portal.users] if user_id not in portal_user_ids: return portal.write({'users': [(4, user_id)]}, context=context) if user_id in portal_user_ids: return False def unlink_portal_user(self, cr, uid, portal_id, user_id, context=None): - res_portal = self.pool.get('res.portal') - return res_portal.write(cr, uid, [portal_id], {'users': [(3, user_id)]}, context=context) + res_groups = self.pool.get('res.groups') + return res_groups.write(cr, uid, [portal_id], {'users': [(3, user_id)]}, context=context) def unlink_user(self, cr, uid, user_id, context=None): #TODO: search portal groups diff --git a/addons/portal/wizard/share_wizard.py b/addons/portal/wizard/share_wizard.py index e56e7517348..b1b6e980dec 100644 --- a/addons/portal/wizard/share_wizard.py +++ b/addons/portal/wizard/share_wizard.py @@ -119,16 +119,14 @@ class share_wizard_portal(osv.TransientModel): # alter the rules of the groups so they can see the shared data if wizard_data.group_ids: # get the list of portals and the related groups to install their menus. - 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] + res_groups = self.pool.get('res.groups') + all_portal_group_ids = res_groups.search(cr, UID_ROOT, [('is_portal', '=', True)]) # populate result lines with the users of each group and # setup the menu for portal groups 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) + self._create_shared_data_menu(cr, uid, wizard_data, group.id, context=context) for user in group.users: new_line = {'user_id': user.id, |
