Ejemplo n.º 1
0
def disable_plugin(plugin):
    try:
        plugin = get_plugin(plugin)
    except KeyError:
        flash(_("Plugin %(plugin)s not found.", plugin=plugin.name), "danger")
        return redirect(url_for("management.plugins"))

    plugin_dir = os.path.join(os.path.abspath(os.path.dirname(os.path.dirname(__file__))), "plugins", plugin.identifier)

    disabled_file = os.path.join(plugin_dir, "DISABLED")

    try:
        open(disabled_file, "a").close()
        flash(_("Plugin is disabled. Please reload your app."), "success")

    except OSError:
        flash(
            _(
                "If you are using a host which doesn't "
                "support writting on the disk, this won't work - than you "
                "need to create a 'DISABLED' file by yourself."
            ),
            "info",
        )

    return redirect(url_for("management.plugins"))
Ejemplo n.º 2
0
 def setting(self, plugin):
     """
     Set plugin base info
     :param plugin:
     :return:
     """
     plugin = get_plugin(plugin)
     return self.render('weko_plugins/admin/plugin_setting.html',
                        plugin=plugin)
Ejemplo n.º 3
0
 def detail(self, plugin):
     """
     Get plugin base info
     :param plugin:
     :return:
     """
     plugin = get_plugin(plugin)
     return self.render('weko_plugins/admin/plugin_detail.html',
                        plugin=plugin)
Ejemplo n.º 4
0
 def delete(self, plugin):
     """
     Delete the plugin
     :param plugin:
     :return:
     """
     plugin = get_plugin(plugin)
     if plugin is not None:
         plugin.delete()
         del current_plugins.plugin_manager.plugins[plugin.identifier]
         # del current_plugins.plugin_manager.all_plugins[plugin.identifier]
     return redirect(url_for('pluginsetting.index'))
Ejemplo n.º 5
0
def setting(plugin):
    """
    Set plugin base info.

    :param plugin:
    :return:

    """
    plugin = get_plugin(plugin)
    return render_template(
        'weko_plugins/plugin_setting.html',
        plugin=plugin
    )
Ejemplo n.º 6
0
 def enable(self, plugin):
     """
     Enable the plugin
     :param plugin:
     :return:
     """
     plugin = get_plugin(plugin)
     current_plugins.plugin_manager.enable_plugins([plugin])
     redirect_url = url_for('pluginsetting.index')
     href = request.args.get('href', 'index')
     if 'detail' == href:
         redirect_url = url_for('pluginsetting.detail',
                                plugin=plugin.identifier)
     return redirect(redirect_url)
Ejemplo n.º 7
0
def disable_plugin(plugin):
    try:
        plugin = get_plugin(plugin)
    except KeyError:
        flash(_("Plugin %(plugin)s not found.", plugin=plugin.name), "danger")
        return redirect(url_for("management.plugins"))

    try:
        plugin.disable()
        flash(_("Plugin %(plugin)s disabled. Please restart FlaskBB now.",
                plugin=plugin.name), "success")
    except OSError:
        flash(_("It seems that FlaskBB does not have enough filesystem "
                "permissions. Try creating the 'DISABLED' file by "
                "yourself."), "danger")

    return redirect(url_for("management.plugins"))
Ejemplo n.º 8
0
def disable_plugin(plugin):
    try:
        plugin = get_plugin(plugin)
    except KeyError:
        flash(_("Plugin %(plugin)s not found.", plugin=plugin.name), "danger")
        return redirect(url_for("management.plugins"))

    try:
        plugin.disable()
        flash(_("Plugin %(plugin)s disabled. Please restart FlaskBB now.",
                plugin=plugin.name), "success")
    except OSError:
        flash(_("It seems that FlaskBB does not have enough filesystem "
                "permissions. Try creating the 'DISABLED' file by "
                "yourself instead."), "danger")

    return redirect(url_for("management.plugins"))
