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:
soupette 2019-05-24 16:02:44 +02:00 committed by Alexandre Bodin
parent 42e0bf8fed
commit 5a087173a7
10 changed files with 110 additions and 50 deletions

View File

@ -10,7 +10,7 @@ import cn from 'classnames';
import { isEmpty, replace } from 'lodash'; import { isEmpty, replace } from 'lodash';
import { FormattedMessage } from 'react-intl'; import { FormattedMessage } from 'react-intl';
import { Button } from 'strapi-helper-plugin'; import { Button, PopUpWarning } from 'strapi-helper-plugin';
import InstallPluginPopup from '../InstallPluginPopup'; import InstallPluginPopup from '../InstallPluginPopup';
import styles from './styles.scss'; import styles from './styles.scss';
@ -21,6 +21,8 @@ const PLUGINS_WITH_CONFIG = ['content-manager', 'email', 'upload'];
class PluginCard extends React.Component { class PluginCard extends React.Component {
state = { state = {
boostrapCol: 'col-lg-4', boostrapCol: 'col-lg-4',
showModalAutoReload: false,
showModalEnv: false,
}; };
componentDidMount() { componentDidMount() {
@ -73,15 +75,23 @@ class PluginCard extends React.Component {
}; };
handleDownloadPlugin = e => { handleDownloadPlugin = e => {
if ( const {
!this.props.isAlreadyInstalled && autoReload,
this.props.plugin.id !== 'support-us' currentEnvironment,
) { downloadPlugin,
this.props.downloadPlugin(e); history: { push },
} else if (this.props.plugin.id === 'support-us') { isAlreadyInstalled,
this.aTag.click(); plugin: { id },
} = this.props;
if (!autoReload) {
this.setState({ showModalAutoReload: true });
} else if (currentEnvironment === 'development') {
this.setState({ showModalEnv: true });
} else if (!isAlreadyInstalled) {
downloadPlugin(e);
} else { } else {
this.props.history.push('/list-plugins'); push('/list-plugins');
} }
}; };
@ -200,6 +210,34 @@ class PluginCard extends React.Component {
} }
plugin={this.props.plugin} 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> </div>
); );
} }

View File

