mirror of
https://github.com/discourse/discourse.git
synced 2025-02-16 18:24:52 -06:00
FIX: Missing User objects in Utilities
This commit is contained in:
parent
f5ed0dc2e6
commit
bc2067898e
@ -1,6 +1,5 @@
|
||||
import { escape } from "pretty-text/sanitizer";
|
||||
import toMarkdown from "discourse/lib/to-markdown";
|
||||
import User from "discourse/models/user";
|
||||
|
||||
const homepageSelector = "meta[name=discourse_current_homepage]";
|
||||
|
||||
@ -239,7 +238,7 @@ export function validateUploadedFile(file, opts) {
|
||||
|
||||
// check that the uploaded file is authorized
|
||||
if (opts.allowStaffToUploadAnyFileInPm && opts.isPrivateMessage) {
|
||||
if (User.currentProp("staff")) {
|
||||
if (Discourse.User.currentProp("staff")) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@ -271,7 +270,7 @@ export function validateUploadedFile(file, opts) {
|
||||
|
||||
if (!opts.bypassNewUserRestriction) {
|
||||
// ensures that new users can upload a file
|
||||
if (!User.current().isAllowedToUploadAFile(opts.type)) {
|
||||
if (!Discourse.User.current().isAllowedToUploadAFile(opts.type)) {
|
||||
bootbox.alert(
|
||||
I18n.t(`post.errors.${opts.type}_upload_not_allowed_for_new_user`)
|
||||
);
|
||||
@ -305,7 +304,7 @@ function staffExtensions() {
|
||||
|
||||
function imagesExtensions() {
|
||||
let exts = extensions().filter(ext => IMAGES_EXTENSIONS_REGEX.test(ext));
|
||||
if (User.currentProp("staff")) {
|
||||
if (Discourse.User.currentProp("staff")) {
|
||||
const staffExts = staffExtensions().filter(ext =>
|
||||
IMAGES_EXTENSIONS_REGEX.test(ext)
|
||||
);
|
||||
@ -327,7 +326,10 @@ function staffExtensionsRegex() {
|
||||
}
|
||||
|
||||
function isAuthorizedFile(fileName) {
|
||||
if (User.currentProp("staff") && staffExtensionsRegex().test(fileName)) {
|
||||
if (
|
||||
Discourse.User.currentProp("staff") &&
|
||||
staffExtensionsRegex().test(fileName)
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
return extensionsRegex().test(fileName);
|
||||
@ -338,7 +340,7 @@ function isAuthorizedImage(fileName) {
|
||||
}
|
||||
|
||||
export function authorizedExtensions() {
|
||||
const exts = User.currentProp("staff")
|
||||
const exts = Discourse.User.currentProp("staff")
|
||||
? [...extensions(), ...staffExtensions()]
|
||||
: extensions();
|
||||
return exts.filter(ext => ext.length > 0).join(", ");
|
||||
@ -354,7 +356,7 @@ export function authorizesAllExtensions() {
|
||||
return (
|
||||
Discourse.SiteSettings.authorized_extensions.indexOf("*") >= 0 ||
|
||||
(Discourse.SiteSettings.authorized_extensions_for_staff.indexOf("*") >= 0 &&
|
||||
User.currentProp("staff"))
|
||||
Discourse.User.currentProp("staff"))
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -3,6 +3,7 @@ import { next } from "@ember/runloop";
|
||||
import Topic from "discourse/models/topic";
|
||||
import PostStream from "discourse/models/post-stream";
|
||||
import { Placeholder } from "discourse/lib/posts-with-placeholders";
|
||||
import User from "discourse/models/user";
|
||||
|
||||
moduleFor("controller:topic", "controller:topic", {
|
||||
needs: [
|
||||
@ -223,7 +224,7 @@ QUnit.test("canDeleteSelected", function(assert) {
|
||||
],
|
||||
stream: [1, 2, 3]
|
||||
};
|
||||
const currentUser = Discourse.User.create({ admin: false });
|
||||
const currentUser = User.create({ admin: false });
|
||||
this.registry.register("current-user:main", currentUser, {
|
||||
instantiate: false
|
||||
});
|
||||
@ -316,7 +317,7 @@ QUnit.test("Can split/merge topic", function(assert) {
|
||||
});
|
||||
|
||||
QUnit.test("canChangeOwner", function(assert) {
|
||||
const currentUser = Discourse.User.create({ admin: false });
|
||||
const currentUser = User.create({ admin: false });
|
||||
this.registry.register("current-user:main", currentUser, {
|
||||
instantiate: false
|
||||
});
|
||||
|
@ -2,6 +2,7 @@ import EmberObject from "@ember/object";
|
||||
import createStore from "helpers/create-store";
|
||||
import { autoLoadModules } from "discourse/initializers/auto-load-modules";
|
||||
import TopicTrackingState from "discourse/models/topic-tracking-state";
|
||||
import User from "discourse/models/user";
|
||||
|
||||
export default function(name, opts) {
|
||||
opts = opts || {};
|
||||
@ -29,7 +30,7 @@ export default function(name, opts) {
|
||||
|
||||
const store = createStore();
|
||||
if (!opts.anonymous) {
|
||||
const currentUser = Discourse.User.create({ username: "eviltrout" });
|
||||
const currentUser = User.create({ username: "eviltrout" });
|
||||
this.currentUser = currentUser;
|
||||
this.registry.register("current-user:main", this.currentUser, {
|
||||
instantiate: false
|
||||
|
@ -1,6 +1,7 @@
|
||||
import DiscourseURL from "discourse/lib/url";
|
||||
import ClickTrack from "discourse/lib/click-track";
|
||||
import { fixture, logIn } from "helpers/qunit-helpers";
|
||||
import User from "discourse/models/user";
|
||||
|
||||
QUnit.module("lib:click-track-edit-history", {
|
||||
beforeEach() {
|
||||
@ -93,7 +94,7 @@ QUnit.skip(
|
||||
"tracks external URLs when opening in another window",
|
||||
async assert => {
|
||||
assert.expect(3);
|
||||
Discourse.User.currentProp("external_links_in_new_tab", true);
|
||||
User.currentProp("external_links_in_new_tab", true);
|
||||
|
||||
const done = assert.async();
|
||||
/* global server */
|
||||
|
@ -2,6 +2,7 @@ import { later } from "@ember/runloop";
|
||||
import DiscourseURL from "discourse/lib/url";
|
||||
import ClickTrack from "discourse/lib/click-track";
|
||||
import { fixture, logIn } from "helpers/qunit-helpers";
|
||||
import User from "discourse/models/user";
|
||||
|
||||
QUnit.module("lib:click-track", {
|
||||
beforeEach() {
|
||||
@ -104,7 +105,7 @@ QUnit.skip(
|
||||
"tracks external URLs when opening in another window",
|
||||
async assert => {
|
||||
assert.expect(3);
|
||||
Discourse.User.currentProp("external_links_in_new_tab", true);
|
||||
User.currentProp("external_links_in_new_tab", true);
|
||||
|
||||
const done = assert.async();
|
||||
/* global server */
|
||||
@ -140,7 +141,7 @@ QUnit.skip("does not track right clicks inside quotes", async assert => {
|
||||
});
|
||||
|
||||
QUnit.skip("does not track clicks links in quotes", async assert => {
|
||||
Discourse.User.currentProp("external_links_in_new_tab", true);
|
||||
User.currentProp("external_links_in_new_tab", true);
|
||||
assert.notOk(track(generateClickEventOn(".quote a:last-child")));
|
||||
assert.ok(window.open.calledWith("https://google.com", "_blank"));
|
||||
});
|
||||
@ -154,7 +155,7 @@ QUnit.skip("does not track clicks on mailto", async assert => {
|
||||
});
|
||||
|
||||
QUnit.skip("removes the href and put it as a data attribute", async assert => {
|
||||
Discourse.User.currentProp("external_links_in_new_tab", true);
|
||||
User.currentProp("external_links_in_new_tab", true);
|
||||
|
||||
assert.notOk(track(generateClickEventOn("a")));
|
||||
|
||||
@ -188,7 +189,7 @@ function badgeClickCount(assert, id, expected) {
|
||||
|
||||
QUnit.skip("does not update badge clicks on my own link", async assert => {
|
||||
sandbox
|
||||
.stub(Discourse.User, "currentProp")
|
||||
.stub(User, "currentProp")
|
||||
.withArgs("id")
|
||||
.returns(314);
|
||||
badgeClickCount(assert, "with-badge", 1);
|
||||
@ -196,7 +197,7 @@ QUnit.skip("does not update badge clicks on my own link", async assert => {
|
||||
|
||||
QUnit.skip("does not update badge clicks in my own post", async assert => {
|
||||
sandbox
|
||||
.stub(Discourse.User, "currentProp")
|
||||
.stub(User, "currentProp")
|
||||
.withArgs("id")
|
||||
.returns(3141);
|
||||
badgeClickCount(assert, "with-badge-but-not-mine", 1);
|
||||
|
@ -17,6 +17,7 @@ import {
|
||||
setCaretPosition,
|
||||
fillMissingDates
|
||||
} from "discourse/lib/utilities";
|
||||
import User from "discourse/models/user";
|
||||
import * as Utilities from "discourse/lib/utilities";
|
||||
|
||||
QUnit.module("lib:utilities");
|
||||
@ -72,7 +73,7 @@ QUnit.test("uploading one file", assert => {
|
||||
|
||||
QUnit.test("new user cannot upload images", assert => {
|
||||
Discourse.SiteSettings.newuser_max_images = 0;
|
||||
Discourse.User.resetCurrent(Discourse.User.create());
|
||||
User.resetCurrent(User.create());
|
||||
sandbox.stub(bootbox, "alert");
|
||||
|
||||
assert.not(validUpload([{ name: "image.png" }]), "the upload is not valid");
|
||||
@ -87,7 +88,7 @@ QUnit.test("new user cannot upload images", assert => {
|
||||
QUnit.test("new user cannot upload attachments", assert => {
|
||||
Discourse.SiteSettings.newuser_max_attachments = 0;
|
||||
sandbox.stub(bootbox, "alert");
|
||||
Discourse.User.resetCurrent(Discourse.User.create());
|
||||
User.resetCurrent(User.create());
|
||||
|
||||
assert.not(validUpload([{ name: "roman.txt" }]));
|
||||
assert.ok(
|
||||
@ -120,7 +121,7 @@ QUnit.test("skipping validation works", assert => {
|
||||
QUnit.test("staff can upload anything in PM", assert => {
|
||||
const files = [{ name: "some.docx" }];
|
||||
Discourse.SiteSettings.authorized_extensions = "jpeg";
|
||||
Discourse.User.resetCurrent(Discourse.User.create({ moderator: true }));
|
||||
User.resetCurrent(User.create({ moderator: true }));
|
||||
|
||||
sandbox.stub(bootbox, "alert");
|
||||
|
||||
@ -151,8 +152,8 @@ var dummyBlob = function() {
|
||||
};
|
||||
|
||||
QUnit.test("allows valid uploads to go through", assert => {
|
||||
Discourse.User.resetCurrent(Discourse.User.create());
|
||||
Discourse.User.currentProp("trust_level", 1);
|
||||
User.resetCurrent(User.create());
|
||||
User.currentProp("trust_level", 1);
|
||||
sandbox.stub(bootbox, "alert");
|
||||
|
||||
// image
|
||||
|
@ -1,5 +1,6 @@
|
||||
import Post from "discourse/models/post";
|
||||
import createStore from "helpers/create-store";
|
||||
import User from "discourse/models/user";
|
||||
|
||||
QUnit.module("model:post-stream");
|
||||
|
||||
@ -549,7 +550,7 @@ QUnit.test("staging and undoing a new post", assert => {
|
||||
"the original post is lastAppended"
|
||||
);
|
||||
|
||||
const user = Discourse.User.create({
|
||||
const user = User.create({
|
||||
username: "eviltrout",
|
||||
name: "eviltrout",
|
||||
id: 321
|
||||
@ -650,7 +651,7 @@ QUnit.test("staging and committing a post", assert => {
|
||||
"the original post is lastAppended"
|
||||
);
|
||||
|
||||
const user = Discourse.User.create({
|
||||
const user = User.create({
|
||||
username: "eviltrout",
|
||||
name: "eviltrout",
|
||||
id: 321
|
||||
@ -772,7 +773,7 @@ QUnit.test("comitting and triggerNewPostInStream race condition", assert => {
|
||||
const store = postStream.store;
|
||||
|
||||
postStream.appendPost(store.createRecord("post", { id: 1, post_number: 1 }));
|
||||
const user = Discourse.User.create({
|
||||
const user = User.create({
|
||||
username: "eviltrout",
|
||||
name: "eviltrout",
|
||||
id: 321
|
||||
@ -804,8 +805,8 @@ QUnit.test("comitting and triggerNewPostInStream race condition", assert => {
|
||||
QUnit.test("triggerNewPostInStream for ignored posts", async assert => {
|
||||
const postStream = buildStream(280, [1]);
|
||||
const store = postStream.store;
|
||||
Discourse.User.resetCurrent(
|
||||
Discourse.User.create({
|
||||
User.resetCurrent(
|
||||
User.create({
|
||||
username: "eviltrout",
|
||||
name: "eviltrout",
|
||||
id: 321,
|
||||
|
@ -1,4 +1,5 @@
|
||||
import Post from "discourse/models/post";
|
||||
import User from "discourse/models/user";
|
||||
|
||||
QUnit.module("model: Post");
|
||||
|
||||
@ -56,7 +57,7 @@ QUnit.test("updateFromPost", assert => {
|
||||
});
|
||||
|
||||
QUnit.test("destroy by staff", assert => {
|
||||
var user = Discourse.User.create({ username: "staff", moderator: true }),
|
||||
var user = User.create({ username: "staff", moderator: true }),
|
||||
post = buildPost({ user: user });
|
||||
|
||||
post.destroy(user);
|
||||
@ -81,7 +82,7 @@ QUnit.test("destroy by staff", assert => {
|
||||
|
||||
QUnit.test("destroy by non-staff", assert => {
|
||||
var originalCooked = "this is the original cooked value",
|
||||
user = Discourse.User.create({ username: "evil trout" }),
|
||||
user = User.create({ username: "evil trout" }),
|
||||
post = buildPost({ user: user, cooked: originalCooked });
|
||||
|
||||
return post.destroy(user).then(() => {
|
||||
|
@ -1,3 +1,5 @@
|
||||
import User from "discourse/models/user";
|
||||
|
||||
QUnit.module("model:topic-details");
|
||||
|
||||
import Topic from "discourse/models/topic";
|
||||
@ -25,5 +27,5 @@ QUnit.test("updateFromJson", assert => {
|
||||
1,
|
||||
"it loaded the allowed users"
|
||||
);
|
||||
assert.containsInstance(details.get("allowed_users"), Discourse.User);
|
||||
assert.containsInstance(details.get("allowed_users"), User);
|
||||
});
|
||||
|
@ -2,6 +2,7 @@ import EmberObject from "@ember/object";
|
||||
import { IMAGE_VERSION as v } from "pretty-text/emoji/version";
|
||||
import Category from "discourse/models/category";
|
||||
import Topic from "discourse/models/topic";
|
||||
import User from "discourse/models/user";
|
||||
|
||||
QUnit.module("model:topic");
|
||||
|
||||
@ -108,7 +109,7 @@ QUnit.test("updateFromJson", assert => {
|
||||
});
|
||||
|
||||
QUnit.test("destroy", assert => {
|
||||
const user = Discourse.User.create({ username: "eviltrout" });
|
||||
const user = User.create({ username: "eviltrout" });
|
||||
const topic = Topic.create({ id: 1234 });
|
||||
|
||||
topic.destroy(user);
|
||||
@ -117,7 +118,7 @@ QUnit.test("destroy", assert => {
|
||||
});
|
||||
|
||||
QUnit.test("recover", assert => {
|
||||
const user = Discourse.User.create({ username: "eviltrout" });
|
||||
const user = User.create({ username: "eviltrout" });
|
||||
const topic = Topic.create({
|
||||
id: 1234,
|
||||
deleted_at: new Date(),
|
||||
|
@ -1,10 +1,11 @@
|
||||
import UserDraft from "discourse/models/user-draft";
|
||||
import { NEW_TOPIC_KEY } from "discourse/models/composer";
|
||||
import User from "discourse/models/user";
|
||||
|
||||
QUnit.module("model:user-drafts");
|
||||
|
||||
QUnit.test("stream", assert => {
|
||||
const user = Discourse.User.create({ id: 1, username: "eviltrout" });
|
||||
const user = User.create({ id: 1, username: "eviltrout" });
|
||||
const stream = user.get("userDraftsStream");
|
||||
assert.present(stream, "a user has a drafts stream by default");
|
||||
assert.equal(stream.get("itemsLoaded"), 0, "no items are loaded by default");
|
||||
|
@ -1,9 +1,10 @@
|
||||
import UserAction from "discourse/models/user-action";
|
||||
import User from "discourse/models/user";
|
||||
|
||||
QUnit.module("Discourse.UserStream");
|
||||
QUnit.module("model: UserStream");
|
||||
|
||||
QUnit.test("basics", assert => {
|
||||
var user = Discourse.User.create({ id: 1, username: "eviltrout" });
|
||||
var user = User.create({ id: 1, username: "eviltrout" });
|
||||
var stream = user.get("stream");
|
||||
assert.present(stream, "a user has a stream by default");
|
||||
assert.equal(stream.get("user"), user, "the stream points back to the user");
|
||||
@ -16,7 +17,7 @@ QUnit.test("basics", assert => {
|
||||
});
|
||||
|
||||
QUnit.test("filterParam", assert => {
|
||||
var user = Discourse.User.create({ id: 1, username: "eviltrout" });
|
||||
var user = User.create({ id: 1, username: "eviltrout" });
|
||||
var stream = user.get("stream");
|
||||
|
||||
// defaults to posts/topics
|
||||
|
Loading…
Reference in New Issue
Block a user