FIX: Hide Unassigned if user doesn't have access (#179)
There's no need to display the "Unassigned" button for regular users when `assigns_public` is `false`.
This commit is contained in:
parent
bdff555968
commit
ad95725987
|
@ -102,18 +102,22 @@ function registerTopicFooterButtons(api) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function initialize(api) {
|
function initialize(api) {
|
||||||
|
const siteSettings = api.container.lookup("site-settings:main");
|
||||||
|
const currentUser = api.getCurrentUser();
|
||||||
|
|
||||||
|
if (siteSettings.assigns_public || currentUser?.can_assign) {
|
||||||
api.addNavigationBarItem({
|
api.addNavigationBarItem({
|
||||||
name: "unassigned",
|
name: "unassigned",
|
||||||
customFilter: (category) => {
|
customFilter: (category) => {
|
||||||
return category && category.enable_unassigned_filter;
|
return category?.custom_fields?.enable_unassigned_filter === "true";
|
||||||
},
|
},
|
||||||
customHref: (category) => {
|
customHref: (category) => {
|
||||||
if (category) {
|
if (category) {
|
||||||
return getURL(category.url) + "/l/latest?status=open&assigned=nobody";
|
return getURL(category.url) + "/l/latest?status=open&assigned=nobody";
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
forceActive: (category, args, router) => {
|
forceActive: (category, args) => {
|
||||||
const queryParams = router.currentRoute.queryParams;
|
const queryParams = args.currentRouteQueryParams;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
queryParams &&
|
queryParams &&
|
||||||
|
@ -124,6 +128,7 @@ function initialize(api) {
|
||||||
},
|
},
|
||||||
before: "top",
|
before: "top",
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
api.addAdvancedSearchOptions(
|
api.addAdvancedSearchOptions(
|
||||||
api.getCurrentUser() && api.getCurrentUser().can_assign
|
api.getCurrentUser() && api.getCurrentUser().can_assign
|
||||||
|
@ -145,7 +150,6 @@ function initialize(api) {
|
||||||
api.modifyClass("model:topic", {
|
api.modifyClass("model:topic", {
|
||||||
@computed("assigned_to_user")
|
@computed("assigned_to_user")
|
||||||
assignedToUserPath(assignedToUser) {
|
assignedToUserPath(assignedToUser) {
|
||||||
const siteSettings = api.container.lookup("site-settings:main");
|
|
||||||
return getURL(
|
return getURL(
|
||||||
siteSettings.assigns_user_url_path.replace(
|
siteSettings.assigns_user_url_path.replace(
|
||||||
"{username}",
|
"{username}",
|
||||||
|
|
|
@ -4,7 +4,9 @@ plugins:
|
||||||
client: true
|
client: true
|
||||||
assigns_by_staff_mention: false
|
assigns_by_staff_mention: false
|
||||||
unassign_creates_tracking_post: true
|
unassign_creates_tracking_post: true
|
||||||
assigns_public: false
|
assigns_public:
|
||||||
|
default: false
|
||||||
|
client: true
|
||||||
assign_self_regex: ""
|
assign_self_regex: ""
|
||||||
assign_other_regex: ""
|
assign_other_regex: ""
|
||||||
unassign_on_close: false
|
unassign_on_close: false
|
||||||
|
@ -27,6 +29,6 @@ plugins:
|
||||||
client: true
|
client: true
|
||||||
type: group_list
|
type: group_list
|
||||||
list_type: compact
|
list_type: compact
|
||||||
default: ''
|
default: ""
|
||||||
allow_any: false
|
allow_any: false
|
||||||
refresh: true
|
refresh: true
|
||||||
|
|
|
@ -0,0 +1,114 @@
|
||||||
|
import {
|
||||||
|
acceptance,
|
||||||
|
exists,
|
||||||
|
updateCurrentUser,
|
||||||
|
} from "discourse/tests/helpers/qunit-helpers";
|
||||||
|
import { visit } from "@ember/test-helpers";
|
||||||
|
import { test } from "qunit";
|
||||||
|
import I18n from "I18n";
|
||||||
|
import DiscoveryFixtures from "discourse/tests/fixtures/discovery-fixtures";
|
||||||
|
|
||||||
|
function stubCategory(needs, customFields) {
|
||||||
|
needs.site({
|
||||||
|
categories: [
|
||||||
|
{
|
||||||
|
id: 6,
|
||||||
|
name: "test",
|
||||||
|
slug: "test",
|
||||||
|
custom_fields: customFields,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
|
needs.pretender((server, helper) => {
|
||||||
|
server.get("/c/test/6/l/latest.json", () => {
|
||||||
|
return helper.response(
|
||||||
|
DiscoveryFixtures["/latest_can_create_topic.json"]
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
acceptance(
|
||||||
|
"Discourse Assign | Categories for users that can assign",
|
||||||
|
function (needs) {
|
||||||
|
needs.user();
|
||||||
|
needs.settings({
|
||||||
|
assign_enabled: true,
|
||||||
|
assigns_user_url_path: "/",
|
||||||
|
assigns_public: false,
|
||||||
|
});
|
||||||
|
stubCategory(needs, { enable_unassigned_filter: "true" });
|
||||||
|
|
||||||
|
test("can see Unassigned button", async (assert) => {
|
||||||
|
updateCurrentUser({ can_assign: true });
|
||||||
|
await visit("/c/test");
|
||||||
|
|
||||||
|
const title = I18n.t("filters.unassigned.help");
|
||||||
|
assert.ok(exists(`#navigation-bar li[title='${title}']`));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
acceptance(
|
||||||
|
"Discourse Assign | Categories without enable_unassigned_filter",
|
||||||
|
function (needs) {
|
||||||
|
needs.user();
|
||||||
|
needs.settings({
|
||||||
|
assign_enabled: true,
|
||||||
|
assigns_user_url_path: "/",
|
||||||
|
assigns_public: false,
|
||||||
|
});
|
||||||
|
stubCategory(needs, { enable_unassigned_filter: "false" });
|
||||||
|
|
||||||
|
test("cannot see Unassigned button", async (assert) => {
|
||||||
|
updateCurrentUser({ can_assign: true });
|
||||||
|
await visit("/c/test");
|
||||||
|
|
||||||
|
const title = I18n.t("filters.unassigned.help");
|
||||||
|
assert.ok(!exists(`#navigation-bar li[title='${title}']`));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
acceptance(
|
||||||
|
"Discourse Assign | Categories when assigns are public",
|
||||||
|
function (needs) {
|
||||||
|
needs.user();
|
||||||
|
needs.settings({
|
||||||
|
assign_enabled: true,
|
||||||
|
assigns_user_url_path: "/",
|
||||||
|
assigns_public: true,
|
||||||
|
});
|
||||||
|
stubCategory(needs, { enable_unassigned_filter: "true" });
|
||||||
|
|
||||||
|
test("can see Unassigned button", async (assert) => {
|
||||||
|
updateCurrentUser({ can_assign: false });
|
||||||
|
await visit("/c/test");
|
||||||
|
|
||||||
|
const title = I18n.t("filters.unassigned.help");
|
||||||
|
assert.ok(exists(`#navigation-bar li[title='${title}']`));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
acceptance(
|
||||||
|
"Discourse Assign | Categories when assigns are private",
|
||||||
|
function (needs) {
|
||||||
|
needs.user();
|
||||||
|
needs.settings({
|
||||||
|
assign_enabled: true,
|
||||||
|
assigns_user_url_path: "/",
|
||||||
|
assigns_public: false,
|
||||||
|
});
|
||||||
|
stubCategory(needs, { enable_unassigned_filter: "true" });
|
||||||
|
|
||||||
|
test("cannot see Unassigned button", async (assert) => {
|
||||||
|
updateCurrentUser({ can_assign: false });
|
||||||
|
await visit("/c/test");
|
||||||
|
|
||||||
|
const title = I18n.t("filters.unassigned.help");
|
||||||
|
assert.ok(!exists(`#navigation-bar li[title='${title}']`));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
);
|
Loading…
Reference in New Issue