BUGFIX: PMs could be created with a category

BUGFIX: hide category column when displaying the list of private messages
This commit is contained in:
Régis Hanol
2014-01-24 12:57:48 +01:00
parent 0634f3320a
commit 245bc19379
5 changed files with 28 additions and 6 deletions

View File

@@ -7,6 +7,7 @@
@module Discourse @module Discourse
**/ **/
Discourse.UserTopicsListController = Discourse.ObjectController.extend({ Discourse.UserTopicsListController = Discourse.ObjectController.extend({
hideCategory: false,
actions: { actions: {
loadMore: function() { loadMore: function() {

View File

@@ -4,9 +4,12 @@ Discourse.UserTopicListRoute = Discourse.Route.extend({
}, },
setupController: function(controller, model) { setupController: function(controller, model) {
this.controllerFor('user_activity').set('userActionType', this.get('userActionType'));
this.controllerFor('user_topics_list').set('model', model);
this.controllerFor('user').set('indexStream', false); this.controllerFor('user').set('indexStream', false);
this.controllerFor('user_activity').set('userActionType', this.get('userActionType'));
this.controllerFor('user_topics_list').setProperties({
model: model,
hideCategory: false
});
} }
}); });
@@ -20,6 +23,7 @@ function createPMRoute(viewName, path) {
setupController: function() { setupController: function() {
this._super.apply(this, arguments); this._super.apply(this, arguments);
this.controllerFor('user_topics_list').set('hideCategory', true);
this.controllerFor('user').setProperties({ this.controllerFor('user').setProperties({
pmView: viewName, pmView: viewName,
indexStream: false indexStream: false

View File

@@ -1 +1 @@
{{basic-topic-list topicList=model}} {{basic-topic-list topicList=model hideCategory=hideCategory}}

View File

@@ -47,10 +47,20 @@ class TopicCreator
end end
def setup def setup
topic_params = {title: @opts[:title], user_id: @user.id, last_post_user_id: @user.id} topic_params = {
topic_params[:archetype] = @opts[:archetype] if @opts[:archetype].present? title: @opts[:title],
user_id: @user.id,
last_post_user_id: @user.id
}
topic_params[:subtype] = @opts[:subtype] if @opts[:subtype].present? topic_params[:subtype] = @opts[:subtype] if @opts[:subtype].present?
if @opts[:archetype].present?
topic_params[:archetype] = @opts[:archetype]
# PM can't have a category
@opts.delete(:category) if topic_params[:archetype] == Archetype.private_message
end
# Temporary fix to allow older clients to create topics. # Temporary fix to allow older clients to create topics.
# When all clients are updated the category variable should # When all clients are updated the category variable should
# be set directly to the contents of the if statement. # be set directly to the contents of the if statement.
@@ -59,10 +69,13 @@ class TopicCreator
else else
Category.where(name: @opts[:category]).first Category.where(name: @opts[:category]).first
end end
@guardian.ensure_can_create!(Topic,category) @guardian.ensure_can_create!(Topic,category)
topic_params[:category_id] = category.id if category.present? topic_params[:category_id] = category.id if category.present?
topic_params[:meta_data] = @opts[:meta_data] if @opts[:meta_data].present? topic_params[:meta_data] = @opts[:meta_data] if @opts[:meta_data].present?
topic_params[:created_at] = Time.zone.parse(@opts[:created_at].to_s) if @opts[:created_at].present? topic_params[:created_at] = Time.zone.parse(@opts[:created_at].to_s) if @opts[:created_at].present?
topic_params topic_params
end end

View File

@@ -313,13 +313,17 @@ describe PostCreator do
PostCreator.create(user, title: 'hi there welcome to my topic', PostCreator.create(user, title: 'hi there welcome to my topic',
raw: "this is my awesome message @#{unrelated.username_lower}", raw: "this is my awesome message @#{unrelated.username_lower}",
archetype: Archetype.private_message, archetype: Archetype.private_message,
target_usernames: [target_user1.username, target_user2.username].join(',')) target_usernames: [target_user1.username, target_user2.username].join(','),
category: 1)
end end
it 'acts correctly' do it 'acts correctly' do
post.topic.archetype.should == Archetype.private_message post.topic.archetype.should == Archetype.private_message
post.topic.topic_allowed_users.count.should == 3 post.topic.topic_allowed_users.count.should == 3
# PMs can't have a category
post.topic.category.should be_nil
# does not notify an unrelated user # does not notify an unrelated user
unrelated.notifications.count.should == 0 unrelated.notifications.count.should == 0
post.topic.subtype.should == TopicSubtype.user_to_user post.topic.subtype.should == TopicSubtype.user_to_user