diff --git a/extensions/guardian.rb b/extensions/guardian.rb index 2474b49b..f00cf9e8 100644 --- a/extensions/guardian.rb +++ b/extensions/guardian.rb @@ -9,7 +9,7 @@ module CustomWizardGuardian end def can_create_post?(parent) - result = parent.present? ? wizard_user_can_create_topic_on_category?(parent) : false + result = parent.present? ? wizard_user_can_create_topic_on_category?(parent) : false result || super end @@ -23,7 +23,7 @@ module CustomWizardGuardian def creating_wizard(topic) wizard_id = topic.wizard_created.presence wizard = CustomWizard::Builder.new(wizard_id, @user).build if wizard_id - return wizard.presence + wizard.presence end def wizard_can_create_topic_on_category?(wizard, topic) diff --git a/spec/extensions/guardian_extension_spec.rb b/spec/extensions/guardian_extension_spec.rb index 09edd1d6..50e2ebe4 100644 --- a/spec/extensions/guardian_extension_spec.rb +++ b/spec/extensions/guardian_extension_spec.rb @@ -2,7 +2,7 @@ require_relative '../plugin_helper' describe ::Guardian do - fab!(:user) { + fab!(:user) { Fabricate(:user, name: "Angus", username: 'angus', email: "angus@email.com") } fab!(:category) { Fabricate(:category, name: 'cat1', slug: 'cat-slug') } @@ -65,4 +65,31 @@ describe ::Guardian do expect(user.guardian.send(:wizard_user_can_create_topic_on_category?, topic)).to be_falsey end end + + context "the wizard can't create a topic in the category" do + it "restricts editing the topic first post" do + wizard = CustomWizard::Builder.new(@template[:id], user).build + wizard.create_updater( + wizard.steps.first.id, + step_1_field_1: "Topic Title", + step_1_field_2: "topic body" + ).update + wizard.create_updater(wizard.steps.second.id, {}).update + wizard.create_updater(wizard.steps.last.id, + step_3_field_3: category.id + ).update + + topic = Topic.where( + title: "Topic Title", + category_id: category.id + ).first + + new_category = Fabricate(:category) + topic.category_id = new_category.id + topic.save + topic.reload + + expect(user.guardian.send(:wizard_user_can_create_topic_on_category?, topic)).to be_falsey + end + end end