Пример #1
0
def set_auditlog_states():
    from lucterios.CORE.parameters import Params
    try:
        LucteriosAuditlogModelRegistry.set_state_packages(
            Params.getvalue('CORE-AuditLog').split())
    except LucteriosException:
        pass
Пример #2
0
    def test_auditlog_user(self):
        LucteriosAuditlogModelRegistry.set_state_packages(['CORE'])

        self.factory.xfer = AudiLogConfig()
        self.calljson('/CORE/audiLogConfig', {'type_selected': 'CORE.lucteriosuser'}, False)
        self.assert_count_equal('lucterioslogentry', 0)

        self.factory.xfer = GroupsList()
        self.calljson('/CORE/groupsList', {}, False)
        self.assert_count_equal('group', 1)

        self.factory.xfer = GroupsEdit()
        self.calljson('/CORE/groupsEdit', {'SAVE': 'YES', 'name': 'truc', 'permissions': '7;9;13'}, False)
        self.assert_observer('core.acknowledge', 'CORE', 'groupsEdit')

        self.factory.xfer = AudiLogConfig()
        self.calljson('/CORE/audiLogConfig', {'type_selected': 'CORE.lucteriosuser'}, False)
        self.assert_count_equal('lucterioslogentry', 1)

        self.factory.xfer = GroupsDelete()
        self.calljson('/CORE/groupsDelete', {'group': '2', "CONFIRME": 'YES'}, False)
        self.assert_observer('core.acknowledge', 'CORE', 'groupsDelete')

        self.factory.xfer = AudiLogConfig()
        self.calljson('/CORE/audiLogConfig', {'type_selected': 'CORE.lucteriosgroup'}, False)
        self.assert_count_equal('lucterioslogentry', 2)
        self.assert_json_equal('', 'lucterioslogentry/@0/action', 2)
        self.assert_json_equal('', 'lucterioslogentry/@0/object_repr', "truc")
        self.assert_json_equal('', 'lucterioslogentry/@1/action', 0)
        self.assert_json_equal('', 'lucterioslogentry/@1/object_repr', "truc")
Пример #3
0
def get_url_patterns():
    res = _init_url_patterns()
    for appname in settings.INSTALLED_APPS:
        appmodule = import_module(appname)
        is_lucterios_ext = False
        for _, modname, ispkg in pkgutil.iter_modules(appmodule.__path__):
            if (modname[:5] == 'views') and not ispkg:
                view = import_module(appname + '.' + modname)
                for obj in inspect.getmembers(view):
                    try:
                        if obj[1].url_text != '':
                            if inspect.isclass(obj[1]):
                                is_lucterios_ext = True
                                as_view_meth = getattr(obj[1], "as_view")
                                res.append(
                                    url(r"^%s$" % obj[1].url_text,
                                        as_view_meth()))
                    except AttributeError:
                        pass
            elif settings.APPLIS_MODULE == appmodule:
                is_lucterios_ext = True
        if not is_lucterios_ext:
            try:
                patterns = getattr(import_module('%s.urls' % appname),
                                   'urlpatterns', None)
                if isinstance(patterns, (list, tuple)):
                    for url_pattern in patterns:
                        module_items = appname.split('.')
                        if module_items[0] == 'lucterios':
                            continue
                        if module_items[0] == 'django':
                            res.append(url_pattern)
                        else:
                            res.append(
                                url(
                                    r"^%s/%s" %
                                    (module_items[-1],
                                     url_pattern.pattern._regex[1:]),
                                    url_pattern.callback, None,
                                    url_pattern.pattern.name))
            except ImportError:
                pass
    print("PluginManager.get_instance")
    for plugin_item in PluginManager.get_instance():
        for view_item in plugin_item.views:
            res.append(url(r"^%s$" % view_item.url_text, view_item.as_view()))
    try:
        from django.contrib.admin.sites import site
        res.append(url(r'^accounts/login/$', site.login))
    except ImportError:
        pass
    res.extend(staticfiles_urlpatterns())
    logging.getLogger('lucterios.core.init').debug("Urls:" + '\n'.join(
        str(res_item) for res_item in res))
    Signal.call_signal("auditlog_register")
    LucteriosAuditlogModelRegistry.main_enabled()
    return res
