mirror of
https://github.com/strapi/strapi.git
synced 2025-11-02 02:44:55 +00:00
Prevent the users from uninstalling a core plugin.
Prevent the user from adding/removing a plugin with the UI if the env is not development
This commit is contained in:
parent
42e0bf8fed
commit
5a087173a7
@ -10,7 +10,7 @@ import cn from 'classnames';
|
||||
import { isEmpty, replace } from 'lodash';
|
||||
import { FormattedMessage } from 'react-intl';
|
||||
|
||||
import { Button } from 'strapi-helper-plugin';
|
||||
import { Button, PopUpWarning } from 'strapi-helper-plugin';
|
||||
import InstallPluginPopup from '../InstallPluginPopup';
|
||||
|
||||
import styles from './styles.scss';
|
||||
@ -21,6 +21,8 @@ const PLUGINS_WITH_CONFIG = ['content-manager', 'email', 'upload'];
|
||||
class PluginCard extends React.Component {
|
||||
state = {
|
||||
boostrapCol: 'col-lg-4',
|
||||
showModalAutoReload: false,
|
||||
showModalEnv: false,
|
||||
};
|
||||
|
||||
componentDidMount() {
|
||||
@ -63,8 +65,8 @@ class PluginCard extends React.Component {
|
||||
this.props.plugin.id === 'content-manager'
|
||||
? '/plugins/content-manager/ctm-configurations'
|
||||
: `/plugins/${this.props.plugin.id}/configurations/${
|
||||
this.props.currentEnvironment
|
||||
}`;
|
||||
this.props.currentEnvironment
|
||||
}`;
|
||||
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
@ -73,15 +75,23 @@ class PluginCard extends React.Component {
|
||||
};
|
||||
|
||||
handleDownloadPlugin = e => {
|
||||
if (
|
||||
!this.props.isAlreadyInstalled &&
|
||||
this.props.plugin.id !== 'support-us'
|
||||
) {
|
||||
this.props.downloadPlugin(e);
|
||||
} else if (this.props.plugin.id === 'support-us') {
|
||||
this.aTag.click();
|
||||
const {
|
||||
autoReload,
|
||||
currentEnvironment,
|
||||
downloadPlugin,
|
||||
history: { push },
|
||||
isAlreadyInstalled,
|
||||
plugin: { id },
|
||||
} = this.props;
|
||||
|
||||
if (!autoReload) {
|
||||
this.setState({ showModalAutoReload: true });
|
||||
} else if (currentEnvironment === 'development') {
|
||||
this.setState({ showModalEnv: true });
|
||||
} else if (!isAlreadyInstalled) {
|
||||
downloadPlugin(e);
|
||||
} else {
|
||||
this.props.history.push('/list-plugins');
|
||||
push('/list-plugins');
|
||||
}
|
||||
};
|
||||
|
||||
@ -200,6 +210,34 @@ class PluginCard extends React.Component {
|
||||
}
|
||||
plugin={this.props.plugin}
|
||||
/>
|
||||
<PopUpWarning
|
||||
content={{
|
||||
message:
|
||||
'app.components.PluginCard.PopUpWarning.install.impossible.autoReload.needed',
|
||||
title:
|
||||
'app.components.PluginCard.PopUpWarning.install.impossible.title',
|
||||
confirm:
|
||||
'app.components.PluginCard.PopUpWarning.install.impossible.confirm',
|
||||
}}
|
||||
isOpen={this.state.showModalAutoReload}
|
||||
onlyConfirmButton
|
||||
onConfirm={() => this.setState({ showModalAutoReload: false })}
|
||||
popUpWarningType="warning"
|
||||
/>
|
||||
<PopUpWarning
|
||||
content={{
|
||||
message:
|
||||
'app.components.PluginCard.PopUpWarning.install.impossible.environment',
|
||||
title:
|
||||
'app.components.PluginCard.PopUpWarning.install.impossible.title',
|
||||
confirm:
|
||||
'app.components.PluginCard.PopUpWarning.install.impossible.confirm',
|
||||
}}
|
||||
isOpen={this.state.showModalEnv}
|
||||
onlyConfirmButton
|
||||
onConfirm={() => this.setState({ showModalEnv: false })}
|
||||
popUpWarningType="warning"
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@ -33,38 +33,39 @@ class Row extends React.Component {
|
||||
};
|
||||
|
||||
render() {
|
||||
// const uploadPath = `/plugins/upload/configurations/${this.context.currentEnvironment}`;
|
||||
// Make sure to match the ctm config URI instead of content-type view URI
|
||||
const {
|
||||
history: { push },
|
||||
name,
|
||||
plugin: { required },
|
||||
} = this.props;
|
||||
const { currentEnvironment } = this.context;
|
||||
|
||||
const settingsPath =
|
||||
this.props.name === 'content-manager'
|
||||
name === 'content-manager'
|
||||
? '/plugins/content-manager/ctm-configurations'
|
||||
: `/plugins/${this.props.name}/configurations/${
|
||||
this.context.currentEnvironment
|
||||
}`;
|
||||
// const icons = this.props.name === 'upload' || this.props.name === 'email' ? [
|
||||
const icons = includes(PLUGINS_WITH_CONFIG, this.props.name)
|
||||
? [
|
||||
{
|
||||
icoType: 'cog',
|
||||
onClick: e => {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
this.props.history.push(settingsPath);
|
||||
},
|
||||
: `/plugins/${name}/configurations/${currentEnvironment}`;
|
||||
|
||||
const icons = [];
|
||||
|
||||
if (PLUGINS_WITH_CONFIG.includes(name)) {
|
||||
icons.push({
|
||||
icoType: 'cog',
|
||||
onClick: e => {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
push(settingsPath);
|
||||
},
|
||||
{
|
||||
icoType: 'trash',
|
||||
id: this.props.name,
|
||||
onClick: this.handleClick,
|
||||
},
|
||||
]
|
||||
: [
|
||||
{
|
||||
icoType: 'trash',
|
||||
id: this.props.name,
|
||||
onClick: this.handleClick,
|
||||
},
|
||||
];
|
||||
});
|
||||
}
|
||||
|
||||
if (!required && currentEnvironment === 'development') {
|
||||
icons.push({
|
||||
icoType: 'trash',
|
||||
id: name,
|
||||
onClick: this.handleClick,
|
||||
});
|
||||
}
|
||||
|
||||
return (
|
||||
<ListRow>
|
||||
|
||||
@ -55,7 +55,7 @@ class Marketplace extends React.Component {
|
||||
|
||||
renderPluginCard = plugin => {
|
||||
const {
|
||||
admin: { currentEnvironment },
|
||||
admin: { autoReload, currentEnvironment },
|
||||
availablePlugins,
|
||||
downloadPlugin,
|
||||
history,
|
||||
@ -65,6 +65,7 @@ class Marketplace extends React.Component {
|
||||
|
||||
return (
|
||||
<PluginCard
|
||||
autoReload={autoReload}
|
||||
currentEnvironment={currentEnvironment}
|
||||
history={history}
|
||||
key={currentPlugin.id}
|
||||
|
||||
@ -93,6 +93,10 @@
|
||||
"app.components.PluginCard.compatible": "Compatible with your app",
|
||||
"app.components.PluginCard.compatibleCommunity": "Compatible with the community",
|
||||
"app.components.PluginCard.more-details": "More details",
|
||||
"app.components.PluginCard.PopUpWarning.install.impossible.autoReload.needed": "The autoReload feature needs to be unabled. Please start you app with `yarn develop`.",
|
||||
"app.components.PluginCard.PopUpWarning.install.impossible.environment": "For security reasons, a plugin can only be downloaded in a development environment.",
|
||||
"app.components.PluginCard.PopUpWarning.install.impossible.confirm": "I understand!",
|
||||
"app.components.PluginCard.PopUpWarning.install.impossible.title": "Downloading is impossible",
|
||||
"app.components.PluginCard.price.free": "Free",
|
||||
"app.components.PluginCard.settings": "Settings",
|
||||
"app.components.listPlugins.button": "Add New Plugin",
|
||||
|
||||
@ -93,6 +93,10 @@
|
||||
"app.components.PluginCard.compatible": "Compatible avec votre app",
|
||||
"app.components.PluginCard.compatibleCommunity": "Compatible avec la communauté",
|
||||
"app.components.PluginCard.more-details": "Plus de détails",
|
||||
"app.components.PluginCard.PopUpWarning.install.impossible.autoReload.needed": "La configuration d'autoReload a besoin d'être activée pour télécharger un plugin. Veuillez démarrer votre application avec `yarn develop`.",
|
||||
"app.components.PluginCard.PopUpWarning.install.impossible.environment": "Pour des raisoins de sécurité, un plugin ne peut être installé qu'en dévelopment.",
|
||||
"app.components.PluginCard.PopUpWarning.install.impossible.confirm": "J'ai compris!",
|
||||
"app.components.PluginCard.PopUpWarning.install.impossible.title": "Le téléchargement est impossible",
|
||||
"app.components.PluginCard.price.free": "Gratuit",
|
||||
"app.components.PluginCard.settings": "Réglages",
|
||||
"app.components.listPlugins.button": "Ajouter un Nouveau Plugin",
|
||||
@ -150,4 +154,4 @@
|
||||
"notification.error.layout": "Impossible de récupérer le layout de l'admin",
|
||||
"request.error.model.unknown": "Le model n'existe pas",
|
||||
"app.utils.delete": "Supprimer"
|
||||
}
|
||||
}
|
||||
|
||||
@ -8,7 +8,7 @@
|
||||
},
|
||||
"scripts": {
|
||||
"test": "echo \"no tests yet\"",
|
||||
"dev": "webpack-dev-server --config webpack.config.dev.js"
|
||||
"develop": "webpack-dev-server --config webpack.config.dev.js"
|
||||
},
|
||||
"main": "index.js",
|
||||
"dependencies": {
|
||||
|
||||
@ -20,7 +20,10 @@ function parseJSON(response) {
|
||||
* @return {object|undefined} Returns either the response, or throws an error
|
||||
*/
|
||||
function checkStatus(response, checkToken = true) {
|
||||
if ((response.status >= 200 && response.status < 300) || response.status === 0) {
|
||||
if (
|
||||
(response.status >= 200 && response.status < 300) ||
|
||||
response.status === 0
|
||||
) {
|
||||
return response;
|
||||
}
|
||||
|
||||
@ -46,7 +49,7 @@ function checkTokenValidity(response) {
|
||||
};
|
||||
|
||||
if (auth.getToken()) {
|
||||
return fetch(`${strapi.backendURL}/user/me`, options).then(() => {
|
||||
return fetch(`${strapi.backendURL}/users/me`, options).then(() => {
|
||||
if (response.status === 401) {
|
||||
window.location = `${
|
||||
strapi.remoteURL
|
||||
@ -109,12 +112,18 @@ function serverRestartWatcher(response) {
|
||||
* @return {object} The response data
|
||||
*/
|
||||
export default function request(...args) {
|
||||
let [url, options = {}, shouldWatchServerRestart, stringify = true, ...rest] = args;
|
||||
let [
|
||||
url,
|
||||
options = {},
|
||||
shouldWatchServerRestart,
|
||||
stringify = true,
|
||||
...rest
|
||||
] = args;
|
||||
let noAuth;
|
||||
|
||||
try {
|
||||
[{ noAuth }] = rest;
|
||||
} catch(err) {
|
||||
} catch (err) {
|
||||
noAuth = false;
|
||||
}
|
||||
|
||||
@ -154,7 +163,7 @@ export default function request(...args) {
|
||||
if (options && options.body && stringify) {
|
||||
options.body = JSON.stringify(options.body);
|
||||
}
|
||||
|
||||
|
||||
return fetch(url, options)
|
||||
.then(checkStatus)
|
||||
.then(parseJSON)
|
||||
|
||||
@ -5,7 +5,8 @@
|
||||
"strapi": {
|
||||
"name": "Content Manager",
|
||||
"icon": "plug",
|
||||
"description": "content-manager.plugin.description"
|
||||
"description": "content-manager.plugin.description",
|
||||
"required": true
|
||||
},
|
||||
"scripts": {
|
||||
"test": "echo \"no tests yet\""
|
||||
|
||||
@ -5,7 +5,8 @@
|
||||
"strapi": {
|
||||
"name": "Email",
|
||||
"icon": "paper-plane",
|
||||
"description": "email.plugin.description"
|
||||
"description": "email.plugin.description",
|
||||
"required": true
|
||||
},
|
||||
"scripts": {
|
||||
"test": "echo \"no tests yet\""
|
||||
|
||||
@ -5,7 +5,8 @@
|
||||
"strapi": {
|
||||
"name": "Roles & Permissions",
|
||||
"icon": "users",
|
||||
"description": "users-permissions.plugin.description"
|
||||
"description": "users-permissions.plugin.description",
|
||||
"required": true
|
||||
},
|
||||
"scripts": {
|
||||
"test": "echo \"no tests yet\""
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user