2018-01-04 19:04:22 +01:00
|
|
|
import { get } from 'lodash';
|
2019-04-16 12:54:16 +02:00
|
|
|
import { all, fork, call, put, select, takeLatest } from 'redux-saga/effects';
|
2019-04-16 11:53:29 +02:00
|
|
|
import { auth, request } from 'strapi-helper-plugin';
|
2019-02-22 10:05:07 +01:00
|
|
|
import { pluginDeleted } from '../App/actions';
|
2018-01-05 16:19:53 +01:00
|
|
|
import { selectLocale } from '../LanguageProvider/selectors';
|
2019-09-09 16:45:25 +02:00
|
|
|
import { deletePluginSucceeded, getPluginsSucceeded } from './actions';
|
2017-11-09 11:25:01 +01:00
|
|
|
import { GET_PLUGINS, ON_DELETE_PLUGIN_CONFIRM } from './constants';
|
2017-11-02 16:49:10 +01:00
|
|
|
import { makeSelectPluginToDelete } from './selectors';
|
|
|
|
|
|
2020-01-21 16:03:31 +01:00
|
|
|
/* eslint-disable */
|
|
|
|
|
|
2017-11-02 16:49:10 +01:00
|
|
|
export function* deletePlugin() {
|
|
|
|
|
try {
|
|
|
|
|
const plugin = yield select(makeSelectPluginToDelete());
|
2018-03-06 18:32:39 +01:00
|
|
|
|
2017-11-02 16:49:10 +01:00
|
|
|
const requestUrl = `/admin/plugins/uninstall/${plugin}`;
|
|
|
|
|
|
|
|
|
|
const resp = yield call(request, requestUrl, { method: 'DELETE' });
|
|
|
|
|
|
|
|
|
|
if (resp.ok) {
|
2017-11-09 11:25:01 +01:00
|
|
|
yield put(deletePluginSucceeded(plugin));
|
2017-11-02 16:49:10 +01:00
|
|
|
yield put(pluginDeleted(plugin));
|
2017-12-05 16:29:46 +01:00
|
|
|
|
|
|
|
|
if (plugin === 'users-permissions') {
|
|
|
|
|
auth.clearAppStorage();
|
|
|
|
|
}
|
2017-11-02 16:49:10 +01:00
|
|
|
}
|
2019-04-16 11:53:29 +02:00
|
|
|
} catch (error) {
|
2017-11-09 11:25:01 +01:00
|
|
|
yield put(deletePluginSucceeded(false));
|
2019-04-16 11:53:29 +02:00
|
|
|
strapi.notification.error(
|
2019-07-18 19:28:52 +02:00
|
|
|
'app.components.listPluginsPage.deletePlugin.error'
|
2019-04-16 11:53:29 +02:00
|
|
|
);
|
2017-11-09 11:25:01 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function* pluginsGet() {
|
|
|
|
|
try {
|
2018-01-04 19:04:22 +01:00
|
|
|
// Fetch plugins.
|
2018-11-06 09:56:27 +01:00
|
|
|
const response = yield all([
|
2018-03-08 10:32:01 +01:00
|
|
|
call(request, '/admin/plugins', { method: 'GET' }),
|
2018-11-06 09:56:27 +01:00
|
|
|
]);
|
2018-01-05 16:19:53 +01:00
|
|
|
const locale = yield select(selectLocale());
|
2020-02-28 11:40:55 +01:00
|
|
|
console.log({ response });
|
2018-01-04 19:04:22 +01:00
|
|
|
const opts = {
|
|
|
|
|
method: 'GET',
|
|
|
|
|
headers: {
|
|
|
|
|
'Content-Type': 'application/json',
|
|
|
|
|
},
|
2018-01-05 16:19:53 +01:00
|
|
|
params: {
|
|
|
|
|
lang: locale,
|
|
|
|
|
},
|
2018-01-04 19:04:22 +01:00
|
|
|
};
|
|
|
|
|
|
2018-07-24 19:37:27 +02:00
|
|
|
let availablePlugins;
|
|
|
|
|
|
|
|
|
|
try {
|
2019-07-05 03:05:36 +02:00
|
|
|
// Fetch plugins information.
|
2019-04-16 11:53:29 +02:00
|
|
|
availablePlugins = yield call(
|
|
|
|
|
request,
|
|
|
|
|
'https://marketplace.strapi.io/plugins',
|
2019-07-18 19:28:52 +02:00
|
|
|
opts
|
2019-04-16 11:53:29 +02:00
|
|
|
);
|
2018-07-24 19:37:27 +02:00
|
|
|
} catch (e) {
|
|
|
|
|
availablePlugins = [];
|
|
|
|
|
}
|
2018-01-04 19:04:22 +01:00
|
|
|
|
|
|
|
|
// Add logo URL to object.
|
2018-03-08 10:32:01 +01:00
|
|
|
Object.keys(response[0].plugins).map(name => {
|
2019-04-16 11:53:29 +02:00
|
|
|
response[0].plugins[name].logo = get(
|
|
|
|
|
availablePlugins.find(plugin => plugin.id === name),
|
|
|
|
|
'logo',
|
2019-07-18 19:28:52 +02:00
|
|
|
''
|
2019-04-16 11:53:29 +02:00
|
|
|
);
|
2018-01-04 19:04:22 +01:00
|
|
|
});
|
|
|
|
|
|
2018-03-08 10:32:01 +01:00
|
|
|
yield put(getPluginsSucceeded(response[0]));
|
2019-04-16 11:53:29 +02:00
|
|
|
} catch (err) {
|
2017-12-07 13:17:39 +01:00
|
|
|
strapi.notification.error('notification.error');
|
2017-11-02 16:49:10 +01:00
|
|
|
}
|
|
|
|
|
}
|
2018-01-04 19:04:22 +01:00
|
|
|
|
2017-11-02 11:36:38 +01:00
|
|
|
// Individual exports for testing
|
|
|
|
|
export default function* defaultSaga() {
|
2017-11-02 16:49:10 +01:00
|
|
|
yield fork(takeLatest, ON_DELETE_PLUGIN_CONFIRM, deletePlugin);
|
2019-04-16 12:54:16 +02:00
|
|
|
yield fork(takeLatest, GET_PLUGINS, pluginsGet);
|
2017-11-02 11:36:38 +01:00
|
|
|
}
|