Skip to content

Commit

Permalink
FEATURE: allow moderators to bulk change ownership (discourse#15997)
Browse files Browse the repository at this point in the history
  • Loading branch information
awesomerobot authored Feb 18, 2022
1 parent efb7e19 commit cd61690
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 2 deletions.
14 changes: 12 additions & 2 deletions app/assets/javascripts/discourse/app/controllers/topic.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
},

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
Expand Down

0 comments on commit cd61690

Please sign in to comment.