0
0
Fork 1
Spiegel von https://github.com/paviliondev/discourse-custom-wizard.git synchronisiert 2024-11-22 09:20:29 +01:00

MERGE: merged upstream changes

Dieser Commit ist enthalten in:
Robert Barrow 2019-10-09 16:06:39 +01:00
Commit c5c91a11af
14 geänderte Dateien mit 70 neuen und 36 gelöschten Zeilen

Datei anzeigen

@ -0,0 +1,3 @@
(function() {
window.location.href = "/login";
})();

Datei anzeigen

@ -4,6 +4,12 @@ class CustomWizard::WizardController < ::ApplicationController
helper_method :wizard_page_title helper_method :wizard_page_title
helper_method :theme_ids helper_method :theme_ids
before_action :handle_login_redirect, unless: :current_user
def handle_login_redirect
cookies[:destination_url] = "/w/#{params[:wizard_id]}"
end
def wizard def wizard
CustomWizard::Template.new(PluginStore.get('custom_wizard', params[:wizard_id].underscore)) CustomWizard::Template.new(PluginStore.get('custom_wizard', params[:wizard_id].underscore))

Datei anzeigen

@ -1,5 +1,5 @@
module Jobs module Jobs
class ClearAfterTimeWizard < Jobs::Base class ClearAfterTimeWizard < ::Jobs::Base
sidekiq_options queue: 'critical' sidekiq_options queue: 'critical'
def execute(args) def execute(args)

Datei anzeigen

@ -1,5 +1,5 @@
module Jobs module Jobs
class RefreshApiAccessToken < Jobs::Base class RefreshApiAccessToken < ::Jobs::Base
def execute(args) def execute(args)
CustomWizard::Api::Authorization.get_token(args[:name], refresh: true) CustomWizard::Api::Authorization.get_token(args[:name], refresh: true)
end end

Datei anzeigen

@ -1,5 +1,5 @@
module Jobs module Jobs
class SetAfterTimeWizard < Jobs::Base class SetAfterTimeWizard < ::Jobs::Base
def execute(args) def execute(args)
if CustomWizard::Wizard.find(args[:wizard_id]) if CustomWizard::Wizard.find(args[:wizard_id])
user_ids = [] user_ids = []

Datei anzeigen

@ -53,7 +53,21 @@ class CustomWizard::Builder
result result
end end
result.gsub(/w\{(.*?)\}/) { |match| recurse(data, [*$1.split('.')]) } result = result.gsub(/w\{(.*?)\}/) { |match| recurse(data, [*$1.split('.')]) }
result.gsub(/v\{(.*?)\}/) do |match|
attrs = $1.split(':')
key = attrs.first
format = attrs.length > 1 ? attrs.last : nil
v = nil
if key == 'time'
time_format = format.present? ? format : "%B %-d, %Y"
v = Time.now.strftime(time_format)
end
v
end
end end
def self.recurse(data, keys) def self.recurse(data, keys)
@ -90,7 +104,7 @@ class CustomWizard::Builder
end end
if required_data = step_template['required_data'] if required_data = step_template['required_data']
if !@submissions.last && required_data.length if !@submissions.last && required_data.present?
step.permitted = false step.permitted = false
next next
end end
@ -331,7 +345,7 @@ class CustomWizard::Builder
end end
def standardise_boolean(value) def standardise_boolean(value)
!!HasCustomFields::Helpers::CUSTOM_FIELD_TRUE.include?(value) ActiveRecord::Type::Boolean.new.cast(value)
end end
def create_topic(user, action, data) def create_topic(user, action, data)
@ -354,22 +368,10 @@ class CustomWizard::Builder
skip_validations: true skip_validations: true
} }
if action['custom_category_enabled'] params[:category] = action_category_id(action, data)
if action['custom_category_wizard_field']
category_id = data[action['category_id']] tags = action['tags'] || []
elsif action['custom_category_user_field_key'] params[:tags] = tags
if action['custom_category_user_field_key'].include?('custom_fields')
field = action['custom_category_user_field_key'].split('.').last
category_id = user.custom_fields[field]
else
category_id = user.send(action['custom_category_user_field_key'])
end
end
else
category_id = action['category_id']
end
params[:category] = category_id
topic_custom_fields = {} topic_custom_fields = {}
@ -394,7 +396,7 @@ class CustomWizard::Builder
end end
end end
else else
value = [*value] if key === 'tags' value = [*value] + tags if key === 'tags'
params[key.to_sym] = value params[key.to_sym] = value
end end
end end
@ -550,8 +552,8 @@ class CustomWizard::Builder
url += "&body=#{post}" url += "&body=#{post}"
if action['category_id'] if category_id = action_category_id(action, data)
if category = Category.find(action['category_id']) if category = Category.find(category_id)
url += "&category=#{category.full_slug('/')}" url += "&category=#{category.full_slug('/')}"
end end
end end
@ -597,4 +599,21 @@ class CustomWizard::Builder
PluginStore.set("#{@wizard.id}_submissions", @wizard.user.id, @submissions) PluginStore.set("#{@wizard.id}_submissions", @wizard.user.id, @submissions)
@wizard.reset @wizard.reset
end end
def action_category_id(action, data)
if action['custom_category_enabled']
if action['custom_category_wizard_field']
category_id = data[action['category_id']]
elsif action['custom_category_user_field_key']
if action['custom_category_user_field_key'].include?('custom_fields')
field = action['custom_category_user_field_key'].split('.').last
user.custom_fields[field]
else
user.send(action['custom_category_user_field_key'])
end
end
else
action['category_id']
end
end
end end