Ejemplo n.º 9
0
def disable_plugin(plugin):
    try:
        plugin = get_plugin(plugin)
    except KeyError:
        flash(_("Plugin %(plugin)s not found.", plugin=plugin.name), "danger")
        return redirect(url_for("management.plugins"))

    plugin_dir = os.path.join(
        os.path.abspath(os.path.dirname(os.path.dirname(__file__))), "plugins",
        plugin.identifier)

    disabled_file = os.path.join(plugin_dir, "DISABLED")

    open(disabled_file, "a").close()

    flash(_("Plugin is disabled. Please reload your app."), "success")

    flash(
        _("If you are using a host which doesn't "
          "support writting on the disk, this won't work - than you need to "
          "create a 'DISABLED' file by yourself."), "info")

    return redirect(url_for("management.plugins"))
Ejemplo n.º 10
0
    def test_get_plugin(self):
        with self.app.test_request_context():
            plugin = get_plugin("test1")

        self.assertEquals(plugin, self.plugin_manager.plugins["test1"])
Ejemplo n.º 11
0
def test_admin(app):
    """Test Weko-Plugin interace."""
    wekoplugins(app)
    admin = Admin(app, name='Test')

    assert 'view_class' in plugin_adminview
    assert 'kwargs' in plugin_adminview

    # Register both models in admin
    view_class = plugin_adminview.pop('view_class')
    kwargs = plugin_adminview.pop('kwargs')
    admin.add_view(view_class(**kwargs))

    # Check if generated admin menu contains the correct items
    menu_items = {str(item.name): item for item in admin.menu()}
    assert 'Plugins' in menu_items
    assert menu_items['Plugins'].is_category()

    submenu_items = {
        str(item.name): item for item in menu_items['Plugins'].get_children()
    }
    assert 'Plugin List' in submenu_items
    assert isinstance(submenu_items['Plugin List'], menu.MenuView)

    with app.test_request_context():
        index_view_url = url_for('pluginsetting.index')
        assert '/admin/pluginsetting/' == index_view_url
        detail_view_url = url_for('pluginsetting.detail',
                                  plugin='hello_world')
        assert '/admin/pluginsetting/hello_world' == detail_view_url
        setting_view_url = url_for('pluginsetting.setting',
                                   plugin='hello_world')
        assert '/admin/pluginsetting/setting/hello_world' == setting_view_url
        disable_view_url = url_for('pluginsetting.disable',
                                   plugin='hello_world')
        assert '/admin/pluginsetting/disable/hello_world' == disable_view_url
        enable_view_url = url_for('pluginsetting.enable',
                                  plugin='hello_world')
        assert '/admin/pluginsetting/enable/hello_world' == enable_view_url
        delete_view_url = url_for('pluginsetting.delete',
                                  plugin='hello_world')
        assert '/admin/pluginsetting/delete/hello_world' == delete_view_url

    with app.test_client() as client:
        # List plugin view.
        res = client.get(index_view_url)
        assert res.status_code == 200

        # List plugin view.
        res = client.get(detail_view_url)
        assert res.status_code == 200

        # List plugin view.
        res = client.get(setting_view_url)
        assert res.status_code == 200

        # List plugin view.
        res = client.get(disable_view_url)
        assert res.status_code == 302
        plugin = get_plugin('hello_world')
        assert plugin.enabled is False

        # List plugin view.
        res = client.get(enable_view_url)
        assert res.status_code == 302
        plugin = get_plugin('hello_world')
        assert plugin.enabled is True

        # List plugin view.
        res = client.get(delete_view_url)
        assert res.status_code == 302
        try:
            plugin = get_plugin('hello_world')
            assert 1 == 0
        except KeyError:
            # test success when except is happened
            assert 1 == 1
Ejemplo n.º 12
0
def disable(plugin):
    plugin = get_plugin(plugin)
    plugins.disable_plugins([plugin])
    j = {"status": "plugin_action_disabled"}
    return jsonify(j)
Ejemplo n.º 13
0
 def enable(plugin):
     plugin = get_plugin(plugin)
     plugin_manager.enable_plugins([plugin])
     return redirect(url_for("index"))
Ejemplo n.º 14
0
    def test_get_plugin(self):
        with self.app.test_request_context():
            plugin = get_plugin("test1")

        self.assertEquals(plugin, self.plugin_manager.plugins["test1"])
Ejemplo n.º 15
0
def enable(plugin):
    plugin = get_plugin(plugin)
    plugin_manager.enable_plugins([plugin])
    return redirect(url_for("index"))