@ -33,38 +33,39 @@ class Row extends React.Component {
}; };
render() { render() {
// const uploadPath = `/plugins/upload/configurations/${this.context.currentEnvironment}`;
// Make sure to match the ctm config URI instead of content-type view URI // 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 = const settingsPath =
this.props.name === 'content-manager' name === 'content-manager'
? '/plugins/content-manager/ctm-configurations' ? '/plugins/content-manager/ctm-configurations'
: `/plugins/${this.props.name}/configurations/${ : `/plugins/${name}/configurations/${currentEnvironment}`;
this.context.currentEnvironment
}`; const icons = [];
// const icons = this.props.name === 'upload' || this.props.name === 'email' ? [
const icons = includes(PLUGINS_WITH_CONFIG, this.props.name) if (PLUGINS_WITH_CONFIG.includes(name)) {
? [ icons.push({
{
icoType: 'cog', icoType: 'cog',
onClick: e => { onClick: e => {
e.preventDefault(); e.preventDefault();
e.stopPropagation(); e.stopPropagation();
this.props.history.push(settingsPath); push(settingsPath);
}, },
}, });
{ }
if (!required && currentEnvironment === 'development') {
icons.push({
icoType: 'trash', icoType: 'trash',
id: this.props.name, id: name,
onClick: this.handleClick, onClick: this.handleClick,
}, });
] }
: [
{
icoType: 'trash',
id: this.props.name,
onClick: this.handleClick,
},
];
return ( return (
<ListRow> <ListRow>

View File

@ -55,7 +55,7 @@ class Marketplace extends React.Component {
renderPluginCard = plugin => { renderPluginCard = plugin => {
const { const {
admin: { currentEnvironment }, admin: { autoReload, currentEnvironment },
availablePlugins, availablePlugins,
downloadPlugin, downloadPlugin,
history, history,
@ -65,6 +65,7 @@ class Marketplace extends React.Component {
return ( return (
<PluginCard <PluginCard
autoReload={autoReload}
currentEnvironment={currentEnvironment} currentEnvironment={currentEnvironment}
history={history} history={history}
key={currentPlugin.id} key={currentPlugin.id}

View File

@ -93,6 +93,10 @@
"app.components.PluginCard.compatible": "Compatible with your app", "app.components.PluginCard.compatible": "Compatible with your app",
"app.components.PluginCard.compatibleCommunity": "Compatible with the community", "app.components.PluginCard.compatibleCommunity": "Compatible with the community",
"app.components.PluginCard.more-details": "More details", "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.price.free": "Free",
"app.components.PluginCard.settings": "Settings", "app.components.PluginCard.settings": "Settings",
"app.components.listPlugins.button": "Add New Plugin", "app.components.listPlugins.button": "Add New Plugin",

View File

@ -93,6 +93,10 @@
"app.components.PluginCard.compatible": "Compatible avec votre app", "app.components.PluginCard.compatible": "Compatible avec votre app",
"app.components.PluginCard.compatibleCommunity": "Compatible avec la communauté", "app.components.PluginCard.compatibleCommunity": "Compatible avec la communauté",
"app.components.PluginCard.more-details": "Plus de détails", "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.price.free": "Gratuit",
"app.components.PluginCard.settings": "Réglages", "app.components.PluginCard.settings": "Réglages",
"app.components.listPlugins.button": "Ajouter un Nouveau Plugin", "app.components.listPlugins.button": "Ajouter un Nouveau Plugin",

View File

@ -8,7 +8,7 @@
}, },
"scripts": { "scripts": {
"test": "echo \"no tests yet\"", "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", "main": "index.js",
"dependencies": { "dependencies": {

View File

@ -20,7 +20,10 @@ function parseJSON(response) {
* @return {object|undefined} Returns either the response, or throws an error * @return {object|undefined} Returns either the response, or throws an error
*/ */
function checkStatus(response, checkToken = true) { 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; return response;
} }
@ -46,7 +49,7 @@ function checkTokenValidity(response) {
}; };
if (auth.getToken()) { if (auth.getToken()) {
return fetch(`${strapi.backendURL}/user/me`, options).then(() => { return fetch(`${strapi.backendURL}/users/me`, options).then(() => {
if (response.status === 401) { if (response.status === 401) {
window.location = `${ window.location = `${
strapi.remoteURL strapi.remoteURL
@ -109,7 +112,13 @@ function serverRestartWatcher(response) {
* @return {object} The response data * @return {object} The response data
*/ */
export default function request(...args) { export default function request(...args) {
let [url, options = {}, shouldWatchServerRestart, stringify = true, ...rest] = args; let [
url,
options = {},
shouldWatchServerRestart,
stringify = true,
...rest
] = args;
let noAuth; let noAuth;
try { try {

View File

@ -5,7 +5,8 @@
"strapi": { "strapi": {
"name": "Content Manager", "name": "Content Manager",
"icon": "plug", "icon": "plug",
"description": "content-manager.plugin.description" "description": "content-manager.plugin.description",
"required": true
}, },
"scripts": { "scripts": {
"test": "echo \"no tests yet\"" "test": "echo \"no tests yet\""

View File

@ -5,7 +5,8 @@
"strapi": { "strapi": {
"name": "Email", "name": "Email",
"icon": "paper-plane", "icon": "paper-plane",
"description": "email.plugin.description" "description": "email.plugin.description",
"required": true
}, },
"scripts": { "scripts": {
"test": "echo \"no tests yet\"" "test": "echo \"no tests yet\""

View File

@ -5,7 +5,8 @@
"strapi": { "strapi": {
"name": "Roles & Permissions", "name": "Roles & Permissions",
"icon": "users", "icon": "users",
"description": "users-permissions.plugin.description" "description": "users-permissions.plugin.description",
"required": true
}, },
"scripts": { "scripts": {
"test": "echo \"no tests yet\"" "test": "echo \"no tests yet\""