Datei anzeigen

@ -15,6 +15,7 @@ config.assets.paths << Rails.root.join('plugins', 'discourse-custom-wizard', 'as
if Rails.env.production? if Rails.env.production?
config.assets.precompile += %w{ config.assets.precompile += %w{
wizard-custom-guest.js
wizard-custom-lib.js wizard-custom-lib.js
wizard-custom.js wizard-custom.js
wizard-plugin.js wizard-plugin.js
@ -36,7 +37,6 @@ end
after_initialize do after_initialize do
UserHistory.actions[:custom_wizard_step] = 1000 UserHistory.actions[:custom_wizard_step] = 1000
require_dependency 'application_controller'
module ::CustomWizard module ::CustomWizard
class Engine < ::Rails::Engine class Engine < ::Rails::Engine
engine_name 'custom_wizard' engine_name 'custom_wizard'
@ -137,11 +137,13 @@ after_initialize do
@user = user @user = user
end end
end end
require_dependency 'invites_controller'
class ::InvitesController class ::InvitesController
prepend InvitesControllerCustomWizard prepend InvitesControllerCustomWizard
end end
require_dependency 'application_controller'
class ::ApplicationController class ::ApplicationController
before_action :redirect_to_wizard_if_required, if: :current_user before_action :redirect_to_wizard_if_required, if: :current_user

Datei anzeigen

@ -1,4 +1,4 @@
class CustomWizard::ApiSerializer < ApplicationSerializer class CustomWizard::ApiSerializer < ::ApplicationSerializer
attributes :name, attributes :name,
:title, :title,
:authorization, :authorization,

Datei anzeigen

@ -1,4 +1,4 @@
class CustomWizard::Api::AuthorizationSerializer < ApplicationSerializer class CustomWizard::Api::AuthorizationSerializer < ::ApplicationSerializer
attributes :auth_type, attributes :auth_type,
:auth_url, :auth_url,
:token_url, :token_url,

Datei anzeigen

@ -1,4 +1,4 @@
class CustomWizard::BasicApiSerializer < ApplicationSerializer class CustomWizard::BasicApiSerializer < ::ApplicationSerializer
attributes :name, attributes :name,
:title, :title,
:endpoints :endpoints

Datei anzeigen

@ -1,4 +1,4 @@
class CustomWizard::Api::BasicEndpointSerializer < ApplicationSerializer class CustomWizard::Api::BasicEndpointSerializer < ::ApplicationSerializer
attributes :id, attributes :id,
:name :name
end end

Datei anzeigen

@ -1,4 +1,4 @@
class CustomWizard::Api::EndpointSerializer < ApplicationSerializer class CustomWizard::Api::EndpointSerializer < ::ApplicationSerializer
attributes :id, attributes :id,
:name, :name,
:method, :method,

Datei anzeigen

@ -1,4 +1,4 @@
class CustomWizard::Api::LogSerializer < ApplicationSerializer class CustomWizard::Api::LogSerializer < ::ApplicationSerializer
attributes :log_id, attributes :log_id,
:time, :time,
:status, :status,

Datei anzeigen

@ -40,8 +40,12 @@
<%= raw theme_lookup("body_tag") %> <%= raw theme_lookup("body_tag") %>
<%- end %> <%- end %>
<%= preload_script 'wizard-custom-start' %> <%- if current_user %>
<%= preload_script 'wizard-raw-templates' %> <%= preload_script 'wizard-custom-start' %>
<%= preload_script 'wizard-raw-templates' %>
<%- else %>
<%= preload_script 'wizard-custom-guest' %>
<%- end %>
<div id="svg-sprites" style="display:none;"> <div id="svg-sprites" style="display:none;">
<div class="fontawesome"> <div class="fontawesome">