def update_user_groups_view(self, cr, uid, context=None): view = self.pool['ir.model.data'].xmlid_to_object( cr, SUPERUSER_ID, 'base.user_groups_view', context=context) if view and view.exists() and view._name == 'ir.ui.view': xml1, xml2 = [], [] xml1.append(E.separator(string=_('Application'), colspan="4")) xml3 = [] xml3.append(E.separator(string=_('User Roles'), colspan="4")) custom_group_id = None try: custom_group_id = \ self.pool['ir.model.data'].get_object_reference(cr, uid, 'res_roles', 'module_category_user_roles')[1] except: pass for app, kind, gs in self.get_groups_by_application( cr, uid, context): xml = None custom = False if type == 'selection' and any( [g.category_id.id == custom_group_id for g in gs]) or all( [g.category_id.id == custom_group_id for g in gs]): xml = xml3 custom = True # hide groups in category 'Hidden' (except to group_no_one) attrs = { 'groups': 'base.group_no_one'} if app and app.xml_id == 'base.module_category_hidden' and not custom else {} if kind == 'selection': xml = xml or xml1 # application name with a selection field field_name = name_selection_groups(map(int, gs)) xml.append(E.field(name=field_name, **attrs)) xml.append(E.newline()) else: xml = xml or xml2 # application separator with boolean fields app_name = app and app.name or _('Other') if not custom: xml.append( E.separator(string=app_name, colspan="4", **attrs)) for g in gs: field_name = name_boolean_group(g.id) xml.append(E.field(name=field_name, **attrs)) xml = E.field(*(xml3 + xml1 + xml2), name="groups_id", position="replace") xml.addprevious(etree.Comment("GENERATED AUTOMATICALLY BY GROUPS")) xml_content = etree.tostring(xml, pretty_print=True, xml_declaration=True, encoding="utf-8") view.write({'arch': xml_content}) return True
def _update_user_groups_view(self): # call super to make module compatible with other modules (e.g. access_restricted) super(GroupsView, self)._update_user_groups_view() if self._context.get('install_mode'): # use installation/admin language for translatable names in the view user_context = self.env['res.users'].context_get() self = self.with_context(**user_context) # We have to try-catch this, because at first init the view does not # exist but we are already creating some basic groups. view = self.env.ref('base.user_groups_view', raise_if_not_found=False) if view and view.exists() and view._name == 'ir.ui.view': group_no_one = view.env.ref('base.group_no_one') xml1, xml2 = [], [] xml1.append(E.separator(string=_('Application'), colspan="2")) xml3 = [] xml3.append(E.separator(string=_('Custom User Groups'), colspan="4")) for app, kind, gs in self.get_groups_by_application(): xml = None custom = False if kind == 'selection' and any([g.is_custom_group for g in gs]) or all([g.is_custom_group for g in gs]): xml = xml3 custom = True # hide groups in category 'Hidden' (except to group_no_one) attrs = {'groups': 'base.group_no_one'} if app and (app.xml_id == 'base.module_category_hidden' or app.xml_id == 'base.module_category_extra') and not custom else {} if kind == 'selection': xml = xml or xml1 # application name with a selection field field_name = name_selection_groups(map(int, gs)) xml.append(E.field(name=field_name, **attrs)) xml.append(E.newline()) else: xml = xml or xml2 # application separator with boolean fields app_name = app and app.name or _('Other') if not custom: xml.append(E.separator(string=app_name, colspan="4", **attrs)) for g in gs: field_name = name_boolean_group(g.id) if g == group_no_one: # make the group_no_one invisible in the form view xml.append(E.field(name=field_name, invisible="1", **attrs)) else: xml.append(E.field(name=field_name, **attrs)) xml2.append({'class': "o_label_nowrap"}) xml = E.field(E.group(*(xml3), col="2"), E.group(*(xml2), col="4"), E.group(*(xml1), col="2"), name="groups_id", position="replace") xml.addprevious(etree.Comment("GENERATED AUTOMATICALLY BY GROUPS")) xml_content = etree.tostring(xml, pretty_print=True, xml_declaration=True, encoding="utf-8") view.write({'arch': xml_content}) return True
def update_user_groups_view(self, cr, uid, context=None): view = self.pool['ir.model.data'].xmlid_to_object(cr, SUPERUSER_ID, 'base.user_groups_view', context=context) if view and view.exists() and view._name == 'ir.ui.view': xml1, xml2 = [], [] _attrs = { 'groups': 'base.group_no_one'} xml1.append(E.separator(string=_('Application'), colspan="4", **_attrs)) xml3 = [] xml3.append(E.separator(string=_('User Roles'), colspan="4")) custom_group_id = None try: custom_group_id = \ self.pool['ir.model.data'].get_object_reference(cr, uid, 'res_roles', 'module_category_user_roles')[1] except: pass for app, kind, gs in self.get_groups_by_application(cr, uid, context): xml = None custom = False if type == 'selection' and any([g.category_id.id == custom_group_id for g in gs]) or all( [g.category_id.id == custom_group_id for g in gs]): xml = xml3 custom = True # hide groups in category 'Hidden' (except to group_no_one) attrs = { 'groups': 'base.group_no_one'} if app and app.xml_id == 'base.module_category_hidden' and not custom else {} attrs = { 'groups': 'base.group_no_one'} if app and not custom else {} if kind == 'selection': xml = xml or xml1 # application name with a selection field field_name = name_selection_groups(map(int, gs)) xml.append(E.field(name=field_name, **attrs)) xml.append(E.newline()) else: xml = xml or xml2 # application separator with boolean fields app_name = app and app.name or _('Other') if not custom: xml.append(E.separator(string=app_name, colspan="4", **attrs)) for g in gs: field_name = name_boolean_group(g.id) xml.append(E.field(name=field_name, **attrs)) xml = E.field(*(xml3 + xml1 + xml2), name="groups_id", position="replace") xml.addprevious(etree.Comment("GENERATED AUTOMATICALLY BY GROUPS")) xml_content = etree.tostring(xml, pretty_print=True, xml_declaration=True, encoding="utf-8") view.write({'arch': xml_content}) return True
def update_user_groups_view(self, cr, uid, context=None): res = super(GroupsView, self).update_user_groups_view(cr, uid, context=context) if not context or context.get('install_mode'): # use installation/admin language for translatable names in the # view context = dict(context or {}) context.update(self.pool['res.users'].context_get(cr, uid)) view = self.pool['ir.model.data'].xmlid_to_object( cr, SUPERUSER_ID, 'epps_user.epps_user_groups_view', context=context) epps_modules_category = self.pool['ir.model.data'].xmlid_to_object( cr, SUPERUSER_ID, 'base.module_category_epps_modules', context=context) if view and view.exists() and view._name == 'ir.ui.view': xml1, xml2 = [], [] xml1.append(E.separator(string=_('Modules'), colspan="1")) xml1.append(E.separator(string=_('Access Rights'), colspan="1")) xml1.append(E.separator(string=_(''), colspan="2")) for app, kind, gs in self.get_groups_by_application( cr, uid, context): if app and app.parent_id and app.parent_id.id == epps_modules_category.id and app.visible != False: # hide groups in category 'Hidden' (except to group_no_one) attrs = { 'groups': 'base.group_no_one'} if app and app.xml_id == 'base.module_category_hidden' else {} if kind == 'selection': # application name with a selection field field_name = name_selection_groups(map(int, gs)) xml1.append(E.field(name=field_name, **attrs)) xml1.append(E.newline()) else: # application separator with boolean fields app_name = app and app.name or _('Other') xml2.append( E.separator(string=app_name, colspan="4", **attrs)) for g in gs: field_name = name_boolean_group(g.id) xml2.append(E.field(name=field_name, **attrs)) xml = E.field(*(xml1 + xml2), name="groups_id", position="replace") xml.addprevious(etree.Comment("GENERATED AUTOMATICALLY BY GROUPS")) xml_content = etree.tostring(xml, pretty_print=True, xml_declaration=True, encoding="utf-8") view.write({'arch': xml_content}) return res
def fields_get(self, cr, uid, allfields=None, context=None, write_access=True, attributes=None): res = super(ResUsers, self).fields_get(cr, uid, allfields, context, write_access, attributes) # add reified groups fields if uid != SUPERUSER_ID and not (self.pool['res.users'].has_group( cr, uid, 'base.group_erp_manager') or self.pool['res.users'].has_group( cr, uid, 'epps_user.group_customer_administrator')): return res for app, kind, gs in self.pool['res.groups'].get_groups_by_application( cr, uid, context): if kind == 'selection': # selection group field tips = [ '%s: %s' % (g.name, g.comment) for g in gs if g.comment ] res[name_selection_groups(map(int, gs))] = { 'type': 'selection', 'string': app and app.name or _('Other'), 'selection': [(False, '')] + [(g.id, g.name) for g in gs], 'help': '\n'.join(tips), 'exportable': False, 'selectable': False, } else: # boolean group fields for g in gs: res[name_boolean_group(g.id)] = { 'type': 'boolean', 'string': g.name, 'help': g.comment, 'exportable': False, 'selectable': False, } return res
def update_user_groups_view(self, cr, uid, context=None): ''' This function is almost the same with the function in original module, except the part that we always set attrs Readonly to True for all groups. So that list of groups for a user is always get from Profile Group ''' view = self.pool['ir.model.data'].xmlid_to_object( cr, SUPERUSER_ID, 'base.user_groups_view', context=context) if view and view.exists() and view._name == 'ir.ui.view': xml1, xml2 = [], [] xml1.append(E.separator(string=_('Application'), colspan="4")) for app, kind, gs in self.get_groups_by_application( cr, uid, context): # hide groups in category 'Hidden' (except to group_no_one) # Trobz: all groups here should be readonly and based on # profile attrs = {'readonly': '1'} if kind == 'selection': # application name with a selection field field_name = name_selection_groups(map(int, gs)) xml1.append(E.field(name=field_name, **attrs)) xml1.append(E.newline()) else: # application separator with boolean fields app_name = app and app.name or _('Other') xml2.append( E.separator(string=app_name, colspan="4", **attrs)) for g in gs: field_name = name_boolean_group(g.id) xml2.append(E.field(name=field_name, **attrs)) xml = E.field(*(xml1 + xml2), name="groups_id", position="replace") xml.addprevious(etree.Comment("GENERATED AUTOMATICALLY BY GROUPS")) xml_content = etree.tostring(xml, pretty_print=True, xml_declaration=True, encoding="utf-8") view.write({'arch': xml_content}) return True
def fields_get(self, cr, uid, allfields=None, context=None, write_access=True, attributes=None): res = super(res_users, self).fields_get(cr, uid, allfields, context, write_access, attributes) # add reified groups fields if not self.pool['res.users']._is_admin(cr, uid, [uid]): return res for app, kind, gs in self.pool['res.groups'].\ get_groups_by_application(cr, uid, context): if kind == 'selection': # selection group field tips = [ '%s: %s' % (g.name, g.comment) for g in gs if g.comment ] res[name_selection_groups(map(int, gs))] = { 'type': 'selection', 'string': app and app.name or _('Other'), 'selection': [(False, '')] + [(g.id, g.name) for g in gs], 'help': '\n'.join(tips), 'exportable': False, 'selectable': False, } else: # boolean group fields for g in gs: res[name_boolean_group(g.id)] = { 'type': 'boolean', 'string': g.name, 'help': g.comment, 'exportable': False, 'selectable': False, } return res
def update_user_groups_view(self, cr, uid, context=None): # the view with id 'base.user_groups_view' inherits the user form view, # and introduces the reified group fields # we have to try-catch this, because at first init the view does not exist # but we are already creating some basic groups user_context = dict(context or {}) if user_context.get('install_mode'): # use installation/admin language for translatable names in the view user_context.update(self.pool['res.users'].context_get(cr, uid)) view = self.pool['ir.model.data'].xmlid_to_object( cr, SUPERUSER_ID, 'base.user_groups_view', context=user_context) if view and view.exists() and view._name == 'ir.ui.view': group_no_one = view.env.ref('base.group_no_one') xml1, xml2 = [], [] xml1.append(E.separator(string=_('Application'), colspan="2")) xml3 = [] xml3.append( E.separator(string=_('Custom User Groups'), colspan="4")) for app, kind, gs in self.get_groups_by_application( cr, uid, user_context): xml = None custom = False if kind == 'selection' and any([g.is_custom_group for g in gs]) or all([ g.is_custom_group for g in gs ]): xml = xml3 custom = True # hide groups in category 'Hidden' (except to group_no_one) attrs = { 'groups': 'base.group_no_one' } if app and (app.xml_id == 'base.module_category_hidden' or app.xml_id == 'base.module_category_extra' ) and not custom else {} if kind == 'selection': xml = xml or xml1 # application name with a selection field field_name = name_selection_groups(map(int, gs)) xml.append(E.field(name=field_name, **attrs)) xml.append(E.newline()) else: xml = xml or xml2 # application separator with boolean fields app_name = app and app.name or _('Other') if not custom: xml.append( E.separator(string=app_name, colspan="4", **attrs)) for g in gs: field_name = name_boolean_group(g.id) if g == group_no_one: # make the group_no_one invisible in the form view xml.append( E.field(name=field_name, invisible="1", **attrs)) else: xml.append(E.field(name=field_name, **attrs)) xml2.append({'class': "o_label_nowrap"}) xml = E.field(E.group(*(xml3), col="2"), E.group(*(xml2), col="4"), E.group(*(xml1), col="2"), name="groups_id", position="replace") xml.addprevious(etree.Comment("GENERATED AUTOMATICALLY BY GROUPS")) xml_content = etree.tostring(xml, pretty_print=True, xml_declaration=True, encoding="utf-8") view.write({'arch': xml_content}) return True