mirror of
https://github.com/discourse/discourse.git
synced 2025-05-28 11:41:45 +08:00
FEATURE: Warn admins when installing a theme that's already installed (#11651)
Installing multiple copies of the same theme/component is possible, but you rarely need to actually have multiple copies installed. We've seen many times new admins installing duplicates of components because they were unaware it was already installed. This PR makes the theme installer modal loop through the existing themes when you click on 'install', and if there is a theme with a URL that matches the URL you entered, a warning will show up and you will need to click 'install' again to proceed.
This commit is contained in:
@ -125,6 +125,19 @@ export default Controller.extend(ModalFunctionality, {
|
||||
return privateChecked && checkPrivate && publicKey;
|
||||
},
|
||||
|
||||
onClose() {
|
||||
this.set("duplicateRemoteThemeWarning", null);
|
||||
},
|
||||
|
||||
themeHasSameUrl(theme, url) {
|
||||
const themeUrl = theme.remote_theme && theme.remote_theme.remote_url;
|
||||
return (
|
||||
themeUrl &&
|
||||
url &&
|
||||
url.replace(/\.git$/, "") === themeUrl.replace(/\.git$/, "")
|
||||
);
|
||||
},
|
||||
|
||||
actions: {
|
||||
uploadLocaleFile() {
|
||||
this.set("localFile", $("#file-input")[0].files[0]);
|
||||
@ -167,6 +180,17 @@ export default Controller.extend(ModalFunctionality, {
|
||||
}
|
||||
|
||||
if (this.remote || this.popular) {
|
||||
const duplicate = this.themesController.model.content.find((theme) =>
|
||||
this.themeHasSameUrl(theme, this.uploadUrl)
|
||||
);
|
||||
if (duplicate && !this.duplicateRemoteThemeWarning) {
|
||||
const warning = I18n.t(
|
||||
"admin.customize.theme.duplicate_remote_theme",
|
||||
{ name: duplicate.name }
|
||||
);
|
||||
this.set("duplicateRemoteThemeWarning", warning);
|
||||
return;
|
||||
}
|
||||
options.data = {
|
||||
remote: this.uploadUrl,
|
||||
branch: this.branch,
|
||||
|
Reference in New Issue
Block a user