Arpit Jalan 2020-10-06 22:41:55 +05:30 committed by GitHub
parent 340d979357
commit f4c7c7bff3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 54 additions and 1 deletions

View File

@ -68,6 +68,10 @@ addBulkButton("showAppendTagTopics", "append_tags", {
class: "btn-default", class: "btn-default",
enabledSetting: "tagging_enabled", enabledSetting: "tagging_enabled",
}); });
addBulkButton("removeTags", "remove_tags", {
icon: "tag",
class: "btn-danger",
});
addBulkButton("deleteTopics", "delete", { addBulkButton("deleteTopics", "delete", {
icon: "trash-alt", icon: "trash-alt",
class: "btn-danger", class: "btn-danger",
@ -201,6 +205,10 @@ export default Controller.extend(ModalFunctionality, {
resetRead() { resetRead() {
this.performAndRefresh({ type: "reset_read" }); this.performAndRefresh({ type: "reset_read" });
}, },
removeTags() {
this.performAndRefresh({ type: "remove_tags" });
},
}, },
}); });

View File

@ -2177,6 +2177,7 @@ en:
choose_new_tags: "Choose new tags for these topics:" choose_new_tags: "Choose new tags for these topics:"
choose_append_tags: "Choose new tags to append for these topics:" choose_append_tags: "Choose new tags to append for these topics:"
changed_tags: "The tags of those topics were changed." changed_tags: "The tags of those topics were changed."
remove_tags: "Remove Tags"
none: none:
unread: "You have no unread topics." unread: "You have no unread topics."

View File

@ -13,7 +13,8 @@ class TopicsBulkAction
def self.operations def self.operations
@operations ||= %w(change_category close archive change_notification_level @operations ||= %w(change_category close archive change_notification_level
reset_read dismiss_posts delete unlist archive_messages reset_read dismiss_posts delete unlist archive_messages
move_messages_to_inbox change_tags append_tags relist) move_messages_to_inbox change_tags append_tags remove_tags
relist)
end end
def self.register_operation(name, &block) def self.register_operation(name, &block)
@ -176,6 +177,15 @@ class TopicsBulkAction
end end
end end
def remove_tags
topics.each do |t|
if guardian.can_edit?(t)
TopicTag.where(topic_id: t.id).delete_all
@changed_ids << t.id
end
end
end
def guardian def guardian
@guardian ||= Guardian.new(@user) @guardian ||= Guardian.new(@user)
end end

View File

@ -305,4 +305,38 @@ describe TopicsBulkAction do
end end
end end
end end
describe "remove_tags" do
fab!(:tag1) { Fabricate(:tag) }
fab!(:tag2) { Fabricate(:tag) }
before do
SiteSetting.tagging_enabled = true
SiteSetting.min_trust_level_to_tag_topics = 0
topic.tags = [tag1, tag2]
end
it "can remove all tags" do
tba = TopicsBulkAction.new(topic.user, [topic.id], type: 'remove_tags')
topic_ids = tba.perform!
expect(topic_ids).to eq([topic.id])
topic.reload
expect(topic.tags.size).to eq(0)
end
context "when user can't edit topic" do
before do
Guardian.any_instance.expects(:can_edit?).returns(false)
end
it "doesn't remove the tags" do
tba = TopicsBulkAction.new(topic.user, [topic.id], type: 'remove_tags')
topic_ids = tba.perform!
expect(topic_ids).to eq([])
topic.reload
expect(topic.tags.map(&:name)).to contain_exactly(tag1.name, tag2.name)
end
end
end
end end