REFACTOR: Move upload utilities to their own file

This commit is contained in:
Robin Ward
2019-11-14 11:56:12 -05:00
parent c83ae9a79f
commit d4b7c028fa
9 changed files with 546 additions and 528 deletions
@@ -2,7 +2,7 @@ import discourseComputed from "discourse-common/utils/decorators";
import Controller from "@ember/controller";
import ModalFunctionality from "discourse/mixins/modal-functionality";
import { ajax } from "discourse/lib/ajax";
import { allowsImages } from "discourse/lib/utilities";
import { allowsImages } from "discourse/lib/uploads";
import { popupAjaxError } from "discourse/lib/ajax-error";
export default Controller.extend(ModalFunctionality, {
@@ -42,7 +42,10 @@ export default Controller.extend(ModalFunctionality, {
@discourseComputed()
allowAvatarUpload() {
return this.siteSettings.allow_uploaded_avatars && allowsImages();
return (
this.siteSettings.allow_uploaded_avatars &&
allowsImages(this.currentUser.staff)
);
},
actions: {
@@ -14,12 +14,11 @@ import {
on
} from "discourse-common/utils/decorators";
import { getOwner } from "discourse-common/lib/get-owner";
import { escapeExpression, safariHacksDisabled } from "discourse/lib/utilities";
import {
escapeExpression,
uploadIcon,
authorizesOneOrMoreExtensions,
safariHacksDisabled
} from "discourse/lib/utilities";
uploadIcon
} from "discourse/lib/uploads";
import { emojiUnescape } from "discourse/lib/text";
import { shortDate } from "discourse/lib/formatter";
import { SAVE_LABELS, SAVE_ICONS } from "discourse/models/composer";
@@ -322,11 +321,13 @@ export default Controller.extend({
@discourseComputed
allowUpload() {
return authorizesOneOrMoreExtensions();
return authorizesOneOrMoreExtensions(this.currentUser.staff);
},
@discourseComputed()
uploadIcon: () => uploadIcon(),
uploadIcon() {
return uploadIcon(this.currentUser.staff);
},
actions: {
togglePreview() {
@@ -7,13 +7,13 @@ import {
} from "discourse-common/utils/decorators";
import {
allowsAttachments,
authorizesAllExtensions,
authorizedExtensions,
authorizesAllExtensions,
uploadIcon
} from "discourse/lib/utilities";
} from "discourse/lib/uploads";
function uploadTranslate(key) {
if (allowsAttachments()) {
function uploadTranslate(key, user) {
if (allowsAttachments(user.staff)) {
key += "_with_attachments";
}
return `upload_selector.${key}`;
@@ -28,17 +28,23 @@ export default Controller.extend(ModalFunctionality, {
selection: "local",
@discourseComputed()
uploadIcon: () => uploadIcon(),
uploadIcon() {
return uploadIcon(this.currentUser.staff);
},
@discourseComputed()
title: () => uploadTranslate("title"),
title() {
return uploadTranslate("title", this.currentUser);
},
@discourseComputed("selection")
tip(selection) {
const authorized_extensions = authorizesAllExtensions()
const authorized_extensions = authorizesAllExtensions(
this.currentUser.staff
)
? ""
: `(${authorizedExtensions()})`;
return I18n.t(uploadTranslate(`${selection}_tip`), {
: `(${authorizedExtensions(this.currentUser.staff)})`;
return I18n.t(uploadTranslate(`${selection}_tip`, this.currentUser), {
authorized_extensions
});
},