Пример #4
0
    def test_auditlog_user(self):
        LucteriosAuditlogModelRegistry.set_state_packages(['CORE'])

        self.factory.xfer = AudiLogConfig()
        self.calljson('/CORE/audiLogConfig',
                      {'type_selected': 'CORE.lucteriosuser'}, False)
        self.assert_count_equal('lucterioslogentry', 0)

        self.factory.xfer = UsersList()
        self.calljson('/CORE/usersList', {}, False)
        self.assert_observer('core.custom', 'CORE', 'usersList')
        self.assert_count_equal('user_actif', 2)
        self.assert_count_equal('user_inactif', 0)

        self.factory.xfer = UsersEdit()
        self.calljson(
            '/CORE/usersEdit', {
                'SAVE': 'YES',
                'username': '******',
                'first_name': 'John',
                'last_name': 'Doe',
                'user_permissions': '1;3;4'
            }, False)
        self.assert_observer('core.acknowledge', 'CORE', 'usersEdit')

        self.factory.xfer = AudiLogConfig()
        self.calljson('/CORE/audiLogConfig',
                      {'type_selected': 'CORE.lucteriosuser'}, False)
        self.assert_count_equal('lucterioslogentry', 1)

        self.factory.xfer = UsersDisabled()
        self.calljson('/CORE/usersDisabled', {'user_actif': '3'}, False)
        self.assert_observer('core.acknowledge', 'CORE', 'usersDisabled')

        self.factory.xfer = AudiLogConfig()
        self.calljson('/CORE/audiLogConfig',
                      {'type_selected': 'CORE.lucteriosuser'}, False)
        self.assert_count_equal('lucterioslogentry', 2)

        self.factory.xfer = UsersDelete()
        self.calljson('/CORE/usersDelete', {
            'user_actif': '3',
            "CONFIRME": 'YES'
        }, False)
        self.assert_observer('core.acknowledge', 'CORE', 'usersDelete')

        self.factory.xfer = AudiLogConfig()
        self.calljson('/CORE/audiLogConfig',
                      {'type_selected': 'CORE.lucteriosuser'}, False)
        self.assert_count_equal('lucterioslogentry', 3)
        self.assert_json_equal('', 'lucterioslogentry/@0/action', 2)
        self.assert_json_equal('', 'lucterioslogentry/@0/object_repr', "abc")
        self.assert_json_equal('', 'lucterioslogentry/@1/action', 1)
        self.assert_json_equal('', 'lucterioslogentry/@1/object_repr', "abc")
        self.assert_json_equal('', 'lucterioslogentry/@2/action', 0)
        self.assert_json_equal('', 'lucterioslogentry/@2/object_repr', "abc")
Пример #5
0
def get_url_patterns():
    url_patterns = UrlPatterns()
    for appname in settings.INSTALLED_APPS:
        if not url_patterns.add_lct_application(appname):
            url_patterns.add_ext_application(appname)
    url_patterns.add_plugins()
    url_patterns.add_extra_url()
    logging.getLogger('lucterios.core.init').debug("Urls:" + '\n'.join(str(res_item) for res_item in url_patterns))
    Signal.call_signal("auditlog_register")
    LucteriosAuditlogModelRegistry.main_enabled()
    return url_patterns
Пример #6
0
def get_sender_ident_for_m2m(sender, instance):
    from lucterios.framework.auditlog import LucteriosAuditlogModelRegistry
    sender_ident = six.text_type(sender)
    attrname = six.text_type(instance._meta.verbose_name),
    for m2m_property in LucteriosAuditlogModelRegistry.get_m2m_property(
            instance.__class__):
        if m2m_property.through == sender:
            sender_ident = six.text_type(m2m_property.field.verbose_name)
            attrname = m2m_property.field.name
    return sender_ident, attrname
Пример #7
0
 def tearDown(self):
     LucteriosTest.tearDown(self)
     LucteriosAuditlogModelRegistry.set_state_packages([])
Пример #8
0
 def tearDown(self):
     LucteriosTest.tearDown(self)
     tools.WrapAction.mode_connect_notfree = parameters.notfree_mode_connect
     LucteriosAuditlogModelRegistry.set_state_packages([])