mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
FIX: Respect site settings for sidebar users, groups and badges link (#18325)
The links should not be displayed when its associated site setting has been disabled. This commit maintains parity with the old hamburger menu.
This commit is contained in:
parent
a38e44fd5e
commit
03f83c0eed
@ -23,27 +23,19 @@ export default class SidebarCommunitySection extends Component {
|
|||||||
constructor() {
|
constructor() {
|
||||||
super(...arguments);
|
super(...arguments);
|
||||||
|
|
||||||
this.moreSectionLinks = [
|
this.moreSectionLinks = this.#initializeSectionLinks([
|
||||||
...this.defaultMoreSectionLinks,
|
...this.defaultMoreSectionLinks,
|
||||||
...customSectionLinks,
|
...customSectionLinks,
|
||||||
].map((sectionLinkClass) => {
|
]);
|
||||||
return this.#initializeSectionLink(sectionLinkClass);
|
|
||||||
});
|
|
||||||
|
|
||||||
this.moreSecondarySectionLinks = [
|
this.moreSecondarySectionLinks = this.#initializeSectionLinks([
|
||||||
...this.defaultMoreSecondarySectionLinks,
|
...this.defaultMoreSecondarySectionLinks,
|
||||||
...secondaryCustomSectionLinks,
|
...secondaryCustomSectionLinks,
|
||||||
].map((sectionLinkClass) => {
|
]);
|
||||||
return this.#initializeSectionLink(sectionLinkClass);
|
|
||||||
});
|
|
||||||
|
|
||||||
const mainSectionLinks = this.currentUser?.staff
|
this.sectionLinks = this.#initializeSectionLinks(
|
||||||
? [...this.defaultMainSectionLinks, ...this.defaultAdminMainSectionLinks]
|
this.defaultMainSectionLinks
|
||||||
: [...this.defaultMainSectionLinks];
|
);
|
||||||
|
|
||||||
this.sectionLinks = mainSectionLinks.map((sectionLinkClass) => {
|
|
||||||
return this.#initializeSectionLink(sectionLinkClass);
|
|
||||||
});
|
|
||||||
|
|
||||||
this.callbackId = this.topicTrackingState.onStateChange(() => {
|
this.callbackId = this.topicTrackingState.onStateChange(() => {
|
||||||
this.sectionLinks.forEach((sectionLink) => {
|
this.sectionLinks.forEach((sectionLink) => {
|
||||||
@ -62,11 +54,6 @@ export default class SidebarCommunitySection extends Component {
|
|||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
// Override in child
|
|
||||||
get defaultAdminMainSectionLinks() {
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
|
|
||||||
// Override in child
|
// Override in child
|
||||||
get defaultMoreSectionLinks() {
|
get defaultMoreSectionLinks() {
|
||||||
return [];
|
return [];
|
||||||
@ -77,6 +64,18 @@ export default class SidebarCommunitySection extends Component {
|
|||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#initializeSectionLinks(sectionLinkClasses) {
|
||||||
|
return sectionLinkClasses.reduce((links, sectionLinkClass) => {
|
||||||
|
const sectionLink = this.#initializeSectionLink(sectionLinkClass);
|
||||||
|
|
||||||
|
if (sectionLink.shouldDisplay) {
|
||||||
|
links.push(sectionLink);
|
||||||
|
}
|
||||||
|
|
||||||
|
return links;
|
||||||
|
}, []);
|
||||||
|
}
|
||||||
|
|
||||||
#initializeSectionLink(sectionLinkClass) {
|
#initializeSectionLink(sectionLinkClass) {
|
||||||
return new sectionLinkClass({
|
return new sectionLinkClass({
|
||||||
topicTrackingState: this.topicTrackingState,
|
topicTrackingState: this.topicTrackingState,
|
||||||
|
@ -32,11 +32,12 @@ export default class SidebarUserCommunitySection extends SidebarCommonCommunityS
|
|||||||
}
|
}
|
||||||
|
|
||||||
get defaultMainSectionLinks() {
|
get defaultMainSectionLinks() {
|
||||||
return [EverythingSectionLink, TrackedSectionLink, MyPostsSectionLink];
|
return [
|
||||||
}
|
EverythingSectionLink,
|
||||||
|
TrackedSectionLink,
|
||||||
get defaultAdminMainSectionLinks() {
|
MyPostsSectionLink,
|
||||||
return [AdminSectionLink];
|
AdminSectionLink,
|
||||||
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
get defaultMoreSectionLinks() {
|
get defaultMoreSectionLinks() {
|
||||||
|
@ -33,6 +33,13 @@ export default class BaseCommunitySectionLink {
|
|||||||
this._notImplemented();
|
this._notImplemented();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @returns {boolean} Whether the section link should be displayed. Defaults to true.
|
||||||
|
*/
|
||||||
|
get shouldDisplay() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @returns {string} Ember route
|
* @returns {string} Ember route
|
||||||
*/
|
*/
|
||||||
|
@ -18,4 +18,8 @@ export default class BadgesSectionLink extends BaseSectionLink {
|
|||||||
get text() {
|
get text() {
|
||||||
return I18n.t("sidebar.sections.community.links.badges.content");
|
return I18n.t("sidebar.sections.community.links.badges.content");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get shouldDisplay() {
|
||||||
|
return this.siteSettings.enable_badges;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,4 +18,8 @@ export default class GroupsSectionLink extends BaseSectionLink {
|
|||||||
get text() {
|
get text() {
|
||||||
return I18n.t("sidebar.sections.community.links.groups.content");
|
return I18n.t("sidebar.sections.community.links.groups.content");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get shouldDisplay() {
|
||||||
|
return this.siteSettings.enable_group_directory;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,4 +18,11 @@ export default class UsersSectionLink extends BaseSectionLink {
|
|||||||
get text() {
|
get text() {
|
||||||
return I18n.t("sidebar.sections.community.links.users.content");
|
return I18n.t("sidebar.sections.community.links.users.content");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get shouldDisplay() {
|
||||||
|
return (
|
||||||
|
this.siteSettings.enable_user_directory &&
|
||||||
|
(this.currentUser || !this.siteSettings.hide_user_profiles_from_public)
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,4 +18,8 @@ export default class AdminSectionLink extends BaseSectionLink {
|
|||||||
get text() {
|
get text() {
|
||||||
return I18n.t("sidebar.sections.community.links.admin.content");
|
return I18n.t("sidebar.sections.community.links.admin.content");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get shouldDisplay() {
|
||||||
|
return this.currentUser?.staff;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,7 @@ import { test } from "qunit";
|
|||||||
|
|
||||||
import {
|
import {
|
||||||
acceptance,
|
acceptance,
|
||||||
|
exists,
|
||||||
query,
|
query,
|
||||||
queryAll,
|
queryAll,
|
||||||
} from "discourse/tests/helpers/qunit-helpers";
|
} from "discourse/tests/helpers/qunit-helpers";
|
||||||
@ -72,7 +73,18 @@ acceptance("Sidebar - Anonymous user - Community Section", function (needs) {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
test("groups and badges section links are shown in more...", async function (assert) {
|
test("users section link is not shown when hide_user_profiles_from_public site setting is enabled", async function (assert) {
|
||||||
|
this.siteSettings.hide_user_profiles_from_public = true;
|
||||||
|
|
||||||
|
await visit("/");
|
||||||
|
|
||||||
|
assert.notOk(
|
||||||
|
exists(".sidebar-section-community .sidebar-section-link-users"),
|
||||||
|
"users section link is not shown in sidebar"
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("groups and badges section links are shown in more...", async function (assert) {
|
||||||
await visit("/");
|
await visit("/");
|
||||||
|
|
||||||
await click(
|
await click(
|
||||||
|
@ -229,6 +229,21 @@ acceptance("Sidebar - Logged on user - Community Section", function (needs) {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("users section link is not shown when enable_user_directory site setting is disabled", async function (assert) {
|
||||||
|
this.siteSettings.enable_user_directory = false;
|
||||||
|
|
||||||
|
await visit("/");
|
||||||
|
|
||||||
|
await click(
|
||||||
|
".sidebar-section-community .sidebar-more-section-links-details-summary"
|
||||||
|
);
|
||||||
|
|
||||||
|
assert.notOk(
|
||||||
|
exists(".sidebar-section-community .sidebar-section-link-users"),
|
||||||
|
"users section link is not displayed in sidebar"
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
test("clicking on badges link", async function (assert) {
|
test("clicking on badges link", async function (assert) {
|
||||||
await visit("/");
|
await visit("/");
|
||||||
|
|
||||||
@ -245,6 +260,21 @@ acceptance("Sidebar - Logged on user - Community Section", function (needs) {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("badges section link is not shown when badges has been disabled", async function (assert) {
|
||||||
|
this.siteSettings.enable_badges = false;
|
||||||
|
|
||||||
|
await visit("/");
|
||||||
|
|
||||||
|
await click(
|
||||||
|
".sidebar-section-community .sidebar-more-section-links-details-summary"
|
||||||
|
);
|
||||||
|
|
||||||
|
assert.notOk(
|
||||||
|
exists(".sidebar-section-community .sidebar-section-link-badges"),
|
||||||
|
"badges section link is not shown in sidebar"
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
test("clicking on groups link", async function (assert) {
|
test("clicking on groups link", async function (assert) {
|
||||||
await visit("/t/280");
|
await visit("/t/280");
|
||||||
|
|
||||||
@ -292,6 +322,21 @@ acceptance("Sidebar - Logged on user - Community Section", function (needs) {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("groups section link is not shown when enable_group_directory site setting has been disabled", async function (assert) {
|
||||||
|
this.siteSettings.enable_group_directory = false;
|
||||||
|
|
||||||
|
await visit("/");
|
||||||
|
|
||||||
|
await click(
|
||||||
|
".sidebar-section-community .sidebar-more-section-links-details-summary"
|
||||||
|
);
|
||||||
|
|
||||||
|
assert.notOk(
|
||||||
|
exists(".sidebar-section-community .sidebar-section-link-groups"),
|
||||||
|
"groups section link is not shown in sidebar"
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
test("navigating to about from sidebar", async function (assert) {
|
test("navigating to about from sidebar", async function (assert) {
|
||||||
await visit("/");
|
await visit("/");
|
||||||
|
|
||||||
|
@ -99,6 +99,7 @@ const ORIGINAL_SETTINGS = {
|
|||||||
secure_media: false,
|
secure_media: false,
|
||||||
external_emoji_url: "",
|
external_emoji_url: "",
|
||||||
remove_muted_tags_from_latest: "always",
|
remove_muted_tags_from_latest: "always",
|
||||||
|
enable_group_directory: true,
|
||||||
};
|
};
|
||||||
|
|
||||||
let siteSettings = Object.assign({}, ORIGINAL_SETTINGS);
|
let siteSettings = Object.assign({}, ORIGINAL_SETTINGS);
|
||||||
|
Loading…
Reference in New Issue
Block a user