DEV: Remove Discourse.User and import instead
This commit is contained in:
parent
0a14b9b42a
commit
f9894aec97
|
@ -7,10 +7,11 @@ import { popupAjaxError } from "discourse/lib/ajax-error";
|
|||
import Group from "discourse/models/group";
|
||||
import { userPath } from "discourse/lib/url";
|
||||
import { Promise } from "rsvp";
|
||||
import User from "discourse/models/user";
|
||||
|
||||
const wrapAdmin = user => (user ? AdminUser.create(user) : null);
|
||||
|
||||
const AdminUser = Discourse.User.extend({
|
||||
const AdminUser = User.extend({
|
||||
adminUserView: true,
|
||||
customGroups: filter("groups", g => !g.automatic && Group.create(g)),
|
||||
automaticGroups: filter("groups", g => g.automatic && Group.create(g)),
|
||||
|
|
|
@ -5,6 +5,7 @@ import showModal from "discourse/lib/show-modal";
|
|||
import BackupStatus from "admin/models/backup-status";
|
||||
import Backup from "admin/models/backup";
|
||||
import PreloadStore from "preload-store";
|
||||
import User from "discourse/models/user";
|
||||
|
||||
const LOG_CHANNEL = "/admin/backups/logs";
|
||||
|
||||
|
@ -12,7 +13,7 @@ export default DiscourseRoute.extend({
|
|||
activate() {
|
||||
this.messageBus.subscribe(LOG_CHANNEL, log => {
|
||||
if (log.message === "[STARTED]") {
|
||||
Discourse.User.currentProp("hideReadOnlyAlert", true);
|
||||
User.currentProp("hideReadOnlyAlert", true);
|
||||
this.controllerFor("adminBackups").set(
|
||||
"model.isOperationRunning",
|
||||
true
|
||||
|
@ -31,7 +32,7 @@ export default DiscourseRoute.extend({
|
|||
})
|
||||
);
|
||||
} else if (log.message === "[SUCCESS]") {
|
||||
Discourse.User.currentProp("hideReadOnlyAlert", false);
|
||||
User.currentProp("hideReadOnlyAlert", false);
|
||||
this.controllerFor("adminBackups").set(
|
||||
"model.isOperationRunning",
|
||||
false
|
||||
|
|
|
@ -8,6 +8,7 @@ import { computed } from "@ember/object";
|
|||
import FocusEvent from "discourse-common/mixins/focus-event";
|
||||
import EmberObject from "@ember/object";
|
||||
import deprecated from "discourse-common/lib/deprecated";
|
||||
import User from "discourse/models/user";
|
||||
|
||||
const _pluginCallbacks = [];
|
||||
|
||||
|
@ -62,7 +63,7 @@ const Discourse = Ember.Application.extend(FocusEvent, {
|
|||
}
|
||||
|
||||
var displayCount = this.displayCount;
|
||||
if (displayCount > 0 && !Discourse.User.currentProp("dynamic_favicon")) {
|
||||
if (displayCount > 0 && !User.currentProp("dynamic_favicon")) {
|
||||
title = `(${displayCount}) ${title}`;
|
||||
}
|
||||
|
||||
|
@ -71,15 +72,15 @@ const Discourse = Ember.Application.extend(FocusEvent, {
|
|||
|
||||
@discourseComputed("contextCount", "notificationCount")
|
||||
displayCount() {
|
||||
return Discourse.User.current() &&
|
||||
Discourse.User.currentProp("title_count_mode") === "notifications"
|
||||
return User.current() &&
|
||||
User.currentProp("title_count_mode") === "notifications"
|
||||
? this.notificationCount
|
||||
: this.contextCount;
|
||||
},
|
||||
|
||||
@observes("contextCount", "notificationCount")
|
||||
faviconChanged() {
|
||||
if (Discourse.User.currentProp("dynamic_favicon")) {
|
||||
if (User.currentProp("dynamic_favicon")) {
|
||||
let url = Discourse.SiteSettings.site_favicon_url;
|
||||
|
||||
// Since the favicon is cached on the browser for a really long time, we
|
||||
|
|
|
@ -17,6 +17,7 @@ import UserFieldsValidation from "discourse/mixins/user-fields-validation";
|
|||
import { userPath } from "discourse/lib/url";
|
||||
import { findAll } from "discourse/models/login-method";
|
||||
import EmberObject from "@ember/object";
|
||||
import User from "discourse/models/user";
|
||||
|
||||
export default Controller.extend(
|
||||
ModalFunctionality,
|
||||
|
@ -244,7 +245,7 @@ export default Controller.extend(
|
|||
}
|
||||
|
||||
this.set("formSubmitted", true);
|
||||
return Discourse.User.createAccount(attrs).then(
|
||||
return User.createAccount(attrs).then(
|
||||
result => {
|
||||
this.set("isDeveloper", false);
|
||||
if (result.success) {
|
||||
|
|
|
@ -8,6 +8,7 @@ import {
|
|||
observes
|
||||
} from "discourse-common/utils/decorators";
|
||||
import discourseDebounce from "discourse/lib/debounce";
|
||||
import User from "discourse/models/user";
|
||||
|
||||
export default Controller.extend({
|
||||
queryParams: ["order", "desc", "filter"],
|
||||
|
@ -112,7 +113,7 @@ export default Controller.extend({
|
|||
{ order: this.order, desc: this.desc }
|
||||
).then(result => {
|
||||
this.get("model.members").addObjects(
|
||||
result.members.map(member => Discourse.User.create(member))
|
||||
result.members.map(member => User.create(member))
|
||||
);
|
||||
this.setProperties({
|
||||
loading: false,
|
||||
|
|
|
@ -8,6 +8,7 @@ import {
|
|||
observes
|
||||
} from "discourse-common/utils/decorators";
|
||||
import discourseDebounce from "discourse/lib/debounce";
|
||||
import User from "discourse/models/user";
|
||||
|
||||
export default Controller.extend({
|
||||
queryParams: ["order", "desc", "filter"],
|
||||
|
@ -55,7 +56,7 @@ export default Controller.extend({
|
|||
}
|
||||
).then(result => {
|
||||
const requesters = (!force && this.get("model.requesters")) || [];
|
||||
requesters.addObjects(result.members.map(m => Discourse.User.create(m)));
|
||||
requesters.addObjects(result.members.map(m => User.create(m)));
|
||||
this.set("model.requesters", requesters);
|
||||
|
||||
this.setProperties({
|
||||
|
|
|
@ -9,6 +9,7 @@ import { setting, propertyEqual } from "discourse/lib/computed";
|
|||
import DiscourseURL from "discourse/lib/url";
|
||||
import { userPath } from "discourse/lib/url";
|
||||
import { popupAjaxError } from "discourse/lib/ajax-error";
|
||||
import User from "discourse/models/user";
|
||||
|
||||
export default Controller.extend({
|
||||
taken: false,
|
||||
|
@ -41,7 +42,7 @@ export default Controller.extend({
|
|||
if (isEmpty(this.newUsername)) return;
|
||||
if (this.unchanged) return;
|
||||
|
||||
Discourse.User.checkUsername(
|
||||
User.checkUsername(
|
||||
newUsername,
|
||||
undefined,
|
||||
this.get("model.id")
|
||||
|
|
|
@ -5,6 +5,7 @@ import { wantsNewWindow } from "discourse/lib/intercept-click";
|
|||
import { selectedText } from "discourse/lib/utilities";
|
||||
import { Promise } from "rsvp";
|
||||
import ENV from "discourse-common/config/environment";
|
||||
import User from "discourse/models/user";
|
||||
|
||||
export function isValidLink($link) {
|
||||
// Do not track:
|
||||
|
@ -64,7 +65,7 @@ export default {
|
|||
// Warn the user if they cannot download the file.
|
||||
if (
|
||||
Discourse.SiteSettings.prevent_anons_from_downloading_files &&
|
||||
!Discourse.User.current()
|
||||
!User.current()
|
||||
) {
|
||||
bootbox.alert(I18n.t("post.errors.attachment_download_requires_login"));
|
||||
} else if (wantsNewWindow(e)) {
|
||||
|
@ -83,7 +84,7 @@ export default {
|
|||
const postId = $article.data("post-id");
|
||||
const topicId = $("#topic").data("topic-id") || $article.data("topic-id");
|
||||
const userId = $link.data("user-id") || $article.data("user-id");
|
||||
const ownLink = userId && userId === Discourse.User.currentProp("id");
|
||||
const ownLink = userId && userId === User.currentProp("id");
|
||||
|
||||
// Update badge clicks unless it's our own.
|
||||
if (tracking && !ownLink) {
|
||||
|
@ -119,7 +120,7 @@ export default {
|
|||
}
|
||||
|
||||
const isInternal = DiscourseURL.isInternal(href);
|
||||
const openExternalInNewTab = Discourse.User.currentProp(
|
||||
const openExternalInNewTab = User.currentProp(
|
||||
"external_links_in_new_tab"
|
||||
);
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@ import KeyValueStore from "discourse/lib/key-value-store";
|
|||
import { formatUsername } from "discourse/lib/utilities";
|
||||
import { Promise } from "rsvp";
|
||||
import Site from "discourse/models/site";
|
||||
import User from "discourse/models/user";
|
||||
|
||||
let primaryTab = false;
|
||||
let liveEnabled = false;
|
||||
|
@ -22,7 +23,7 @@ function init(messageBus, appEvents) {
|
|||
liveEnabled = false;
|
||||
mbClientId = messageBus.clientId;
|
||||
|
||||
if (!Discourse.User.current()) {
|
||||
if (!User.current()) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -3,6 +3,7 @@ import { escapeExpression } from "discourse/lib/utilities";
|
|||
import { renderIcon } from "discourse-common/lib/icon-library";
|
||||
import { isAppWebview, postRNWebviewMessage } from "discourse/lib/utilities";
|
||||
import { spinnerHTML } from "discourse/helpers/loading-spinner";
|
||||
import User from "discourse/models/user";
|
||||
|
||||
export default function($elem) {
|
||||
if (!$elem) {
|
||||
|
@ -77,7 +78,7 @@ export default function($elem) {
|
|||
];
|
||||
if (
|
||||
!Discourse.SiteSettings.prevent_anons_from_downloading_files ||
|
||||
Discourse.User.current()
|
||||
User.current()
|
||||
) {
|
||||
src.push(
|
||||
'<a class="image-source-link" href="' +
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
import User from "discourse/models/user";
|
||||
|
||||
let _renderer = defaultRenderTag;
|
||||
|
||||
export function replaceTagRenderer(fn) {
|
||||
|
@ -12,10 +14,10 @@ function defaultRenderTag(tag, params) {
|
|||
const tagName = params.tagName || "a";
|
||||
let path;
|
||||
if (tagName === "a" && !params.noHref) {
|
||||
if (params.isPrivateMessage && Discourse.User.current()) {
|
||||
if (params.isPrivateMessage && User.current()) {
|
||||
const username = params.tagsForUser
|
||||
? params.tagsForUser
|
||||
: Discourse.User.current().username;
|
||||
: User.current().username;
|
||||
path = `/u/${username}/messages/tags/${tag}`;
|
||||
} else {
|
||||
path = `/tags/${tag}`;
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import { h } from "virtual-dom";
|
||||
import { renderIcon } from "discourse-common/lib/icon-library";
|
||||
import User from "discourse/models/user";
|
||||
|
||||
const _decorators = [];
|
||||
|
||||
|
@ -9,7 +10,7 @@ export function addFeaturedLinkMetaDecorator(decorator) {
|
|||
|
||||
export function extractLinkMeta(topic) {
|
||||
const href = topic.get("featured_link");
|
||||
const target = Discourse.User.currentProp("external_links_in_new_tab")
|
||||
const target = User.currentProp("external_links_in_new_tab")
|
||||
? "_blank"
|
||||
: "";
|
||||
|
||||
|
|
|
@ -5,6 +5,7 @@ import { schedule } from "@ember/runloop";
|
|||
import offsetCalculator from "discourse/lib/offset-calculator";
|
||||
import LockOn from "discourse/lib/lock-on";
|
||||
import { defaultHomepage } from "discourse/lib/utilities";
|
||||
import User from "discourse/models/user";
|
||||
|
||||
const rewrites = [];
|
||||
const TOPIC_REGEXP = /\/t\/([^\/]+)\/(\d+)\/?(\d+)?/;
|
||||
|
@ -230,7 +231,7 @@ const DiscourseURL = EmberObject.extend({
|
|||
// Rewrite /my/* urls
|
||||
let myPath = `${baseUri}/my/`;
|
||||
if (path.indexOf(myPath) === 0) {
|
||||
const currentUser = Discourse.User.current();
|
||||
const currentUser = User.current();
|
||||
if (currentUser) {
|
||||
path = path.replace(
|
||||
myPath,
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
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]";
|
||||
|
||||
|
@ -238,7 +239,7 @@ export function validateUploadedFile(file, opts) {
|
|||
|
||||
// check that the uploaded file is authorized
|
||||
if (opts.allowStaffToUploadAnyFileInPm && opts.isPrivateMessage) {
|
||||
if (Discourse.User.currentProp("staff")) {
|
||||
if (User.currentProp("staff")) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -270,7 +271,7 @@ export function validateUploadedFile(file, opts) {
|
|||
|
||||
if (!opts.bypassNewUserRestriction) {
|
||||
// ensures that new users can upload a file
|
||||
if (!Discourse.User.current().isAllowedToUploadAFile(opts.type)) {
|
||||
if (!User.current().isAllowedToUploadAFile(opts.type)) {
|
||||
bootbox.alert(
|
||||
I18n.t(`post.errors.${opts.type}_upload_not_allowed_for_new_user`)
|
||||
);
|
||||
|
@ -304,7 +305,7 @@ function staffExtensions() {
|
|||
|
||||
function imagesExtensions() {
|
||||
let exts = extensions().filter(ext => IMAGES_EXTENSIONS_REGEX.test(ext));
|
||||
if (Discourse.User.currentProp("staff")) {
|
||||
if (User.currentProp("staff")) {
|
||||
const staffExts = staffExtensions().filter(ext =>
|
||||
IMAGES_EXTENSIONS_REGEX.test(ext)
|
||||
);
|
||||
|
@ -327,7 +328,7 @@ function staffExtensionsRegex() {
|
|||
|
||||
function isAuthorizedFile(fileName) {
|
||||
if (
|
||||
Discourse.User.currentProp("staff") &&
|
||||
User.currentProp("staff") &&
|
||||
staffExtensionsRegex().test(fileName)
|
||||
) {
|
||||
return true;
|
||||
|
@ -340,7 +341,7 @@ function isAuthorizedImage(fileName) {
|
|||
}
|
||||
|
||||
export function authorizedExtensions() {
|
||||
const exts = Discourse.User.currentProp("staff")
|
||||
const exts = User.currentProp("staff")
|
||||
? [...extensions(), ...staffExtensions()]
|
||||
: extensions();
|
||||
return exts.filter(ext => ext.length > 0).join(", ");
|
||||
|
@ -356,7 +357,7 @@ export function authorizesAllExtensions() {
|
|||
return (
|
||||
Discourse.SiteSettings.authorized_extensions.indexOf("*") >= 0 ||
|
||||
(Discourse.SiteSettings.authorized_extensions_for_staff.indexOf("*") >= 0 &&
|
||||
Discourse.User.currentProp("staff"))
|
||||
User.currentProp("staff"))
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@ import { setting } from "discourse/lib/computed";
|
|||
import { default as discourseComputed } from "discourse-common/utils/decorators";
|
||||
import Mixin from "@ember/object/mixin";
|
||||
import EmberObject from "@ember/object";
|
||||
import User from "discourse/models/user";
|
||||
|
||||
export default Mixin.create({
|
||||
uniqueUsernameValidation: null,
|
||||
|
@ -13,7 +14,7 @@ export default Mixin.create({
|
|||
minUsernameLength: setting("min_username_length"),
|
||||
|
||||
fetchExistingUsername: discourseDebounce(function() {
|
||||
Discourse.User.checkUsername(null, this.accountEmail).then(result => {
|
||||
User.checkUsername(null, this.accountEmail).then(result => {
|
||||
if (
|
||||
result.suggestion &&
|
||||
(isEmpty(this.accountUsername) ||
|
||||
|
@ -76,7 +77,7 @@ export default Mixin.create({
|
|||
|
||||
checkUsernameAvailability: discourseDebounce(function() {
|
||||
if (this.shouldCheckUsernameAvailability()) {
|
||||
return Discourse.User.checkUsername(
|
||||
return User.checkUsername(
|
||||
this.accountUsername,
|
||||
this.accountEmail
|
||||
).then(result => {
|
||||
|
|
|
@ -20,6 +20,7 @@ import { throttle } from "@ember/runloop";
|
|||
import { Promise } from "rsvp";
|
||||
import { set } from "@ember/object";
|
||||
import Site from "discourse/models/site";
|
||||
import User from "discourse/models/user";
|
||||
|
||||
// The actions the composer can take
|
||||
export const CREATE_TOPIC = "createTopic",
|
||||
|
@ -1146,7 +1147,7 @@ Composer.reopenClass({
|
|||
// TODO: Replace with injection
|
||||
create(args) {
|
||||
args = args || {};
|
||||
args.user = args.user || Discourse.User.current();
|
||||
args.user = args.user || User.current();
|
||||
args.site = args.site || Site.current();
|
||||
args.siteSettings = args.siteSettings || Discourse.SiteSettings;
|
||||
return this._super(args);
|
||||
|
|
|
@ -4,6 +4,7 @@ import { popupAjaxError } from "discourse/lib/ajax-error";
|
|||
import { userPath } from "discourse/lib/url";
|
||||
import { Promise } from "rsvp";
|
||||
import { isNone } from "@ember/utils";
|
||||
import User from "discourse/models/user";
|
||||
|
||||
const Invite = EmberObject.extend({
|
||||
rescind() {
|
||||
|
@ -28,7 +29,7 @@ Invite.reopenClass({
|
|||
create() {
|
||||
const result = this._super.apply(this, arguments);
|
||||
if (result.user) {
|
||||
result.user = Discourse.User.create(result.user);
|
||||
result.user = User.create(result.user);
|
||||
}
|
||||
return result;
|
||||
},
|
||||
|
|
|
@ -4,6 +4,7 @@ import Category from "discourse/models/category";
|
|||
import EmberObject from "@ember/object";
|
||||
import deprecated from "discourse-common/lib/deprecated";
|
||||
import Site from "discourse/models/site";
|
||||
import User from "discourse/models/user";
|
||||
|
||||
const NavItem = EmberObject.extend({
|
||||
@discourseComputed("name")
|
||||
|
@ -100,8 +101,8 @@ NavItem.reopenClass({
|
|||
|
||||
// create a nav item from the text, will return null if there is not valid nav item for this particular text
|
||||
fromText(text, opts) {
|
||||
var testName = text.split("/")[0],
|
||||
anonymous = !Discourse.User.current();
|
||||
let testName = text.split("/")[0],
|
||||
anonymous = !User.current();
|
||||
|
||||
opts = opts || {};
|
||||
|
||||
|
|
|
@ -8,6 +8,7 @@ import PostsWithPlaceholders from "discourse/lib/posts-with-placeholders";
|
|||
import { default as discourseComputed } from "discourse-common/utils/decorators";
|
||||
import { loadTopicView } from "discourse/models/topic";
|
||||
import { Promise } from "rsvp";
|
||||
import User from "discourse/models/user";
|
||||
|
||||
export default RestModel.extend({
|
||||
_identityMap: null,
|
||||
|
@ -605,8 +606,8 @@ export default RestModel.extend({
|
|||
return this.findPostsByIds([postId])
|
||||
.then(posts => {
|
||||
const ignoredUsers =
|
||||
Discourse.User.current() &&
|
||||
Discourse.User.current().get("ignored_users");
|
||||
User.current() &&
|
||||
User.current().get("ignored_users");
|
||||
posts.forEach(p => {
|
||||
if (ignoredUsers && ignoredUsers.includes(p.username)) {
|
||||
this.stream.removeObject(postId);
|
||||
|
|
|
@ -15,6 +15,7 @@ import { userPath } from "discourse/lib/url";
|
|||
import Composer from "discourse/models/composer";
|
||||
import { Promise } from "rsvp";
|
||||
import Site from "discourse/models/site";
|
||||
import User from "discourse/models/user";
|
||||
|
||||
const Post = RestModel.extend({
|
||||
// TODO: Remove this once one instantiate all `Discourse.Post` models via the store.
|
||||
|
@ -31,7 +32,7 @@ const Post = RestModel.extend({
|
|||
|
||||
@discourseComputed("url")
|
||||
shareUrl(url) {
|
||||
const user = Discourse.User.current();
|
||||
const user = User.current();
|
||||
const userSuffix = user ? `?u=${user.username_lower}` : "";
|
||||
|
||||
if (this.firstPost) {
|
||||
|
@ -371,7 +372,7 @@ Post.reopenClass({
|
|||
}
|
||||
|
||||
if (json && json.reply_to_user) {
|
||||
json.reply_to_user = Discourse.User.create(json.reply_to_user);
|
||||
json.reply_to_user = User.create(json.reply_to_user);
|
||||
}
|
||||
|
||||
return json;
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import discourseComputed from "discourse-common/utils/decorators";
|
||||
import EmberObject from "@ember/object";
|
||||
import { ajax } from "discourse/lib/ajax";
|
||||
|
||||
import User from "discourse/models/user";
|
||||
/**
|
||||
A model representing a Topic's details that aren't always present, such as a list of participants.
|
||||
When showing topics in lists and such this information should not be required.
|
||||
|
@ -17,7 +17,7 @@ const TopicDetails = RestModel.extend({
|
|||
|
||||
if (details.allowed_users) {
|
||||
details.allowed_users = details.allowed_users.map(function(u) {
|
||||
return Discourse.User.create(u);
|
||||
return User.create(u);
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -48,13 +48,13 @@ const TopicDetails = RestModel.extend({
|
|||
}
|
||||
|
||||
if (
|
||||
Discourse.User.currentProp("mailing_list_mode") &&
|
||||
User.currentProp("mailing_list_mode") &&
|
||||
level > NotificationLevels.MUTED
|
||||
) {
|
||||
return I18n.t("topic.notifications.reasons.mailing_list_mode");
|
||||
} else {
|
||||
return I18n.t(localeString, {
|
||||
username: Discourse.User.currentProp("username_lower"),
|
||||
username: User.currentProp("username_lower"),
|
||||
basePath: Discourse.BaseUri
|
||||
});
|
||||
}
|
||||
|
|
|
@ -10,6 +10,7 @@ import PreloadStore from "preload-store";
|
|||
import Category from "discourse/models/category";
|
||||
import EmberObject from "@ember/object";
|
||||
import Site from "discourse/models/site";
|
||||
import User from "discourse/models/user";
|
||||
|
||||
function isNew(topic) {
|
||||
return (
|
||||
|
@ -47,9 +48,7 @@ const TopicTrackingState = EmberObject.extend({
|
|||
}
|
||||
|
||||
if (["new_topic", "latest"].includes(data.message_type)) {
|
||||
const muted_category_ids = Discourse.User.currentProp(
|
||||
"muted_category_ids"
|
||||
);
|
||||
const muted_category_ids = User.currentProp("muted_category_ids");
|
||||
if (
|
||||
muted_category_ids &&
|
||||
muted_category_ids.includes(data.payload.category_id)
|
||||
|
|
|
@ -22,6 +22,7 @@ import Category from "discourse/models/category";
|
|||
import Session from "discourse/models/session";
|
||||
import { Promise } from "rsvp";
|
||||
import Site from "discourse/models/site";
|
||||
import User from "discourse/models/user";
|
||||
|
||||
export function loadTopicView(topic, args) {
|
||||
const data = _.merge({}, args);
|
||||
|
@ -234,7 +235,7 @@ const Topic = RestModel.extend({
|
|||
|
||||
@discourseComputed("url")
|
||||
shareUrl(url) {
|
||||
const user = Discourse.User.current();
|
||||
const user = User.current();
|
||||
const userQueryString = user ? `?u=${user.get("username_lower")}` : "";
|
||||
return `${url}${userQueryString}`;
|
||||
},
|
||||
|
|
|
@ -6,6 +6,7 @@ import UserActionGroup from "discourse/models/user-action-group";
|
|||
import { postUrl } from "discourse/lib/utilities";
|
||||
import { userPath } from "discourse/lib/url";
|
||||
import Category from "discourse/models/category";
|
||||
import User from "discourse/models/user";
|
||||
|
||||
const UserActionTypes = {
|
||||
likes_given: 1,
|
||||
|
@ -69,12 +70,12 @@ const UserAction = RestModel.extend({
|
|||
|
||||
@discourseComputed("username")
|
||||
sameUser(username) {
|
||||
return username === Discourse.User.currentProp("username");
|
||||
return username === User.currentProp("username");
|
||||
},
|
||||
|
||||
@discourseComputed("target_username")
|
||||
targetUser(targetUsername) {
|
||||
return targetUsername === Discourse.User.currentProp("username");
|
||||
return targetUsername === User.currentProp("username");
|
||||
},
|
||||
|
||||
presentName: or("name", "username"),
|
||||
|
|
|
@ -4,6 +4,7 @@ import Badge from "discourse/models/badge";
|
|||
import { Promise } from "rsvp";
|
||||
import Topic from "discourse/models/topic";
|
||||
import EmberObject from "@ember/object";
|
||||
import User from "discourse/models/user";
|
||||
|
||||
const UserBadge = EmberObject.extend({
|
||||
@discourseComputed
|
||||
|
@ -28,7 +29,7 @@ UserBadge.reopenClass({
|
|||
}
|
||||
var users = {};
|
||||
json.users.forEach(function(userJson) {
|
||||
users[userJson.id] = Discourse.User.create(userJson);
|
||||
users[userJson.id] = User.create(userJson);
|
||||
});
|
||||
|
||||
// Create Topic objects.
|
||||
|
|
|
@ -27,6 +27,7 @@ import { Promise } from "rsvp";
|
|||
import { getProperties } from "@ember/object";
|
||||
import deprecated from "discourse-common/lib/deprecated";
|
||||
import Site from "discourse/models/site";
|
||||
import User from "discourse/models/user";
|
||||
|
||||
export const SECOND_FACTOR_METHODS = {
|
||||
TOTP: 1,
|
||||
|
@ -249,7 +250,7 @@ const User = RestModel.extend({
|
|||
},
|
||||
|
||||
copy() {
|
||||
return Discourse.User.create(this.getProperties(Object.keys(this)));
|
||||
return User.create(this.getProperties(Object.keys(this)));
|
||||
},
|
||||
|
||||
save(fields) {
|
||||
|
@ -361,7 +362,7 @@ const User = RestModel.extend({
|
|||
"external_links_in_new_tab",
|
||||
"dynamic_favicon"
|
||||
);
|
||||
Discourse.User.current().setProperties(userProps);
|
||||
User.current().setProperties(userProps);
|
||||
this.setProperties(updatedState);
|
||||
})
|
||||
.finally(() => {
|
||||
|
@ -541,7 +542,7 @@ const User = RestModel.extend({
|
|||
return ajax(userPath(`${user.get("username")}.json`), { data: options });
|
||||
}).then(json => {
|
||||
if (!isEmpty(json.user.stats)) {
|
||||
json.user.stats = Discourse.User.groupStats(
|
||||
json.user.stats = User.groupStats(
|
||||
json.user.stats.map(s => {
|
||||
if (s.count) s.count = parseInt(s.count, 10);
|
||||
return UserActionStat.create(s);
|
||||
|
@ -562,7 +563,7 @@ const User = RestModel.extend({
|
|||
}
|
||||
|
||||
if (json.user.invited_by) {
|
||||
json.user.invited_by = Discourse.User.create(json.user.invited_by);
|
||||
json.user.invited_by = User.create(json.user.invited_by);
|
||||
}
|
||||
|
||||
if (!isEmpty(json.user.featured_user_badge_ids)) {
|
||||
|
@ -585,7 +586,7 @@ const User = RestModel.extend({
|
|||
},
|
||||
|
||||
findStaffInfo() {
|
||||
if (!Discourse.User.currentProp("staff")) {
|
||||
if (!User.currentProp("staff")) {
|
||||
return Promise.resolve(null);
|
||||
}
|
||||
return ajax(userPath(`${this.username_lower}/staff-info.json`)).then(
|
||||
|
@ -681,7 +682,7 @@ const User = RestModel.extend({
|
|||
type: "PUT",
|
||||
data: { notification_level: level, expiring_at: expiringAt }
|
||||
}).then(() => {
|
||||
const currentUser = Discourse.User.current();
|
||||
const currentUser = User.current();
|
||||
if (currentUser) {
|
||||
if (level === "normal" || level === "mute") {
|
||||
currentUser.ignored_users.removeObject(this.username);
|
||||
|
@ -827,7 +828,7 @@ const User = RestModel.extend({
|
|||
});
|
||||
|
||||
User.reopenClass(Singleton, {
|
||||
// Find a `Discourse.User` for a given username.
|
||||
// Find a `User` for a given username.
|
||||
findByUsername(username, options) {
|
||||
const user = User.create({ username: username });
|
||||
return user.findDetails(options);
|
||||
|
@ -907,7 +908,7 @@ let warned = false;
|
|||
Object.defineProperty(Discourse, "User", {
|
||||
get() {
|
||||
if (!warned) {
|
||||
deprecated("Import the User class instead of using Discourse.User", {
|
||||
deprecated("Import the User class instead of using User", {
|
||||
since: "2.4.0",
|
||||
dropFrom: "2.6.0"
|
||||
});
|
||||
|
|
|
@ -3,6 +3,7 @@ import buildTopicRoute from "discourse/routes/build-topic-route";
|
|||
import DiscoverySortableController from "discourse/controllers/discovery-sortable";
|
||||
import TagsShowRoute from "discourse/routes/tags-show";
|
||||
import Site from "discourse/models/site";
|
||||
import User from "discourse/models/user";
|
||||
|
||||
export default {
|
||||
after: "inject-discourse-objects",
|
||||
|
@ -55,8 +56,8 @@ export default {
|
|||
Discourse.DiscoveryTopRoute = buildTopicRoute("top", {
|
||||
actions: {
|
||||
willTransition() {
|
||||
Discourse.User.currentProp("should_be_redirected_to_top", false);
|
||||
Discourse.User.currentProp("redirected_to_top.reason", null);
|
||||
User.currentProp("should_be_redirected_to_top", false);
|
||||
User.currentProp("redirected_to_top.reason", null);
|
||||
return this._super(...arguments);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
import DiscourseRoute from "discourse/routes/discourse";
|
||||
import OpenComposer from "discourse/mixins/open-composer";
|
||||
import { scrollTop } from "discourse/mixins/scroll-top";
|
||||
import User from "discourse/models/user";
|
||||
|
||||
export default DiscourseRoute.extend(OpenComposer, {
|
||||
redirect() {
|
||||
|
@ -12,7 +13,7 @@ export default DiscourseRoute.extend(OpenComposer, {
|
|||
},
|
||||
|
||||
beforeModel(transition) {
|
||||
const user = Discourse.User;
|
||||
const user = User;
|
||||
const url = transition.intent.url;
|
||||
|
||||
if (
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import DiscourseRoute from "discourse/routes/discourse";
|
||||
import User from "discourse/models/user";
|
||||
|
||||
export default DiscourseRoute.extend({
|
||||
titleToken() {
|
||||
|
@ -41,7 +42,7 @@ export default DiscourseRoute.extend({
|
|||
return this.currentUser;
|
||||
}
|
||||
|
||||
return Discourse.User.create({
|
||||
return User.create({
|
||||
username: encodeURIComponent(params.username)
|
||||
});
|
||||
},
|
||||
|
|
Loading…
Reference in New Issue