From 9eb5fc6ff67372ae1edef9a17af734ac0b9c59e1 Mon Sep 17 00:00:00 2001 From: Angus McLeod Date: Thu, 23 Feb 2023 19:24:11 +0100 Subject: [PATCH 01/28] Complete updates to handle subscription product slugs --- lib/custom_wizard/subscription.rb | 63 +++++----- .../custom_wizard/subscription_spec.rb | 118 ++++++++++-------- spec/fixtures/subscription_client.rb | 39 +++++- spec/plugin_helper.rb | 1 - 4 files changed, 137 insertions(+), 84 deletions(-) diff --git a/lib/custom_wizard/subscription.rb b/lib/custom_wizard/subscription.rb index dfb75324..a8fdf011 100644 --- a/lib/custom_wizard/subscription.rb +++ b/lib/custom_wizard/subscription.rb @@ -1,8 +1,10 @@ # frozen_string_literal: true class CustomWizard::Subscription - STANDARD_PRODUCT_ID = 'prod_MH11woVoZU5AWb' - BUSINESS_PRODUCT_ID = 'prod_MH0wT627okh3Ef' - COMMUNITY_PRODUCT_ID = 'prod_MU7l9EjxhaukZ7' + PRODUCT_HIERARCHY = %w[ + community + standard + business + ] def self.attributes { @@ -99,8 +101,30 @@ class CustomWizard::Subscription } end + attr_accessor :product_id, + :product_slug + def initialize - @subscription = find_subscription + if CustomWizard::Subscription.client_installed? + result = DiscourseSubscriptionClient.find_subscriptions("discourse-custom-wizard") + + if result&.any? + slugs = result.supplier.product_slugs + + if slugs.present? + ids_and_slugs = result.subscriptions.map do |subscription| + { id: subscription.product_id, slug: slugs[subscription.product_id] } + end + + id_and_slug = ids_and_slugs.sort do |a, b| + PRODUCT_HIERARCHY[a[:slug]] - PRODUCT_HIERARCHY[b[:slug]] + end.first + + @product_id = id_and_slug[:id] + @product_slug = id_and_slug[:slug] + end + end + end end def includes?(feature, attribute, value = nil) @@ -140,36 +164,19 @@ class CustomWizard::Subscription end def standard? - @subscription.product_id === STANDARD_PRODUCT_ID + product_slug === "standard" end def business? - @subscription.product_id === BUSINESS_PRODUCT_ID + product_slug === "business" end def community? - @subscription.product_id === COMMUNITY_PRODUCT_ID + product_slug === "community" end - def client_installed? - defined?(SubscriptionClient) == 'constant' && SubscriptionClient.class == Module - end - - def find_subscription - subscription = nil - - if client_installed? - subscription = SubscriptionClientSubscription.active - .where(product_id: [STANDARD_PRODUCT_ID, BUSINESS_PRODUCT_ID, COMMUNITY_PRODUCT_ID]) - .order("product_id = '#{BUSINESS_PRODUCT_ID}' DESC") - .first - end - - unless subscription - subscription = OpenStruct.new(product_id: nil) - end - - subscription + def self.client_installed? + defined?(DiscourseSubscriptionClient) == 'constant' && DiscourseSubscriptionClient.class == Module end def self.subscribed? @@ -192,10 +199,6 @@ class CustomWizard::Subscription new.type end - def self.client_installed? - new.client_installed? - end - def self.includes?(feature, attribute, value) new.includes?(feature, attribute, value) end diff --git a/spec/components/custom_wizard/subscription_spec.rb b/spec/components/custom_wizard/subscription_spec.rb index 2ac191e1..2e29d641 100644 --- a/spec/components/custom_wizard/subscription_spec.rb +++ b/spec/components/custom_wizard/subscription_spec.rb @@ -2,9 +2,19 @@ describe CustomWizard::Subscription do let(:guests_permitted) { get_wizard_fixture("wizard/guests_permitted") } + let!(:business_product_id) { SecureRandom.hex(8) } + let!(:standard_product_id) { SecureRandom.hex(8) } + let!(:community_product_id) { SecureRandom.hex(8) } + let!(:product_slugs) { + { + "#{business_product_id}" => "business", + "#{standard_product_id}" => "standard", + "#{community_product_id}" => "community" + } + } def undefine_client_classes - Object.send(:remove_const, :SubscriptionClient) if Object.constants.include?(:SubscriptionClient) + Object.send(:remove_const, :DiscourseSubscriptionClient) if Object.constants.include?(:DiscourseSubscriptionClient) Object.send(:remove_const, :SubscriptionClientSubscription) if Object.constants.include?(:SubscriptionClientSubscription) end @@ -12,14 +22,6 @@ describe CustomWizard::Subscription do load File.expand_path("#{Rails.root}/plugins/discourse-custom-wizard/spec/fixtures/subscription_client.rb", __FILE__) end - def stub_client_methods - [:active, :where, :order, :first].each do |method| - SubscriptionClientSubscription.stubs(method) - .returns(SubscriptionClientSubscription) - end - SubscriptionClientSubscription.stubs(:product_id).returns(SecureRandom.hex(8)) - end - after do undefine_client_classes end @@ -50,7 +52,6 @@ describe CustomWizard::Subscription do context "with subscription client" do before do define_client_classes - stub_client_methods end it "detects the subscription client" do @@ -58,6 +59,10 @@ describe CustomWizard::Subscription do end context "without a subscription" do + before do + DiscourseSubscriptionClient.stubs(:find_subscriptions).returns(nil) + end + it "has none type" do expect(described_class.type).to eq(:none) end @@ -71,59 +76,70 @@ describe CustomWizard::Subscription do end end - context "with a subscription" do + context "with subscriptions" do + def get_subscription_result(product_id) + result = DiscourseSubscriptionClient::Subscriptions::Result.new + result.supplier = SubscriptionClientSupplier.new(product_slugs) + result.resource = SubscriptionClientResource.new + result.subscriptions = [SubscriptionClientSubscription.new(product_id)] + result + end + let!(:business_subscription_result) { get_subscription_result(business_product_id) } + let!(:standard_subscription_result) { get_subscription_result(standard_product_id) } + let!(:community_subscription_result) { get_subscription_result(community_product_id) } + it "handles mapped values" do - SubscriptionClientSubscription.stubs(:product_id).returns(CustomWizard::Subscription::STANDARD_PRODUCT_ID) + DiscourseSubscriptionClient.stubs(:find_subscriptions).returns(standard_subscription_result) expect(described_class.includes?(:wizard, :permitted, guests_permitted["permitted"])).to eq(true) - SubscriptionClientSubscription.stubs(:product_id).returns(CustomWizard::Subscription::COMMUNITY_PRODUCT_ID) + DiscourseSubscriptionClient.stubs(:find_subscriptions).returns(community_subscription_result) expect(described_class.includes?(:wizard, :permitted, guests_permitted["permitted"])).to eq(false) end - end - context "with standard subscription" do - before do - SubscriptionClientSubscription.stubs(:product_id).returns(CustomWizard::Subscription::STANDARD_PRODUCT_ID) + context "with a standard subscription" do + before do + DiscourseSubscriptionClient.stubs(:find_subscriptions).returns(standard_subscription_result) + end + + it "detects standard type" do + expect(described_class.type).to eq(:standard) + end + + it "standard features are included" do + expect(described_class.includes?(:wizard, :type, 'send_message')).to eq(true) + end + + it "business features are not included" do + expect(described_class.includes?(:action, :type, 'create_category')).to eq(false) + end end - it "detects standard type" do - expect(described_class.type).to eq(:standard) + context "with a business subscription" do + before do + DiscourseSubscriptionClient.stubs(:find_subscriptions).returns(business_subscription_result) + end + + it "detects business type" do + expect(described_class.type).to eq(:business) + end + + it "business features are included" do + expect(described_class.includes?(:action, :type, 'create_category')).to eq(true) + end end - it "standard features are included" do - expect(described_class.includes?(:wizard, :type, 'send_message')).to eq(true) - end + context "with a community subscription" do + before do + DiscourseSubscriptionClient.stubs(:find_subscriptions).returns(community_subscription_result) + end - it "business features are not included" do - expect(described_class.includes?(:action, :type, 'create_category')).to eq(false) - end - end + it "detects community type" do + expect(described_class.type).to eq(:community) + end - context "with business subscription" do - before do - SubscriptionClientSubscription.stubs(:product_id).returns(CustomWizard::Subscription::BUSINESS_PRODUCT_ID) - end - - it "detects business type" do - expect(described_class.type).to eq(:business) - end - - it "business features are included" do - expect(described_class.includes?(:action, :type, 'create_category')).to eq(true) - end - end - - context "with community subscription" do - before do - SubscriptionClientSubscription.stubs(:product_id).returns(CustomWizard::Subscription::COMMUNITY_PRODUCT_ID) - end - - it "detects community type" do - expect(described_class.type).to eq(:community) - end - - it "community features are included" do - expect(described_class.includes?(:action, :type, 'create_category')).to eq(true) + it "community features are included" do + expect(described_class.includes?(:action, :type, 'create_category')).to eq(true) + end end end end diff --git a/spec/fixtures/subscription_client.rb b/spec/fixtures/subscription_client.rb index a041b507..f495a796 100644 --- a/spec/fixtures/subscription_client.rb +++ b/spec/fixtures/subscription_client.rb @@ -1,4 +1,39 @@ # frozen_string_literal: true -module SubscriptionClient; end -class SubscriptionClientSubscription; end +module DiscourseSubscriptionClient + def self.find_subscriptions(resource_name) + end +end + +class SubscriptionClientSupplier + attr_reader :product_slugs + + def initialize(product_slugs) + @product_slugs = product_slugs + end +end + +class SubscriptionClientResource +end + +class SubscriptionClientSubscription + attr_reader :product_id + + def initialize(product_id) + @product_id = product_id + end +end + +module DiscourseSubscriptionClient + class Subscriptions + class Result + attr_accessor :supplier, + :resource, + :subscriptions + + def any? + supplier.present? && resource.present? && subscriptions.present? + end + end + end +end diff --git a/spec/plugin_helper.rb b/spec/plugin_helper.rb index a0189de1..5334c1fa 100644 --- a/spec/plugin_helper.rb +++ b/spec/plugin_helper.rb @@ -9,7 +9,6 @@ def get_wizard_fixture(path) end def enable_subscription(type) - CustomWizard::Subscription.stubs(:client_installed?).returns(true) CustomWizard::Subscription.stubs("#{type}?".to_sym).returns(true) CustomWizard::Subscription.any_instance.stubs("#{type}?".to_sym).returns(true) end From dfc23978ae77d0c9655cba17dd44692611186015 Mon Sep 17 00:00:00 2001 From: Angus McLeod Date: Thu, 23 Feb 2023 19:25:52 +0100 Subject: [PATCH 02/28] Bump version --- plugin.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin.rb b/plugin.rb index 1bbd8f8e..3a65d315 100644 --- a/plugin.rb +++ b/plugin.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true # name: discourse-custom-wizard # about: Forms for Discourse. Better onboarding, structured posting, data enrichment, automated actions and much more. -# version: 2.2.1 +# version: 2.3.0 # authors: Angus McLeod, Faizaan Gagan, Robert Barrow, Keegan George, Kaitlin Maddever # url: https://github.com/paviliondev/discourse-custom-wizard # contact_emails: development@pavilion.tech From bc81ca89aa3a280aec5d29fb3b79dfbfc9b115c3 Mon Sep 17 00:00:00 2001 From: Angus McLeod Date: Thu, 23 Feb 2023 21:23:38 +0100 Subject: [PATCH 03/28] Update workflow --- .github/workflows/discourse-plugin.yml | 11 ++ .github/workflows/plugin-linting.yml | 54 ---------- .github/workflows/plugin-tests.yml | 136 ------------------------- 3 files changed, 11 insertions(+), 190 deletions(-) create mode 100644 .github/workflows/discourse-plugin.yml delete mode 100644 .github/workflows/plugin-linting.yml delete mode 100644 .github/workflows/plugin-tests.yml diff --git a/.github/workflows/discourse-plugin.yml b/.github/workflows/discourse-plugin.yml new file mode 100644 index 00000000..f5cf62e5 --- /dev/null +++ b/.github/workflows/discourse-plugin.yml @@ -0,0 +1,11 @@ +name: Discourse Plugin + +on: + push: + branches: + - main + pull_request: + +jobs: + ci: + uses: discourse/.github/.github/workflows/discourse-plugin.yml@v1 diff --git a/.github/workflows/plugin-linting.yml b/.github/workflows/plugin-linting.yml deleted file mode 100644 index acb85230..00000000 --- a/.github/workflows/plugin-linting.yml +++ /dev/null @@ -1,54 +0,0 @@ -name: Linting - -on: - push: - branches: - - main - - stable - pull_request: - -concurrency: - group: plugin-linting-${{ format('{0}-{1}', github.head_ref || github.run_number, github.job) }} - cancel-in-progress: true - -jobs: - build: - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v3 - - - name: Set up Node.js - uses: actions/setup-node@v3 - with: - node-version: 16 - cache: yarn - - - name: Yarn install - run: yarn install - - - name: Set up ruby - uses: ruby/setup-ruby@v1 - with: - ruby-version: 2.7 - bundler-cache: true - - - name: ESLint - if: ${{ always() }} - run: yarn eslint --ext .js,.js.es6 --no-error-on-unmatched-pattern {test,assets}/javascripts - - - name: Prettier - if: ${{ always() }} - shell: bash - run: | - yarn prettier -v - if [ 0 -lt $(find assets -type f \( -name "*.scss" -or -name "*.js" -or -name "*.es6" \) 2> /dev/null | wc -l) ]; then - yarn prettier --list-different "assets/**/*.{scss,js,es6}" - fi - if [ 0 -lt $(find test -type f \( -name "*.js" -or -name "*.es6" \) 2> /dev/null | wc -l) ]; then - yarn prettier --list-different "test/**/*.{js,es6}" - fi - - - name: Rubocop - if: ${{ always() }} - run: bundle exec rubocop . diff --git a/.github/workflows/plugin-tests.yml b/.github/workflows/plugin-tests.yml deleted file mode 100644 index f58f1b64..00000000 --- a/.github/workflows/plugin-tests.yml +++ /dev/null @@ -1,136 +0,0 @@ -name: Plugin Tests - -on: - push: - branches: - - main - - stable - pull_request: - -concurrency: - group: tests-${{ format('{0}-{1}', github.head_ref || github.run_number, github.job) }} - cancel-in-progress: true - -jobs: - build: - name: ${{ matrix.build_type }} - runs-on: ubuntu-latest - container: discourse/discourse_test:slim${{ startsWith(matrix.build_type, 'frontend') && '-browsers' || '' }} - timeout-minutes: 30 - - env: - DISCOURSE_HOSTNAME: www.example.com - RUBY_GLOBAL_METHOD_CACHE_SIZE: 131072 - RAILS_ENV: test - PGUSER: discourse - PGPASSWORD: discourse - - strategy: - fail-fast: false - - matrix: - build_type: ["backend", "frontend"] - - steps: - - uses: actions/checkout@v3 - with: - repository: discourse/discourse - fetch-depth: 1 - - - name: Install plugin - uses: actions/checkout@v3 - with: - path: plugins/${{ github.event.repository.name }} - fetch-depth: 1 - - - name: Setup Git - run: | - git config --global user.email "ci@ci.invalid" - git config --global user.name "Discourse CI" - - - name: Start redis - run: | - redis-server /etc/redis/redis.conf & - - - name: Start Postgres - run: | - chown -R postgres /var/run/postgresql - sudo -E -u postgres script/start_test_db.rb - sudo -u postgres psql -c "CREATE ROLE $PGUSER LOGIN SUPERUSER PASSWORD '$PGPASSWORD';" - - - name: Bundler cache - uses: actions/cache@v3 - with: - path: vendor/bundle - key: ${{ runner.os }}-gem-${{ hashFiles('**/Gemfile.lock') }} - restore-keys: | - ${{ runner.os }}-gem- - - - name: Setup gems - run: | - gem install bundler --conservative -v $(awk '/BUNDLED WITH/ { getline; gsub(/ /,""); print $0 }' Gemfile.lock) - bundle config --local path vendor/bundle - bundle config --local deployment true - bundle config --local without development - bundle install --jobs 4 - bundle clean - - - name: Lint English locale - if: matrix.build_type == 'backend' - run: bundle exec ruby script/i18n_lint.rb "plugins/${{ github.event.repository.name }}/locales/{client,server}.en.yml" - - - name: Get yarn cache directory - id: yarn-cache-dir - run: echo "::set-output name=dir::$(yarn cache dir)" - - - name: Yarn cache - uses: actions/cache@v3 - id: yarn-cache - with: - path: ${{ steps.yarn-cache-dir.outputs.dir }} - key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }} - restore-keys: | - ${{ runner.os }}-yarn- - - - name: Yarn install - run: yarn install - - - name: Fetch app state cache - uses: actions/cache@v3 - id: app-cache - with: - path: tmp/app-cache - key: >- - ${{ hashFiles('.github/workflows/tests.yml') }}- - ${{ hashFiles('db/**/*', 'plugins/**/db/**/*') }}- - - - name: Restore database from cache - if: steps.app-cache.outputs.cache-hit == 'true' - run: psql -f tmp/app-cache/cache.sql postgres - - - name: Restore uploads from cache - if: steps.app-cache.outputs.cache-hit == 'true' - run: rm -rf public/uploads && cp -r tmp/app-cache/uploads public/uploads - - - name: Create and migrate database - if: steps.app-cache.outputs.cache-hit != 'true' - run: | - bin/rake db:create - bin/rake db:migrate - - - name: Dump database for cache - if: steps.app-cache.outputs.cache-hit != 'true' - run: mkdir -p tmp/app-cache && pg_dumpall > tmp/app-cache/cache.sql - - - name: Dump uploads for cache - if: steps.app-cache.outputs.cache-hit != 'true' - run: rm -rf tmp/app-cache/uploads && cp -r public/uploads tmp/app-cache/uploads - - - name: Plugin RSpec - if: matrix.build_type == 'backend' - run: bin/rake plugin:spec[${{ github.event.repository.name }}] - - - name: Plugin QUnit - if: matrix.build_type == 'frontend' - run: QUNIT_EMBER_CLI=1 bundle exec rake plugin:qunit['${{ github.event.repository.name }}','1200000'] - timeout-minutes: 10 From da6e75faca1d50929f42f941beb297b7aff11843 Mon Sep 17 00:00:00 2001 From: Angus McLeod Date: Fri, 24 Feb 2023 14:17:00 +0100 Subject: [PATCH 04/28] Fix admin index --- app/controllers/custom_wizard/admin/admin.rb | 2 +- .../custom_wizard/subscription_spec.rb | 1 + .../admin/admin_controller_spec.rb | 39 ++++++++++++++++ .../admin/submissions_controller_spec.rb | 46 ------------------- 4 files changed, 41 insertions(+), 47 deletions(-) create mode 100644 spec/requests/custom_wizard/admin/admin_controller_spec.rb delete mode 100644 spec/requests/custom_wizard/admin/submissions_controller_spec.rb diff --git a/app/controllers/custom_wizard/admin/admin.rb b/app/controllers/custom_wizard/admin/admin.rb index 867be56c..aa8862b6 100644 --- a/app/controllers/custom_wizard/admin/admin.rb +++ b/app/controllers/custom_wizard/admin/admin.rb @@ -8,7 +8,7 @@ class CustomWizard::AdminController < ::Admin::AdminController subscribed: subcription.subscribed?, subscription_type: subcription.type, subscription_attributes: CustomWizard::Subscription.attributes, - subscription_client_installed: subcription.client_installed? + subscription_client_installed: CustomWizard::Subscription.client_installed? ) end diff --git a/spec/components/custom_wizard/subscription_spec.rb b/spec/components/custom_wizard/subscription_spec.rb index 2e29d641..461c97c9 100644 --- a/spec/components/custom_wizard/subscription_spec.rb +++ b/spec/components/custom_wizard/subscription_spec.rb @@ -27,6 +27,7 @@ describe CustomWizard::Subscription do end it "detects the subscription client" do + undefine_client_classes expect(described_class.client_installed?).to eq(false) end diff --git a/spec/requests/custom_wizard/admin/admin_controller_spec.rb b/spec/requests/custom_wizard/admin/admin_controller_spec.rb new file mode 100644 index 00000000..6a7d721c --- /dev/null +++ b/spec/requests/custom_wizard/admin/admin_controller_spec.rb @@ -0,0 +1,39 @@ +# frozen_string_literal: true + +describe CustomWizard::AdminController do + fab!(:admin_user) { Fabricate(:user, admin: true) } + + it "requires an admin" do + get "/admin/wizards.json" + expect(response.status).to eq(404) + end + + context "with an admin" do + before do + sign_in(admin_user) + end + + context "without a subscription" do + it "returns the right subscription details" do + get "/admin/wizards.json" + expect(response.parsed_body["subscribed"]).to eq(false) + expect(response.parsed_body["subscription_attributes"]).to eq(CustomWizard::Subscription.attributes.as_json) + expect(response.parsed_body["subscription_client_installed"]).to eq(false) + end + end + + context "with a subscription" do + before do + enable_subscription("standard") + load File.expand_path("#{Rails.root}/plugins/discourse-custom-wizard/spec/fixtures/subscription_client.rb", __FILE__) + end + + it "returns the right subscription details" do + get "/admin/wizards.json" + expect(response.parsed_body["subscribed"]).to eq(true) + expect(response.parsed_body["subscription_type"]).to eq("standard") + expect(response.parsed_body["subscription_client_installed"]).to eq(true) + end + end + end +end diff --git a/spec/requests/custom_wizard/admin/submissions_controller_spec.rb b/spec/requests/custom_wizard/admin/submissions_controller_spec.rb deleted file mode 100644 index 3c740c85..00000000 --- a/spec/requests/custom_wizard/admin/submissions_controller_spec.rb +++ /dev/null @@ -1,46 +0,0 @@ -# frozen_string_literal: true - -describe CustomWizard::AdminSubmissionsController do - fab!(:admin_user) { Fabricate(:user, admin: true) } - fab!(:user1) { Fabricate(:user) } - fab!(:user2) { Fabricate(:user) } - fab!(:user3) { Fabricate(:user) } - - let(:template) { get_wizard_fixture("wizard") } - let(:template_2) { - temp = template.dup - temp["id"] = "super_mega_fun_wizard_2" - temp - } - - before do - CustomWizard::Template.save(template, skip_jobs: true) - CustomWizard::Template.save(template_2, skip_jobs: true) - - wizard1 = CustomWizard::Wizard.create(template["id"], user1) - wizard2 = CustomWizard::Wizard.create(template["id"], user2) - wizard3 = CustomWizard::Wizard.create(template_2["id"], user3) - - CustomWizard::Submission.new(wizard1, step_1_field_1: "I am a user1's submission").save - CustomWizard::Submission.new(wizard2, step_1_field_1: "I am a user2's submission").save - CustomWizard::Submission.new(wizard3, step_1_field_1: "I am a user3's submission").save - - sign_in(admin_user) - end - - it "returns a list of wizards" do - get "/admin/wizards/submissions.json" - expect(response.parsed_body.length).to eq(2) - expect(response.parsed_body.first['id']).to eq(template['id']) - end - - it "returns users' submissions for a wizard" do - get "/admin/wizards/submissions/#{template['id']}.json" - expect(response.parsed_body['submissions'].length).to eq(2) - end - - it "downloads submissions" do - get "/admin/wizards/submissions/#{template_2['id']}/download" - expect(response.parsed_body.length).to eq(1) - end -end From aef9ed24ae9b76b76abd12b498386352cf019ad6 Mon Sep 17 00:00:00 2001 From: Angus McLeod Date: Fri, 24 Feb 2023 14:27:08 +0100 Subject: [PATCH 05/28] Change problematic Dir.exists? --- spec/requests/custom_wizard/admin/manager_controller_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/requests/custom_wizard/admin/manager_controller_spec.rb b/spec/requests/custom_wizard/admin/manager_controller_spec.rb index 30c1aa3a..9f070458 100644 --- a/spec/requests/custom_wizard/admin/manager_controller_spec.rb +++ b/spec/requests/custom_wizard/admin/manager_controller_spec.rb @@ -13,7 +13,7 @@ describe CustomWizard::AdminManagerController do template_3["id"] = 'super_mega_fun_wizard_3' @template_array = [template, template_2, template_3] - FileUtils.mkdir_p(file_from_fixtures_tmp_folder) unless Dir.exists?(file_from_fixtures_tmp_folder) + FileUtils.mkdir_p(file_from_fixtures_tmp_folder) unless File.directory?(file_from_fixtures_tmp_folder) @tmp_file_path = File.join(file_from_fixtures_tmp_folder, SecureRandom.hex << 'wizards.json') File.write(@tmp_file_path, @template_array.to_json) end From 762ddfa16ef8d647181c4fddc782b82310800808 Mon Sep 17 00:00:00 2001 From: Angus McLeod Date: Mon, 6 Mar 2023 10:00:52 +0100 Subject: [PATCH 06/28] FIX: Ensure tag_groups is in wizard schema --- assets/javascripts/discourse/lib/wizard-schema.js.es6 | 1 + 1 file changed, 1 insertion(+) diff --git a/assets/javascripts/discourse/lib/wizard-schema.js.es6 b/assets/javascripts/discourse/lib/wizard-schema.js.es6 index dcb60a0e..24695d15 100644 --- a/assets/javascripts/discourse/lib/wizard-schema.js.es6 +++ b/assets/javascripts/discourse/lib/wizard-schema.js.es6 @@ -72,6 +72,7 @@ const field = { required: null, type: null, condition: null, + tag_groups: null }, types: {}, mapped: ["prefill", "content", "condition", "index"], From 2114b80185bfc5b1fa42ea195e6be7cab2899d66 Mon Sep 17 00:00:00 2001 From: Angus McLeod Date: Mon, 3 Apr 2023 12:37:09 +1000 Subject: [PATCH 07/28] Add wizard-subscription-selector support to field type selection --- assets/javascripts/discourse/lib/wizard-schema.js.es6 | 1 + .../templates/components/wizard-custom-field.hbs | 9 ++++++--- .../templates/components/wizard-custom-step.hbs | 1 + 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/assets/javascripts/discourse/lib/wizard-schema.js.es6 b/assets/javascripts/discourse/lib/wizard-schema.js.es6 index 24bda1d3..47257d82 100644 --- a/assets/javascripts/discourse/lib/wizard-schema.js.es6 +++ b/assets/javascripts/discourse/lib/wizard-schema.js.es6 @@ -244,6 +244,7 @@ const custom_field = { export function buildFieldTypes(types) { wizardSchema.field.types = types; + wizardSchema.field.type = Object.keys(types); } field.type = Object.keys(field.types); diff --git a/assets/javascripts/discourse/templates/components/wizard-custom-field.hbs b/assets/javascripts/discourse/templates/components/wizard-custom-field.hbs index 6273f9a9..26f6051f 100644 --- a/assets/javascripts/discourse/templates/components/wizard-custom-field.hbs +++ b/assets/javascripts/discourse/templates/components/wizard-custom-field.hbs @@ -56,13 +56,16 @@
- {{combo-box + {{wizard-subscription-selector value=field.type - content=fieldTypes + feature="field" + attribute="type" onChange=(action "changeType") + wizard=wizard options=(hash none="admin.wizard.select_type" - )}} + ) + }}
diff --git a/assets/javascripts/discourse/templates/components/wizard-custom-step.hbs b/assets/javascripts/discourse/templates/components/wizard-custom-step.hbs index 40ac09e0..431c3ae3 100644 --- a/assets/javascripts/discourse/templates/components/wizard-custom-step.hbs +++ b/assets/javascripts/discourse/templates/components/wizard-custom-step.hbs @@ -111,6 +111,7 @@ {{wizard-custom-field field=field step=step + wizard=wizard currentFieldId=currentField.id fieldTypes=fieldTypes removeField="removeField" From b035ab9168562434e319e85bfe756877b4b50167 Mon Sep 17 00:00:00 2001 From: Angus McLeod Date: Mon, 3 Apr 2023 12:39:14 +1000 Subject: [PATCH 08/28] Bump version --- plugin.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin.rb b/plugin.rb index 4e7c8aef..5cf05651 100644 --- a/plugin.rb +++ b/plugin.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true # name: discourse-custom-wizard # about: Forms for Discourse. Better onboarding, structured posting, data enrichment, automated actions and much more. -# version: 2.2.20 +# version: 2.2.21 # authors: Angus McLeod, Faizaan Gagan, Robert Barrow, Keegan George, Kaitlin Maddever # url: https://github.com/paviliondev/discourse-custom-wizard # contact_emails: development@pavilion.tech From 2423e9afb7c89587888e9c2c9e397491482cb81e Mon Sep 17 00:00:00 2001 From: Angus McLeod Date: Mon, 3 Apr 2023 15:08:02 +1000 Subject: [PATCH 09/28] Bump version --- plugin.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin.rb b/plugin.rb index 5cf05651..ab596540 100644 --- a/plugin.rb +++ b/plugin.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true # name: discourse-custom-wizard # about: Forms for Discourse. Better onboarding, structured posting, data enrichment, automated actions and much more. -# version: 2.2.21 +# version: 2.3.1 # authors: Angus McLeod, Faizaan Gagan, Robert Barrow, Keegan George, Kaitlin Maddever # url: https://github.com/paviliondev/discourse-custom-wizard # contact_emails: development@pavilion.tech From cff6796d7c53ef421009250fd97a0e661ef16297 Mon Sep 17 00:00:00 2001 From: Robert <35533304+merefield@users.noreply.github.com> Date: Mon, 17 Apr 2023 16:55:15 +0100 Subject: [PATCH 10/28] Change server meta URL temporarily for test scenario --- plugin.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin.rb b/plugin.rb index 3a65d315..eb156743 100644 --- a/plugin.rb +++ b/plugin.rb @@ -5,7 +5,7 @@ # authors: Angus McLeod, Faizaan Gagan, Robert Barrow, Keegan George, Kaitlin Maddever # url: https://github.com/paviliondev/discourse-custom-wizard # contact_emails: development@pavilion.tech -# subscription_url: https://coop.pavilion.tech +# subscription_url: https://test2.pavilion.tech gem 'liquid', '5.0.1', require: true register_asset 'stylesheets/common/admin.scss' From 32a8dcf19fa555fa2a8867d7dc9b7cc3025957d9 Mon Sep 17 00:00:00 2001 From: Angus McLeod Date: Fri, 28 Apr 2023 16:15:48 +0200 Subject: [PATCH 11/28] Add cron schedule to Custom Wizard workflow --- .github/workflows/discourse-plugin.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/discourse-plugin.yml b/.github/workflows/discourse-plugin.yml index f5cf62e5..13850e3e 100644 --- a/.github/workflows/discourse-plugin.yml +++ b/.github/workflows/discourse-plugin.yml @@ -5,6 +5,8 @@ on: branches: - main pull_request: + schedule: + - cron: "0 0 * * *" jobs: ci: From caab850127c8e63a8cd9813455fcc6d585423cb1 Mon Sep 17 00:00:00 2001 From: merefield Date: Mon, 1 May 2023 21:49:44 +0100 Subject: [PATCH 12/28] FIX: failing log spec --- lib/custom_wizard/log.rb | 4 ++-- spec/serializers/custom_wizard/log_serializer_spec.rb | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/custom_wizard/log.rb b/lib/custom_wizard/log.rb index cb5b78c7..ed9624e1 100644 --- a/lib/custom_wizard/log.rb +++ b/lib/custom_wizard/log.rb @@ -15,13 +15,13 @@ class CustomWizard::Log @username = attrs['username'] end - def self.create(wizard_id, action, username, message) + def self.create(wizard_id, action, username, message, date = Time.now) log_id = SecureRandom.hex(12) PluginStore.set('custom_wizard_log', log_id.to_s, { - date: Time.now, + date: date, wizard_id: wizard_id, action: action, username: username, diff --git a/spec/serializers/custom_wizard/log_serializer_spec.rb b/spec/serializers/custom_wizard/log_serializer_spec.rb index 7dd1db0f..cad4a85b 100644 --- a/spec/serializers/custom_wizard/log_serializer_spec.rb +++ b/spec/serializers/custom_wizard/log_serializer_spec.rb @@ -4,7 +4,7 @@ describe CustomWizard::LogSerializer do fab!(:user) { Fabricate(:user) } it 'should return log attributes' do - CustomWizard::Log.create('first-test-wizard', 'perform_first_action', 'first_test_user', 'First log message') + CustomWizard::Log.create('first-test-wizard', 'perform_first_action', 'first_test_user', 'First log message', 1.day.ago) CustomWizard::Log.create('second-test-wizard', 'perform_second_action', 'second_test_user', 'Second log message') json_array = ActiveModel::ArraySerializer.new( From 8b443e0f087614fc6d7b60fd7cda40e691717df0 Mon Sep 17 00:00:00 2001 From: merefield Date: Mon, 1 May 2023 21:52:10 +0100 Subject: [PATCH 13/28] bump patch --- plugin.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin.rb b/plugin.rb index ab596540..8d5d1a89 100644 --- a/plugin.rb +++ b/plugin.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true # name: discourse-custom-wizard # about: Forms for Discourse. Better onboarding, structured posting, data enrichment, automated actions and much more. -# version: 2.3.1 +# version: 2.3.2 # authors: Angus McLeod, Faizaan Gagan, Robert Barrow, Keegan George, Kaitlin Maddever # url: https://github.com/paviliondev/discourse-custom-wizard # contact_emails: development@pavilion.tech From 4c784d98e6c76c22d201ef1fa26977ffc66cb418 Mon Sep 17 00:00:00 2001 From: Angus McLeod Date: Wed, 3 May 2023 11:01:54 +0200 Subject: [PATCH 14/28] Add not equals support to mapper --- .../discourse/lib/wizard-mapper.js.es6 | 1 + config/locales/client.en.yml | 1 + lib/custom_wizard/mapper.rb | 1 + plugin.rb | 2 +- spec/components/custom_wizard/mapper_spec.rb | 13 +++++++++++++ spec/fixtures/mapper/inputs.json | 15 +++++++++++++++ 6 files changed, 32 insertions(+), 1 deletion(-) diff --git a/assets/javascripts/discourse/lib/wizard-mapper.js.es6 b/assets/javascripts/discourse/lib/wizard-mapper.js.es6 index c398eaf4..9037bec5 100644 --- a/assets/javascripts/discourse/lib/wizard-mapper.js.es6 +++ b/assets/javascripts/discourse/lib/wizard-mapper.js.es6 @@ -35,6 +35,7 @@ function inputTypesContent(options = {}) { const connectors = { pair: [ "equal", + "not_equal", "greater", "less", "greater_or_equal", diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml index 8a856636..98519335 100644 --- a/config/locales/client.en.yml +++ b/config/locales/client.en.yml @@ -324,6 +324,7 @@ en: then: "then" set: "set" equal: '=' + not_equal: '!=' greater: '>' less: '<' greater_or_equal: '>=' diff --git a/lib/custom_wizard/mapper.rb b/lib/custom_wizard/mapper.rb index 4e18ad01..66a10736 100644 --- a/lib/custom_wizard/mapper.rb +++ b/lib/custom_wizard/mapper.rb @@ -30,6 +30,7 @@ class CustomWizard::Mapper OPERATORS = { equal: '==', + not_equal: "!=", greater: '>', less: '<', greater_or_equal: '>=', diff --git a/plugin.rb b/plugin.rb index 8d5d1a89..b90e0965 100644 --- a/plugin.rb +++ b/plugin.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true # name: discourse-custom-wizard # about: Forms for Discourse. Better onboarding, structured posting, data enrichment, automated actions and much more. -# version: 2.3.2 +# version: 2.3.3 # authors: Angus McLeod, Faizaan Gagan, Robert Barrow, Keegan George, Kaitlin Maddever # url: https://github.com/paviliondev/discourse-custom-wizard # contact_emails: development@pavilion.tech diff --git a/spec/components/custom_wizard/mapper_spec.rb b/spec/components/custom_wizard/mapper_spec.rb index 510632a9..3e0e6ce6 100644 --- a/spec/components/custom_wizard/mapper_spec.rb +++ b/spec/components/custom_wizard/mapper_spec.rb @@ -291,6 +291,19 @@ describe CustomWizard::Mapper do end end + it "handles not equal pairs" do + expect(CustomWizard::Mapper.new( + inputs: inputs['not_equals_pair'], + data: data, + user: user1 + ).perform).to eq(true) + expect(CustomWizard::Mapper.new( + inputs: inputs['not_equals_pair'], + data: data, + user: user2 + ).perform).to eq(false) + end + it "handles greater than pairs" do expect(CustomWizard::Mapper.new( inputs: inputs['greater_than_pair'], diff --git a/spec/fixtures/mapper/inputs.json b/spec/fixtures/mapper/inputs.json index 3fd406a4..2ef81a28 100644 --- a/spec/fixtures/mapper/inputs.json +++ b/spec/fixtures/mapper/inputs.json @@ -195,6 +195,21 @@ ] } ], + "not_equals_pair": [ + { + "type": "validation", + "pairs": [ + { + "index": 0, + "key": "trust_level", + "key_type": "user_field", + "value": "1", + "value_type": "text", + "connector": "not_equal" + } + ] + } + ], "greater_than_pair": [ { "type": "validation", From 92fe9db1e03b86b931cf459953ada1742868f12d Mon Sep 17 00:00:00 2001 From: Angus McLeod Date: Thu, 4 May 2023 15:18:34 +0200 Subject: [PATCH 15/28] Change subscription_url back --- plugin.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin.rb b/plugin.rb index eb156743..3a65d315 100644 --- a/plugin.rb +++ b/plugin.rb @@ -5,7 +5,7 @@ # authors: Angus McLeod, Faizaan Gagan, Robert Barrow, Keegan George, Kaitlin Maddever # url: https://github.com/paviliondev/discourse-custom-wizard # contact_emails: development@pavilion.tech -# subscription_url: https://test2.pavilion.tech +# subscription_url: https://coop.pavilion.tech gem 'liquid', '5.0.1', require: true register_asset 'stylesheets/common/admin.scss' From 3ea19e1086f20a98dab35e7751c91856a73306d3 Mon Sep 17 00:00:00 2001 From: Angus McLeod Date: Thu, 4 May 2023 15:49:04 +0200 Subject: [PATCH 16/28] Add support for server products PR in isolation --- lib/custom_wizard/subscription.rb | 4 ++-- .../custom_wizard/subscription_spec.rb | 16 ++++++++-------- spec/fixtures/subscription_client.rb | 4 ++-- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/lib/custom_wizard/subscription.rb b/lib/custom_wizard/subscription.rb index a8fdf011..e9218479 100644 --- a/lib/custom_wizard/subscription.rb +++ b/lib/custom_wizard/subscription.rb @@ -106,7 +106,7 @@ class CustomWizard::Subscription def initialize if CustomWizard::Subscription.client_installed? - result = DiscourseSubscriptionClient.find_subscriptions("discourse-custom-wizard") + result = SubscriptionClient.find_subscriptions("discourse-custom-wizard") if result&.any? slugs = result.supplier.product_slugs @@ -176,7 +176,7 @@ class CustomWizard::Subscription end def self.client_installed? - defined?(DiscourseSubscriptionClient) == 'constant' && DiscourseSubscriptionClient.class == Module + defined?(SubscriptionClient) == 'constant' && SubscriptionClient.class == Module end def self.subscribed? diff --git a/spec/components/custom_wizard/subscription_spec.rb b/spec/components/custom_wizard/subscription_spec.rb index 461c97c9..a296dc6a 100644 --- a/spec/components/custom_wizard/subscription_spec.rb +++ b/spec/components/custom_wizard/subscription_spec.rb @@ -14,7 +14,7 @@ describe CustomWizard::Subscription do } def undefine_client_classes - Object.send(:remove_const, :DiscourseSubscriptionClient) if Object.constants.include?(:DiscourseSubscriptionClient) + Object.send(:remove_const, :SubscriptionClient) if Object.constants.include?(:SubscriptionClient) Object.send(:remove_const, :SubscriptionClientSubscription) if Object.constants.include?(:SubscriptionClientSubscription) end @@ -61,7 +61,7 @@ describe CustomWizard::Subscription do context "without a subscription" do before do - DiscourseSubscriptionClient.stubs(:find_subscriptions).returns(nil) + SubscriptionClient.stubs(:find_subscriptions).returns(nil) end it "has none type" do @@ -79,7 +79,7 @@ describe CustomWizard::Subscription do context "with subscriptions" do def get_subscription_result(product_id) - result = DiscourseSubscriptionClient::Subscriptions::Result.new + result = SubscriptionClient::Subscriptions::Result.new result.supplier = SubscriptionClientSupplier.new(product_slugs) result.resource = SubscriptionClientResource.new result.subscriptions = [SubscriptionClientSubscription.new(product_id)] @@ -90,16 +90,16 @@ describe CustomWizard::Subscription do let!(:community_subscription_result) { get_subscription_result(community_product_id) } it "handles mapped values" do - DiscourseSubscriptionClient.stubs(:find_subscriptions).returns(standard_subscription_result) + SubscriptionClient.stubs(:find_subscriptions).returns(standard_subscription_result) expect(described_class.includes?(:wizard, :permitted, guests_permitted["permitted"])).to eq(true) - DiscourseSubscriptionClient.stubs(:find_subscriptions).returns(community_subscription_result) + SubscriptionClient.stubs(:find_subscriptions).returns(community_subscription_result) expect(described_class.includes?(:wizard, :permitted, guests_permitted["permitted"])).to eq(false) end context "with a standard subscription" do before do - DiscourseSubscriptionClient.stubs(:find_subscriptions).returns(standard_subscription_result) + SubscriptionClient.stubs(:find_subscriptions).returns(standard_subscription_result) end it "detects standard type" do @@ -117,7 +117,7 @@ describe CustomWizard::Subscription do context "with a business subscription" do before do - DiscourseSubscriptionClient.stubs(:find_subscriptions).returns(business_subscription_result) + SubscriptionClient.stubs(:find_subscriptions).returns(business_subscription_result) end it "detects business type" do @@ -131,7 +131,7 @@ describe CustomWizard::Subscription do context "with a community subscription" do before do - DiscourseSubscriptionClient.stubs(:find_subscriptions).returns(community_subscription_result) + SubscriptionClient.stubs(:find_subscriptions).returns(community_subscription_result) end it "detects community type" do diff --git a/spec/fixtures/subscription_client.rb b/spec/fixtures/subscription_client.rb index f495a796..051fbde4 100644 --- a/spec/fixtures/subscription_client.rb +++ b/spec/fixtures/subscription_client.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -module DiscourseSubscriptionClient +module SubscriptionClient def self.find_subscriptions(resource_name) end end @@ -24,7 +24,7 @@ class SubscriptionClientSubscription end end -module DiscourseSubscriptionClient +module SubscriptionClient class Subscriptions class Result attr_accessor :supplier, From 99f2e8bbd97d35466f53f906a980cfbeaea6ea52 Mon Sep 17 00:00:00 2001 From: Angus McLeod Date: Thu, 4 May 2023 15:49:22 +0200 Subject: [PATCH 17/28] Rubocop --- lib/custom_wizard/api/log_entry.rb | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/custom_wizard/api/log_entry.rb b/lib/custom_wizard/api/log_entry.rb index 31af514e..f4f0ce69 100644 --- a/lib/custom_wizard/api/log_entry.rb +++ b/lib/custom_wizard/api/log_entry.rb @@ -65,18 +65,18 @@ class CustomWizard::Api::LogEntry data = ::JSON.parse(record['value']) data[:log_id] = record['key'].split('_').last this_user = User.find_by(id: data['user_id']) - unless this_user.nil? - data[:user_id] = this_user.id || nil - data[:username] = this_user.username || "" - data[:userpath] = "/u/#{this_user.username_lower}/activity" - data[:name] = this_user.name || "" - data[:avatar_template] = "/user_avatar/default/#{this_user.username_lower}/97/#{this_user.uploaded_avatar_id}.png" - else + if this_user.nil? data[:user_id] = nil data[:username] = "" data[:userpath] = "" data[:name] = "" data[:avatar_template] = "" + else + data[:user_id] = this_user.id || nil + data[:username] = this_user.username || "" + data[:userpath] = "/u/#{this_user.username_lower}/activity" + data[:name] = this_user.name || "" + data[:avatar_template] = "/user_avatar/default/#{this_user.username_lower}/97/#{this_user.uploaded_avatar_id}.png" end self.new(api_name, data) end From 42517c094e3613da6374603a78160593dde41977 Mon Sep 17 00:00:00 2001 From: Angus McLeod Date: Thu, 4 May 2023 17:16:11 +0200 Subject: [PATCH 18/28] Minor tweaks to subscription loading logic --- lib/custom_wizard/subscription.rb | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/lib/custom_wizard/subscription.rb b/lib/custom_wizard/subscription.rb index e9218479..02627f07 100644 --- a/lib/custom_wizard/subscription.rb +++ b/lib/custom_wizard/subscription.rb @@ -109,20 +109,19 @@ class CustomWizard::Subscription result = SubscriptionClient.find_subscriptions("discourse-custom-wizard") if result&.any? - slugs = result.supplier.product_slugs - - if slugs.present? - ids_and_slugs = result.subscriptions.map do |subscription| - { id: subscription.product_id, slug: slugs[subscription.product_id] } - end - - id_and_slug = ids_and_slugs.sort do |a, b| - PRODUCT_HIERARCHY[a[:slug]] - PRODUCT_HIERARCHY[b[:slug]] - end.first - - @product_id = id_and_slug[:id] - @product_slug = id_and_slug[:slug] + ids_and_slugs = result.subscriptions.map do |subscription| + { + id: subscription.product_id, + slug: result.products[subscription.product_id] + } end + + id_and_slug = ids_and_slugs.sort do |a, b| + PRODUCT_HIERARCHY[a[:slug]] - PRODUCT_HIERARCHY[b[:slug]] + end.first + + @product_id = id_and_slug[:id] + @product_slug = id_and_slug[:slug] end end end From 44f078caffe30bf2755d4849843ef608334d7952 Mon Sep 17 00:00:00 2001 From: Angus McLeod Date: Thu, 4 May 2023 17:25:10 +0200 Subject: [PATCH 19/28] Fix failing rspec test --- spec/components/custom_wizard/subscription_spec.rb | 1 + spec/fixtures/subscription_client.rb | 5 +++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/spec/components/custom_wizard/subscription_spec.rb b/spec/components/custom_wizard/subscription_spec.rb index a296dc6a..4829d83d 100644 --- a/spec/components/custom_wizard/subscription_spec.rb +++ b/spec/components/custom_wizard/subscription_spec.rb @@ -83,6 +83,7 @@ describe CustomWizard::Subscription do result.supplier = SubscriptionClientSupplier.new(product_slugs) result.resource = SubscriptionClientResource.new result.subscriptions = [SubscriptionClientSubscription.new(product_id)] + result.products = product_slugs result end let!(:business_subscription_result) { get_subscription_result(business_product_id) } diff --git a/spec/fixtures/subscription_client.rb b/spec/fixtures/subscription_client.rb index 051fbde4..146279b1 100644 --- a/spec/fixtures/subscription_client.rb +++ b/spec/fixtures/subscription_client.rb @@ -29,10 +29,11 @@ module SubscriptionClient class Result attr_accessor :supplier, :resource, - :subscriptions + :subscriptions, + :products def any? - supplier.present? && resource.present? && subscriptions.present? + supplier.present? && resource.present? && subscriptions.present? && products.present? end end end From e46d6813792ba507724fffc3a84a03e24a58f58e Mon Sep 17 00:00:00 2001 From: Angus McLeod Date: Wed, 10 May 2023 12:20:53 +0200 Subject: [PATCH 20/28] Update README.md Update issue and documentation links in readme. --- README.md | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 0190f16e..0c454685 100644 --- a/README.md +++ b/README.md @@ -4,22 +4,24 @@ The Custom Wizard Plugin lets you make forms for your Discourse forum. Better us +👋 Looking to report an issue? We're managing issues for this plugin using our [bug report wizard](https://coop.pavilion.tech/w/bug-report). + ## Install If you're not sure how to install a plugin in Discourse, please follow the [plugin installation guide](https://meta.discourse.org/t/install-a-plugin/19157) or contact your Discourse hosting provider. ## Documentation -[Read the full documentation here](https://discourse.pluginmanager.org/c/discourse-custom-wizard/documentation), or go directly to the relevant section +[Read the full documentation here](https://coop.pavilion.tech/c/82), or go directly to the relevant section -- [Wizard Administration](https://discourse.pluginmanager.org/t/wizard-administration) -- [Wizard Settings](https://discourse.pluginmanager.org/t/wizard-settings) -- [Step Settings](https://discourse.pluginmanager.org/t/step-settings) -- [Field Settings](https://discourse.pluginmanager.org/t/field-settings) -- [Conditional Settings](https://discourse.pluginmanager.org/t/conditional-settings) -- [Field Interpolation](https://discourse.pluginmanager.org/t/field-interpolation) -- [Wizard Examples and Templates](https://discourse.pluginmanager.org/t/wizard-examples-and-templates) +- [Wizard Administration](https://coop.pavilion.tech/t/1602) +- [Wizard Settings](https://coop.pavilion.tech/t/1614) +- [Step Settings](https://coop.pavilion.tech/t/1735) +- [Field Settings](https://coop.pavilion.tech/t/1580) +- [Conditional Settings](https://coop.pavilion.tech/t/1673) +- [Field Interpolation](https://coop.pavilion.tech/t/1557) +- [Handling Dates and Times](https://coop.pavilion.tech/t/1708) ## Support -- [Report a bug](https://discourse.pluginmanager.org/w/bug-report) +- [Report an issue](https://coop.pavilion.tech/w/bug-report) From dc23db7a0c1ef06b0f3a36bd43793d91cadd0eba Mon Sep 17 00:00:00 2001 From: Angus McLeod Date: Thu, 18 May 2023 18:45:40 +0200 Subject: [PATCH 21/28] Bump version --- plugin.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin.rb b/plugin.rb index 4556ce99..cb5172eb 100644 --- a/plugin.rb +++ b/plugin.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true # name: discourse-custom-wizard # about: Forms for Discourse. Better onboarding, structured posting, data enrichment, automated actions and much more. -# version: 2.3.4 +# version: 2.4.0 # authors: Angus McLeod, Faizaan Gagan, Robert Barrow, Keegan George, Kaitlin Maddever # url: https://github.com/paviliondev/discourse-custom-wizard # contact_emails: development@pavilion.tech From 00ba8425e360365610281b52d935612d1968ae4a Mon Sep 17 00:00:00 2001 From: Angus McLeod Date: Fri, 19 May 2023 10:29:54 +0200 Subject: [PATCH 22/28] Fix multiple subscriptions sort --- lib/custom_wizard/subscription.rb | 2 +- .../custom_wizard/subscription_spec.rb | 21 ++++++++++++++----- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/lib/custom_wizard/subscription.rb b/lib/custom_wizard/subscription.rb index 02627f07..6ca592f9 100644 --- a/lib/custom_wizard/subscription.rb +++ b/lib/custom_wizard/subscription.rb @@ -117,7 +117,7 @@ class CustomWizard::Subscription end id_and_slug = ids_and_slugs.sort do |a, b| - PRODUCT_HIERARCHY[a[:slug]] - PRODUCT_HIERARCHY[b[:slug]] + PRODUCT_HIERARCHY.index(b[:slug]) - PRODUCT_HIERARCHY.index(a[:slug]) end.first @product_id = id_and_slug[:id] diff --git a/spec/components/custom_wizard/subscription_spec.rb b/spec/components/custom_wizard/subscription_spec.rb index 4829d83d..0bfb1839 100644 --- a/spec/components/custom_wizard/subscription_spec.rb +++ b/spec/components/custom_wizard/subscription_spec.rb @@ -78,17 +78,18 @@ describe CustomWizard::Subscription do end context "with subscriptions" do - def get_subscription_result(product_id) + def get_subscription_result(product_ids) result = SubscriptionClient::Subscriptions::Result.new result.supplier = SubscriptionClientSupplier.new(product_slugs) result.resource = SubscriptionClientResource.new - result.subscriptions = [SubscriptionClientSubscription.new(product_id)] + result.subscriptions = product_ids.map { |product_id| SubscriptionClientSubscription.new(product_id) } result.products = product_slugs result end - let!(:business_subscription_result) { get_subscription_result(business_product_id) } - let!(:standard_subscription_result) { get_subscription_result(standard_product_id) } - let!(:community_subscription_result) { get_subscription_result(community_product_id) } + let!(:business_subscription_result) { get_subscription_result([business_product_id]) } + let!(:standard_subscription_result) { get_subscription_result([standard_product_id]) } + let!(:community_subscription_result) { get_subscription_result([community_product_id]) } + let!(:multiple_subscription_result) { get_subscription_result([community_product_id, business_product_id]) } it "handles mapped values" do SubscriptionClient.stubs(:find_subscriptions).returns(standard_subscription_result) @@ -143,6 +144,16 @@ describe CustomWizard::Subscription do expect(described_class.includes?(:action, :type, 'create_category')).to eq(true) end end + + context "with multiple subscriptions" do + before do + SubscriptionClient.stubs(:find_subscriptions).returns(multiple_subscription_result) + end + + it "detects correct type in hierarchy" do + expect(described_class.type).to eq(:business) + end + end end end end From 49c1848e88d6f7c9901c07831e54083b3a138e7e Mon Sep 17 00:00:00 2001 From: Angus McLeod Date: Fri, 19 May 2023 10:30:58 +0200 Subject: [PATCH 23/28] Bump version --- plugin.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin.rb b/plugin.rb index cb5172eb..7d7da6ae 100644 --- a/plugin.rb +++ b/plugin.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true # name: discourse-custom-wizard # about: Forms for Discourse. Better onboarding, structured posting, data enrichment, automated actions and much more. -# version: 2.4.0 +# version: 2.4.1 # authors: Angus McLeod, Faizaan Gagan, Robert Barrow, Keegan George, Kaitlin Maddever # url: https://github.com/paviliondev/discourse-custom-wizard # contact_emails: development@pavilion.tech From 4cdfdbf9d544270e95076a057ba75d4d0d0c6bb1 Mon Sep 17 00:00:00 2001 From: Angus McLeod Date: Tue, 23 May 2023 10:10:52 +0200 Subject: [PATCH 24/28] FIX: ensure element is present before passing on insertText event --- .../discourse/initializers/custom-wizard-edits.js.es6 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/assets/javascripts/discourse/initializers/custom-wizard-edits.js.es6 b/assets/javascripts/discourse/initializers/custom-wizard-edits.js.es6 index 2d13e703..7eed8faf 100644 --- a/assets/javascripts/discourse/initializers/custom-wizard-edits.js.es6 +++ b/assets/javascripts/discourse/initializers/custom-wizard-edits.js.es6 @@ -69,7 +69,7 @@ export default { }, _wizardInsertText(text, options) { - if (this.session.wizardEventFieldId === this.fieldId) { + if (this.session.wizardEventFieldId === this.fieldId && this.element) { this.insertText(text, options); } }, From 12ca60775abfb51432ccf515643fde61a300cf40 Mon Sep 17 00:00:00 2001 From: Angus McLeod Date: Tue, 23 May 2023 10:11:43 +0200 Subject: [PATCH 25/28] Bump version --- plugin.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin.rb b/plugin.rb index 7d7da6ae..ba3f8bf1 100644 --- a/plugin.rb +++ b/plugin.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true # name: discourse-custom-wizard # about: Forms for Discourse. Better onboarding, structured posting, data enrichment, automated actions and much more. -# version: 2.4.1 +# version: 2.4.2 # authors: Angus McLeod, Faizaan Gagan, Robert Barrow, Keegan George, Kaitlin Maddever # url: https://github.com/paviliondev/discourse-custom-wizard # contact_emails: development@pavilion.tech From 4bfea70dde20863bd5b836c39218e56e0b7ec38a Mon Sep 17 00:00:00 2001 From: Angus McLeod Date: Tue, 23 May 2023 10:27:42 +0200 Subject: [PATCH 26/28] Linting fix --- .../discourse/initializers/custom-wizard-edits.js.es6 | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/assets/javascripts/discourse/initializers/custom-wizard-edits.js.es6 b/assets/javascripts/discourse/initializers/custom-wizard-edits.js.es6 index 7eed8faf..c974fafb 100644 --- a/assets/javascripts/discourse/initializers/custom-wizard-edits.js.es6 +++ b/assets/javascripts/discourse/initializers/custom-wizard-edits.js.es6 @@ -69,7 +69,10 @@ export default { }, _wizardInsertText(text, options) { - if (this.session.wizardEventFieldId === this.fieldId && this.element) { + if ( + this.session.wizardEventFieldId === this.fieldId && + this.element + ) { this.insertText(text, options); } }, From 99e747a331543999112e44fdc2b8b1411068424c Mon Sep 17 00:00:00 2001 From: Angus McLeod Date: Wed, 31 May 2023 12:09:00 +0200 Subject: [PATCH 27/28] Ensure subscriptions are not stubbed if testing for no subscription --- spec/plugin_helper.rb | 11 +++++++++++ .../custom_wizard/admin/admin_controller_spec.rb | 4 ++++ 2 files changed, 15 insertions(+) diff --git a/spec/plugin_helper.rb b/spec/plugin_helper.rb index 5334c1fa..16585e16 100644 --- a/spec/plugin_helper.rb +++ b/spec/plugin_helper.rb @@ -12,3 +12,14 @@ def enable_subscription(type) CustomWizard::Subscription.stubs("#{type}?".to_sym).returns(true) CustomWizard::Subscription.any_instance.stubs("#{type}?".to_sym).returns(true) end + +def disable_subscriptions + %w[ + standard + business + community + ].each do |type| + CustomWizard::Subscription.stubs("#{type}?".to_sym).returns(false) + CustomWizard::Subscription.any_instance.stubs("#{type}?".to_sym).returns(false) + end +end diff --git a/spec/requests/custom_wizard/admin/admin_controller_spec.rb b/spec/requests/custom_wizard/admin/admin_controller_spec.rb index 6a7d721c..5e2b722c 100644 --- a/spec/requests/custom_wizard/admin/admin_controller_spec.rb +++ b/spec/requests/custom_wizard/admin/admin_controller_spec.rb @@ -14,6 +14,10 @@ describe CustomWizard::AdminController do end context "without a subscription" do + before do + disable_subscriptions + end + it "returns the right subscription details" do get "/admin/wizards.json" expect(response.parsed_body["subscribed"]).to eq(false) From c256a41668bcb7ab968e7ff4fe91d9764be85bc9 Mon Sep 17 00:00:00 2001 From: Angus McLeod Date: Wed, 31 May 2023 14:27:00 +0200 Subject: [PATCH 28/28] Also ensure subscription client definition is in the right state --- spec/components/custom_wizard/subscription_spec.rb | 9 --------- spec/plugin_helper.rb | 9 +++++++++ .../custom_wizard/admin/admin_controller_spec.rb | 5 +++-- 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/spec/components/custom_wizard/subscription_spec.rb b/spec/components/custom_wizard/subscription_spec.rb index 0bfb1839..2db8dae0 100644 --- a/spec/components/custom_wizard/subscription_spec.rb +++ b/spec/components/custom_wizard/subscription_spec.rb @@ -13,15 +13,6 @@ describe CustomWizard::Subscription do } } - def undefine_client_classes - Object.send(:remove_const, :SubscriptionClient) if Object.constants.include?(:SubscriptionClient) - Object.send(:remove_const, :SubscriptionClientSubscription) if Object.constants.include?(:SubscriptionClientSubscription) - end - - def define_client_classes - load File.expand_path("#{Rails.root}/plugins/discourse-custom-wizard/spec/fixtures/subscription_client.rb", __FILE__) - end - after do undefine_client_classes end diff --git a/spec/plugin_helper.rb b/spec/plugin_helper.rb index 16585e16..8436f7c9 100644 --- a/spec/plugin_helper.rb +++ b/spec/plugin_helper.rb @@ -23,3 +23,12 @@ def disable_subscriptions CustomWizard::Subscription.any_instance.stubs("#{type}?".to_sym).returns(false) end end + +def undefine_client_classes + Object.send(:remove_const, :SubscriptionClient) if Object.constants.include?(:SubscriptionClient) + Object.send(:remove_const, :SubscriptionClientSubscription) if Object.constants.include?(:SubscriptionClientSubscription) +end + +def define_client_classes + load File.expand_path("#{Rails.root}/plugins/discourse-custom-wizard/spec/fixtures/subscription_client.rb", __FILE__) +end diff --git a/spec/requests/custom_wizard/admin/admin_controller_spec.rb b/spec/requests/custom_wizard/admin/admin_controller_spec.rb index 5e2b722c..877f4262 100644 --- a/spec/requests/custom_wizard/admin/admin_controller_spec.rb +++ b/spec/requests/custom_wizard/admin/admin_controller_spec.rb @@ -16,20 +16,21 @@ describe CustomWizard::AdminController do context "without a subscription" do before do disable_subscriptions + define_client_classes end it "returns the right subscription details" do get "/admin/wizards.json" expect(response.parsed_body["subscribed"]).to eq(false) expect(response.parsed_body["subscription_attributes"]).to eq(CustomWizard::Subscription.attributes.as_json) - expect(response.parsed_body["subscription_client_installed"]).to eq(false) + expect(response.parsed_body["subscription_client_installed"]).to eq(true) end end context "with a subscription" do before do enable_subscription("standard") - load File.expand_path("#{Rails.root}/plugins/discourse-custom-wizard/spec/fixtures/subscription_client.rb", __FILE__) + define_client_classes end it "returns the right subscription details" do