FEATURE: allow selecting a tag when moving posts to a new topic (#6074)

This commit is contained in:
Maja Komel 2018-07-06 18:21:00 +02:00 committed by Régis Hanol
parent dca1ba9a4c
commit 7cba4cbcc6
2 changed files with 21 additions and 4 deletions

View File

@ -966,15 +966,21 @@ export default Ember.Controller.extend(BufferedContent, {
canDeselectAll: Ember.computed.alias("selectedAllPosts"), canDeselectAll: Ember.computed.alias("selectedAllPosts"),
@computed( @computed(
"currentUser.staff",
"selectedPostsCount", "selectedPostsCount",
"selectedAllPosts", "selectedAllPosts",
"selectedPosts", "selectedPosts",
"selectedPosts.[]" "selectedPosts.[]"
) )
canDeleteSelected(selectedPostsCount, selectedAllPosts, selectedPosts) { canDeleteSelected(
isStaff,
selectedPostsCount,
selectedAllPosts,
selectedPosts
) {
return ( return (
selectedPostsCount > 0 && selectedPostsCount > 0 &&
(selectedAllPosts || selectedPosts.every(p => p.can_delete)) ((selectedAllPosts && isStaff) || selectedPosts.every(p => p.can_delete))
); );
}, },

View File

@ -209,7 +209,11 @@ QUnit.test("canDeleteSelected", function(assert) {
], ],
stream: [1, 2, 3] stream: [1, 2, 3]
}; };
const currentUser = Discourse.User.create({ admin: false });
this.registry.register("current-user:main", currentUser, {
instantiate: false
});
this.registry.injection("controller", "currentUser", "current-user:main");
const model = Topic.create({ postStream }); const model = Topic.create({ postStream });
const controller = this.subject({ model }); const controller = this.subject({ model });
const selectedPostIds = controller.get("selectedPostIds"); const selectedPostIds = controller.get("selectedPostIds");
@ -235,9 +239,16 @@ QUnit.test("canDeleteSelected", function(assert) {
selectedPostIds.pushObject(1); selectedPostIds.pushObject(1);
assert.not(
controller.get("canDeleteSelected"),
"false when all posts are selected and user is staff"
);
currentUser.set("admin", true);
assert.ok( assert.ok(
controller.get("canDeleteSelected"), controller.get("canDeleteSelected"),
"true when all posts are selected" "true when all posts are selected and user is staff"
); );
}); });