diff --git a/app/assets/javascripts/discourse/controllers/user_topics_list_controller.js b/app/assets/javascripts/discourse/controllers/user_topics_list_controller.js index 2e13d91fd..0d19c9925 100644 --- a/app/assets/javascripts/discourse/controllers/user_topics_list_controller.js +++ b/app/assets/javascripts/discourse/controllers/user_topics_list_controller.js @@ -7,6 +7,7 @@ @module Discourse **/ Discourse.UserTopicsListController = Discourse.ObjectController.extend({ + hideCategory: false, actions: { loadMore: function() { diff --git a/app/assets/javascripts/discourse/routes/user_topic_list_routes.js b/app/assets/javascripts/discourse/routes/user_topic_list_routes.js index e55162b88..47c1c8b38 100644 --- a/app/assets/javascripts/discourse/routes/user_topic_list_routes.js +++ b/app/assets/javascripts/discourse/routes/user_topic_list_routes.js @@ -4,9 +4,12 @@ Discourse.UserTopicListRoute = Discourse.Route.extend({ }, 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_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() { this._super.apply(this, arguments); + this.controllerFor('user_topics_list').set('hideCategory', true); this.controllerFor('user').setProperties({ pmView: viewName, indexStream: false diff --git a/app/assets/javascripts/discourse/templates/list/user_topics_list.js.handlebars b/app/assets/javascripts/discourse/templates/list/user_topics_list.js.handlebars index e7a7e4e3f..05b91a647 100644 --- a/app/assets/javascripts/discourse/templates/list/user_topics_list.js.handlebars +++ b/app/assets/javascripts/discourse/templates/list/user_topics_list.js.handlebars @@ -1 +1 @@ -{{basic-topic-list topicList=model}} +{{basic-topic-list topicList=model hideCategory=hideCategory}} diff --git a/lib/topic_creator.rb b/lib/topic_creator.rb index 20ae7b56b..8acc807f0 100644 --- a/lib/topic_creator.rb +++ b/lib/topic_creator.rb @@ -47,10 +47,20 @@ class TopicCreator end def setup - topic_params = {title: @opts[:title], user_id: @user.id, last_post_user_id: @user.id} - topic_params[:archetype] = @opts[:archetype] if @opts[:archetype].present? + topic_params = { + title: @opts[:title], + user_id: @user.id, + last_post_user_id: @user.id + } + 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. # When all clients are updated the category variable should # be set directly to the contents of the if statement. @@ -59,10 +69,13 @@ class TopicCreator else Category.where(name: @opts[:category]).first end + @guardian.ensure_can_create!(Topic,category) + topic_params[:category_id] = category.id if category.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 end diff --git a/spec/components/post_creator_spec.rb b/spec/components/post_creator_spec.rb index 994b8cd2a..4963dc601 100644 --- a/spec/components/post_creator_spec.rb +++ b/spec/components/post_creator_spec.rb @@ -313,13 +313,17 @@ describe PostCreator do PostCreator.create(user, title: 'hi there welcome to my topic', raw: "this is my awesome message @#{unrelated.username_lower}", 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 it 'acts correctly' do post.topic.archetype.should == Archetype.private_message 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 unrelated.notifications.count.should == 0 post.topic.subtype.should == TopicSubtype.user_to_user