Esempio n. 1
0
 def fields_get(self, allfields=None, attributes=None):
     res = super(UsersView, self).fields_get(allfields, attributes=attributes)
     if self.env.user._is_superuser():
         return res
     # add reified groups fields
     for app, kind, gs in self.env['res.groups'].sudo().get_groups_by_application():
         gs_system = gs.filtered(lambda r: r.system_group)
         if gs_system:
             gs_filtered = gs.filtered(lambda r: not r.system_group)
             if kind == 'selection':
                 if gs_filtered:
                     # selection group field
                     tips = ['%s: This group can only be assigned by the system user! %s' % (g.name, g.comment if g.comment else '') if g.system_group else '%s: %s' % (g.name, g.comment) for g in gs if g.comment or g.system_group]
                     res[name_selection_groups(gs.ids)] = {
                         'type': 'selection',
                         'string': app.name or _('Other'),
                         'selection': [(False, '')] + [(g.id, '[SYSTEM] %s' % g.name if g.system_group else g.name) for g in gs],
                         'help': '\n'.join(tips),
                         'exportable': False,
                         'selectable': False,
                     }
                 else:
                     del res[name_selection_groups(gs.ids)]
             else:
                 for g in gs_system:
                     del res[name_boolean_group(g.id)]
     return res
Esempio n. 2
0
    def test_base(self):
        demo_user = self.env.ref('base.user_demo')
        group_erp_manager = self.env.ref('base.group_erp_manager')
        group_system = self.env.ref('base.group_system')

        demo_user.write({'groups_id': [(3, group_system.id)]})
        group_system.write({'users': [(3, demo_user.id)]})
        demo_user.write({'groups_id': [(4, group_erp_manager.id)]})

        view_users_form = self.env.ref('base.view_users_form')
        res = self.env['res.users'].sudo(demo_user).with_context({
            'uid':
            demo_user.id
        }).load_views([[view_users_form.id, "form"]])

        sel_groups = name_selection_groups([group_erp_manager.id])
        res = self.env['res.users'].sudo(demo_user).fields_get()
        self.assertTrue(res.get(sel_groups))

        demo_user.write({'groups_id': [(4, group_system.id)]})

        sel_groups = name_selection_groups(
            [group_erp_manager.id, group_system.id])
        res = self.env['res.users'].sudo(demo_user).fields_get()
        self.assertTrue(res.get(sel_groups))
Esempio n. 3
0
    def test_base(self):
        demo_user = self.env.ref('base.user_demo')
        group_erp_manager = self.env.ref('base.group_erp_manager')
        group_system = self.env.ref('base.group_system')

        demo_user.write({'groups_id': [(3, group_system.id)]})
        group_system.write({'users': [(3, demo_user.id)]})
        demo_user.write({'groups_id': [(4, group_erp_manager.id)]})

        view_users_form = self.env.ref('base.view_users_form')
        res = self.env['res.users'].sudo(demo_user).with_context({'uid': demo_user.id}).load_views([[view_users_form.id, "form"]])

        sel_groups = name_selection_groups([group_erp_manager.id])
        res = self.env['res.users'].sudo(demo_user).fields_get()
        self.assertTrue(res.get(sel_groups))

        demo_user.write({'groups_id': [(4, group_system.id)]})

        sel_groups = name_selection_groups([group_erp_manager.id, group_system.id])
        res = self.env['res.users'].sudo(demo_user).fields_get()
        self.assertTrue(res.get(sel_groups))
 def _prepare_user_group_ids_from_default_get(self):
     group_obj = self.env['res.groups']
     user_obj = self.env['res.users']
     res1 = group_obj.get_groups_by_application()
     fields = []
     for item in res1:
         if item[1] == 'boolean':
             for group in item[2]:
                 fields.append(name_boolean_group(group.id))
         elif item[1] == 'selection':
             fields.append(name_selection_groups(item[2].ids))
     res2 = user_obj.default_get(fields)
     return res2['groups_id'][0][2]
Esempio n. 5
0
    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