REFACTOR: Remove `Discourse.SiteSettings` from Category model
This commit is contained in:
parent
217b970e16
commit
bc7dac852f
|
@ -8,6 +8,7 @@ import PermissionType from "discourse/models/permission-type";
|
||||||
import { NotificationLevels } from "discourse/lib/notification-levels";
|
import { NotificationLevels } from "discourse/lib/notification-levels";
|
||||||
import Site from "discourse/models/site";
|
import Site from "discourse/models/site";
|
||||||
import User from "discourse/models/user";
|
import User from "discourse/models/user";
|
||||||
|
import { getOwner } from "discourse-common/lib/get-owner";
|
||||||
|
|
||||||
const Category = RestModel.extend({
|
const Category = RestModel.extend({
|
||||||
permissions: null,
|
permissions: null,
|
||||||
|
@ -267,6 +268,11 @@ const Category = RestModel.extend({
|
||||||
var _uncategorized;
|
var _uncategorized;
|
||||||
|
|
||||||
Category.reopenClass({
|
Category.reopenClass({
|
||||||
|
slugEncoded() {
|
||||||
|
let siteSettings = getOwner(this).lookup("site-settings:main");
|
||||||
|
return siteSettings.slug_generation_method === "encoded";
|
||||||
|
},
|
||||||
|
|
||||||
findUncategorized() {
|
findUncategorized() {
|
||||||
_uncategorized =
|
_uncategorized =
|
||||||
_uncategorized ||
|
_uncategorized ||
|
||||||
|
@ -309,7 +315,7 @@ Category.reopenClass({
|
||||||
},
|
},
|
||||||
|
|
||||||
findSingleBySlug(slug) {
|
findSingleBySlug(slug) {
|
||||||
if (Discourse.SiteSettings.slug_generation_method !== "encoded") {
|
if (!this.slugEncoded()) {
|
||||||
return Category.list().find(c => Category.slugFor(c) === slug);
|
return Category.list().find(c => Category.slugFor(c) === slug);
|
||||||
} else {
|
} else {
|
||||||
return Category.list().find(c => Category.slugFor(c) === encodeURI(slug));
|
return Category.list().find(c => Category.slugFor(c) === encodeURI(slug));
|
||||||
|
@ -335,7 +341,7 @@ Category.reopenClass({
|
||||||
},
|
},
|
||||||
|
|
||||||
findBySlugAndParent(slug, parentCategory) {
|
findBySlugAndParent(slug, parentCategory) {
|
||||||
if (Discourse.SiteSettings.slug_generation_method === "encoded") {
|
if (this.slugEncoded()) {
|
||||||
slug = encodeURI(slug);
|
slug = encodeURI(slug);
|
||||||
}
|
}
|
||||||
return Category.list().find(category => {
|
return Category.list().find(category => {
|
||||||
|
@ -363,7 +369,7 @@ Category.reopenClass({
|
||||||
findBySlugPathWithID(slugPathWithID) {
|
findBySlugPathWithID(slugPathWithID) {
|
||||||
let parts = slugPathWithID.split("/").filter(Boolean);
|
let parts = slugPathWithID.split("/").filter(Boolean);
|
||||||
// slugs found by star/glob pathing in emeber do not automatically url decode - ensure that these are decoded
|
// slugs found by star/glob pathing in emeber do not automatically url decode - ensure that these are decoded
|
||||||
if (Discourse.SiteSettings.slug_generation_method === "encoded") {
|
if (this.slugEncoded()) {
|
||||||
parts = parts.map(urlPart => decodeURI(urlPart));
|
parts = parts.map(urlPart => decodeURI(urlPart));
|
||||||
}
|
}
|
||||||
let category = null;
|
let category = null;
|
||||||
|
@ -404,9 +410,9 @@ Category.reopenClass({
|
||||||
return (
|
return (
|
||||||
item &&
|
item &&
|
||||||
item.get("parentCategory") === parentCategory &&
|
item.get("parentCategory") === parentCategory &&
|
||||||
((Discourse.SiteSettings.slug_generation_method !== "encoded" &&
|
((!this.slugEncoded() &&
|
||||||
Category.slugFor(item) === parentSlug + "/" + slug) ||
|
Category.slugFor(item) === parentSlug + "/" + slug) ||
|
||||||
(Discourse.SiteSettings.slug_generation_method === "encoded" &&
|
(this.slugEncoded() &&
|
||||||
Category.slugFor(item) ===
|
Category.slugFor(item) ===
|
||||||
encodeURI(parentSlug) + "/" + encodeURI(slug)))
|
encodeURI(parentSlug) + "/" + encodeURI(slug)))
|
||||||
);
|
);
|
||||||
|
|
Loading…
Reference in New Issue