mirror of
https://github.com/discourse/discourse.git
synced 2025-06-06 12:26:04 +08:00
DEV: Remove Discourse.User and import instead
This commit is contained in:

committed by
Robin Ward

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