FEATURE: allow moderators to bulk change ownership (#15997)
This commit is contained in:
parent
efb7e19325
commit
cd616900e5
|
@ -1446,12 +1446,22 @@ export default Controller.extend(bufferedProperty("model"), {
|
|||
|
||||
@discourseComputed(
|
||||
"currentUser.admin",
|
||||
"currentUser.staff",
|
||||
"siteSettings.moderators_change_post_ownership",
|
||||
"selectedPostsCount",
|
||||
"selectedPostsUsername"
|
||||
)
|
||||
canChangeOwner(isAdmin, selectedPostsCount, selectedPostsUsername) {
|
||||
canChangeOwner(
|
||||
isAdmin,
|
||||
isStaff,
|
||||
modChangePostOwner,
|
||||
selectedPostsCount,
|
||||
selectedPostsUsername
|
||||
) {
|
||||
return (
|
||||
isAdmin && selectedPostsCount > 0 && selectedPostsUsername !== undefined
|
||||
(isAdmin || (modChangePostOwner && isStaff)) &&
|
||||
selectedPostsCount > 0 &&
|
||||
selectedPostsUsername !== undefined
|
||||
);
|
||||
},
|
||||
|
||||
|
|
|
@ -407,6 +407,54 @@ discourseModule("Unit | Controller | topic", function (hooks) {
|
|||
);
|
||||
});
|
||||
|
||||
test("modCanChangeOwner", function (assert) {
|
||||
const currentUser = User.create({ moderator: false });
|
||||
this.registry.register("current-user:main", currentUser, {
|
||||
instantiate: false,
|
||||
});
|
||||
this.registry.injection("controller", "currentUser", "current-user:main");
|
||||
|
||||
let model = topicWithStream({
|
||||
posts: [
|
||||
{ id: 1, username: "gary" },
|
||||
{ id: 2, username: "lili" },
|
||||
],
|
||||
stream: [1, 2],
|
||||
});
|
||||
model.set("currentUser", { moderator: false });
|
||||
const controller = this.getController("topic", {
|
||||
model,
|
||||
currentUser,
|
||||
siteSettings: {
|
||||
moderators_change_post_ownership: true,
|
||||
},
|
||||
});
|
||||
const selectedPostIds = controller.get("selectedPostIds");
|
||||
|
||||
assert.notOk(
|
||||
controller.get("canChangeOwner"),
|
||||
"false when no posts are selected"
|
||||
);
|
||||
|
||||
selectedPostIds.pushObject(1);
|
||||
|
||||
assert.notOk(controller.get("canChangeOwner"), "false when not moderator");
|
||||
|
||||
currentUser.set("moderator", true);
|
||||
|
||||
assert.ok(
|
||||
controller.get("canChangeOwner"),
|
||||
"true when moderator and one post is selected"
|
||||
);
|
||||
|
||||
selectedPostIds.pushObject(2);
|
||||
|
||||
assert.notOk(
|
||||
controller.get("canChangeOwner"),
|
||||
"false when moderator but more than 1 user"
|
||||
);
|
||||
});
|
||||
|
||||
test("canMergePosts", function (assert) {
|
||||
let model = topicWithStream({
|
||||
posts: [
|
||||
|
|
Loading…
Reference in New Issue