mirror of
https://github.com/discourse/discourse.git
synced 2025-05-23 07:01:13 +08:00
A trigger when a topic is updated, adds a couple of custom field tests
This commit is contained in:
@ -264,6 +264,9 @@ export default ObjectController.extend(Discourse.SelectedPostsCount, BufferedCon
|
|||||||
props = this.get('buffered.buffer');
|
props = this.get('buffered.buffer');
|
||||||
|
|
||||||
Discourse.Topic.update(this.get('model'), props).then(function() {
|
Discourse.Topic.update(this.get('model'), props).then(function() {
|
||||||
|
// Note we roll back on success here because `update` saves
|
||||||
|
// the properties to the topic.
|
||||||
|
self.rollbackBuffer();
|
||||||
self.set('editingTopic', false);
|
self.set('editingTopic', false);
|
||||||
}).catch(function(error) {
|
}).catch(function(error) {
|
||||||
if (error && error.responseText) {
|
if (error && error.responseText) {
|
||||||
@ -271,10 +274,6 @@ export default ObjectController.extend(Discourse.SelectedPostsCount, BufferedCon
|
|||||||
} else {
|
} else {
|
||||||
bootbox.alert(I18n.t('generic_error'));
|
bootbox.alert(I18n.t('generic_error'));
|
||||||
}
|
}
|
||||||
}).finally(function() {
|
|
||||||
// Note we even roll back on success here because `update` saves
|
|
||||||
// the properties to the topic.
|
|
||||||
self.rollbackBuffer();
|
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -2,6 +2,7 @@ require_dependency 'topic_view'
|
|||||||
require_dependency 'promotion'
|
require_dependency 'promotion'
|
||||||
require_dependency 'url_helper'
|
require_dependency 'url_helper'
|
||||||
require_dependency 'topics_bulk_action'
|
require_dependency 'topics_bulk_action'
|
||||||
|
require_dependency 'discourse_event'
|
||||||
|
|
||||||
class TopicsController < ApplicationController
|
class TopicsController < ApplicationController
|
||||||
include UrlHelper
|
include UrlHelper
|
||||||
@ -134,6 +135,8 @@ class TopicsController < ApplicationController
|
|||||||
success = PostRevisor.new(first_post, topic).revise!(current_user, changes, validate_post: false)
|
success = PostRevisor.new(first_post, topic).revise!(current_user, changes, validate_post: false)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
DiscourseEvent.trigger(:topic_saved, topic, params)
|
||||||
|
|
||||||
# this is used to return the title to the client as it may have been changed by "TextCleaner"
|
# this is used to return the title to the client as it may have been changed by "TextCleaner"
|
||||||
success ? render_serialized(topic, BasicTopicSerializer) : render_json_error(topic)
|
success ? render_serialized(topic, BasicTopicSerializer) : render_json_error(topic)
|
||||||
end
|
end
|
||||||
|
@ -111,10 +111,13 @@ describe HasCustomFields do
|
|||||||
db_item = CustomFieldsTestItem.find(test_item.id)
|
db_item = CustomFieldsTestItem.find(test_item.id)
|
||||||
db_item.custom_fields.should == {"a" => ["b", "c", "d"]}
|
db_item.custom_fields.should == {"a" => ["b", "c", "d"]}
|
||||||
|
|
||||||
db_item.custom_fields["a"] = ["c", "d"]
|
db_item.custom_fields.update('a' => ['c', 'd'])
|
||||||
db_item.save
|
db_item.save
|
||||||
db_item.custom_fields.should == {"a" => ["c", "d"]}
|
db_item.custom_fields.should == {"a" => ["c", "d"]}
|
||||||
|
|
||||||
|
db_item.custom_fields.delete('a')
|
||||||
|
db_item.custom_fields.should == {}
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
it "casts integers in arrays properly without error" do
|
it "casts integers in arrays properly without error" do
|
||||||
|
Reference in New Issue
Block a user