mirror of
https://github.com/bs-community/blessing-skin-server.git
synced 2024-12-21 06:19:38 +08:00
Enhance rendering notice for unsatisfied plugin dependencies
This commit is contained in:
parent
b4e8b7e8c9
commit
815fef7f3d
@ -48,22 +48,23 @@ class PluginController extends Controller
|
||||
switch ($request->get('action')) {
|
||||
case 'enable':
|
||||
if (! $plugins->isRequirementsSatisfied($plugin)) {
|
||||
$msg = '';
|
||||
$reason = [];
|
||||
|
||||
foreach ($plugins->getUnsatisfiedRequirements($plugin) as $name => $detail) {
|
||||
$constraint = $detail['constraint'];
|
||||
|
||||
if (! $detail['version']) {
|
||||
$msg .= '<li>'.trans('admin.plugins.operations.unsatisfied.disabled', [
|
||||
'name' => "<code>$name</code>"
|
||||
]).'</li>';
|
||||
$reason[] = trans('admin.plugins.operations.unsatisfied.disabled', compact('name'));
|
||||
} else {
|
||||
$msg .= '<li>'.trans('admin.plugins.operations.unsatisfied.version', [
|
||||
'name' => "<code>$name</code>",
|
||||
'constraint' => "<code>{$detail['constraint']}</code>"
|
||||
]).'</li>';
|
||||
$reason[] = trans('admin.plugins.operations.unsatisfied.version', compact('name', 'constraint'));
|
||||
}
|
||||
}
|
||||
|
||||
return json('<p>'.trans('admin.plugins.operations.unsatisfied.notice')."</p><ul>$msg</ul>", 1);
|
||||
return json([
|
||||
'errno' => 1,
|
||||
'msg' => trans('admin.plugins.operations.unsatisfied.notice'),
|
||||
'reason' => $reason
|
||||
]);
|
||||
}
|
||||
|
||||
$plugins->enable($name);
|
||||
|
@ -415,7 +415,7 @@ describe('tests for "plugins" module', () => {
|
||||
requirements: { 'a': '^1.1.0', 'b': '^2.1.0', 'c': '^3.3.0' },
|
||||
unsatisfiedRequirements: { 'c': '^3.3.0' }
|
||||
}))
|
||||
.mockReturnValueOnce(Promise.resolve({ errno: 1, msg: 'warning' }))
|
||||
.mockReturnValueOnce(Promise.resolve({ errno: 1, msg: 'notice', reason: ['reason1', 'reason2'] }))
|
||||
.mockReturnValueOnce(Promise.reject());
|
||||
const url = jest.fn(path => path);
|
||||
const swal = jest.fn()
|
||||
@ -464,7 +464,7 @@ describe('tests for "plugins" module', () => {
|
||||
expect(reloadTable).toBeCalledWith(null, false);
|
||||
|
||||
await enablePlugin('plugin');
|
||||
expect(swal).toBeCalledWith({ type: 'warning', html: 'warning' });
|
||||
expect(swal).toBeCalledWith({ type: 'warning', html: '<p>notice</p><ul><li>reason1</li><li>reason2</li></ul>' });
|
||||
|
||||
await enablePlugin('plugin');
|
||||
expect(showAjaxError).toBeCalled();
|
||||
|
@ -102,17 +102,18 @@ async function enablePlugin(name) {
|
||||
});
|
||||
}
|
||||
|
||||
const { errno, msg } = await fetch({
|
||||
const { errno, msg, reason } = await fetch({
|
||||
type: 'POST',
|
||||
url: url(`admin/plugins/manage?action=enable&name=${name}`),
|
||||
dataType: 'json'
|
||||
});
|
||||
|
||||
if (errno === 0) {
|
||||
toastr.success(msg);
|
||||
|
||||
$.pluginsTable.ajax.reload(null, false);
|
||||
} else {
|
||||
swal({ type: 'warning', html: msg });
|
||||
swal({ type: 'warning', html: `<p>${msg}</p><ul><li>${reason.join('</li><li>')}</li></ul>` });
|
||||
}
|
||||
} catch (error) {
|
||||
showAjaxError(error);
|
||||
|
@ -110,8 +110,8 @@ plugins:
|
||||
enabled: :plugin has been enabled.
|
||||
unsatisfied:
|
||||
notice: There are unsatisfied dependencies in the plugin, therefore we can't enable it. Please install or update the plugins listed below.
|
||||
disabled: The :name plugin is not enabled.
|
||||
version: The version of :name does not satisfies the constraint :constraint
|
||||
disabled: The <code>:name</code> plugin is not enabled
|
||||
version: The version of <code>:name</code> does not satisfies the constraint <code>:constraint</code>
|
||||
disabled: :plugin has been disabled.
|
||||
deleted: The plugin was deleted successfully.
|
||||
no-config-notice: The plugin is not installed or doesn't provide configuration page.
|
||||
|
@ -110,8 +110,8 @@ plugins:
|
||||
enabled: :plugin 已启用
|
||||
unsatisfied:
|
||||
notice: 无法启用此插件,因为其仍有未满足的依赖关系。请检查以下插件的版本,更新或安装它们:
|
||||
disabled: :name 插件未启用
|
||||
version: :name 的版本不符合要求 :constraint
|
||||
disabled: <code>:name</code> 插件未启用
|
||||
version: <code>:name</code> 的版本不符合要求 <code>:constraint</code>
|
||||
disabled: :plugin 已禁用
|
||||
deleted: 插件已被成功删除
|
||||
no-config-notice: 插件未安装或未提供配置页面
|
||||
|
@ -95,17 +95,16 @@ class PluginControllerTest extends TestCase
|
||||
'action' => 'enable'
|
||||
])->seeJson([
|
||||
'errno' => 1,
|
||||
'msg' => sprintf(
|
||||
'<p>%s</p><ul><li>%s</li><li>%s</li></ul>',
|
||||
trans('admin.plugins.operations.unsatisfied.notice'),
|
||||
'msg' => trans('admin.plugins.operations.unsatisfied.notice'),
|
||||
'reason' => [
|
||||
trans('admin.plugins.operations.unsatisfied.version', [
|
||||
'name' => "<code>example-plugin</code>",
|
||||
'constraint' => "<code>^6.6.6</code>"
|
||||
'name' => 'example-plugin',
|
||||
'constraint' => '^6.6.6'
|
||||
]),
|
||||
trans('admin.plugins.operations.unsatisfied.disabled', [
|
||||
'name' => "<code>whatever</code>"
|
||||
'name' => 'whatever'
|
||||
])
|
||||
)
|
||||
]
|
||||
]);
|
||||
|
||||
// Enable a plugin
|
||||
|
Loading…
Reference in New Issue
Block a user