Spiegel von
https://github.com/paviliondev/discourse-custom-wizard.git
synchronisiert 2024-11-25 18:50:27 +01:00
MERGE: merged upstream changes
Dieser Commit ist enthalten in:
Commit
c5c91a11af
14 geänderte Dateien mit 70 neuen und 36 gelöschten Zeilen
3
assets/javascripts/wizard-custom-guest.js
Normale Datei
3
assets/javascripts/wizard-custom-guest.js
Normale Datei
|
@ -0,0 +1,3 @@
|
|||
(function() {
|
||||
window.location.href = "/login";
|
||||
})();
|
|
@ -5,6 +5,12 @@ class CustomWizard::WizardController < ::ApplicationController
|
|||
helper_method :wizard_page_title
|
||||
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
|
||||
CustomWizard::Template.new(PluginStore.get('custom_wizard', params[:wizard_id].underscore))
|
||||
end
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
module Jobs
|
||||
class ClearAfterTimeWizard < Jobs::Base
|
||||
class ClearAfterTimeWizard < ::Jobs::Base
|
||||
sidekiq_options queue: 'critical'
|
||||
|
||||
def execute(args)
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
module Jobs
|
||||
class RefreshApiAccessToken < Jobs::Base
|
||||
class RefreshApiAccessToken < ::Jobs::Base
|
||||
def execute(args)
|
||||
CustomWizard::Api::Authorization.get_token(args[:name], refresh: true)
|
||||
end
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
module Jobs
|
||||
class SetAfterTimeWizard < Jobs::Base
|
||||
class SetAfterTimeWizard < ::Jobs::Base
|
||||
def execute(args)
|
||||
if CustomWizard::Wizard.find(args[:wizard_id])
|
||||
user_ids = []
|
||||
|
|
|
@ -53,7 +53,21 @@ class CustomWizard::Builder
|
|||
result
|
||||
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
|
||||
|
||||
def self.recurse(data, keys)
|
||||
|
@ -90,7 +104,7 @@ class CustomWizard::Builder
|
|||
end
|
||||
|
||||
if required_data = step_template['required_data']
|
||||
if !@submissions.last && required_data.length
|
||||
if !@submissions.last && required_data.present?
|
||||
step.permitted = false
|
||||
next
|
||||
end
|
||||
|
@ -331,7 +345,7 @@ class CustomWizard::Builder
|
|||
end
|
||||
|
||||
def standardise_boolean(value)
|
||||
!!HasCustomFields::Helpers::CUSTOM_FIELD_TRUE.include?(value)
|
||||
ActiveRecord::Type::Boolean.new.cast(value)
|
||||
end
|
||||
|
||||
def create_topic(user, action, data)
|
||||
|
@ -354,22 +368,10 @@ class CustomWizard::Builder
|
|||
skip_validations: true
|
||||
}
|
||||
|
||||
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
|
||||
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] = action_category_id(action, data)
|
||||
|
||||
params[:category] = category_id
|
||||
tags = action['tags'] || []
|
||||
params[:tags] = tags
|
||||
|
||||
topic_custom_fields = {}
|
||||
|
||||
|
@ -394,7 +396,7 @@ class CustomWizard::Builder
|
|||
end
|
||||
end
|
||||
else
|
||||
value = [*value] if key === 'tags'
|
||||
value = [*value] + tags if key === 'tags'
|
||||
params[key.to_sym] = value
|
||||
end
|
||||
end
|
||||
|
@ -550,8 +552,8 @@ class CustomWizard::Builder
|
|||
|
||||
url += "&body=#{post}"
|
||||
|
||||
if action['category_id']
|
||||
if category = Category.find(action['category_id'])
|
||||
if category_id = action_category_id(action, data)
|
||||
if category = Category.find(category_id)
|
||||
url += "&category=#{category.full_slug('/')}"
|
||||
end
|
||||
end
|
||||
|
@ -597,4 +599,21 @@ class CustomWizard::Builder
|
|||
PluginStore.set("#{@wizard.id}_submissions", @wizard.user.id, @submissions)
|
||||
@wizard.reset
|
||||
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
|
||||
|
|
|
@ -15,6 +15,7 @@ config.assets.paths << Rails.root.join('plugins', 'discourse-custom-wizard', 'as
|
|||
|
||||
if Rails.env.production?
|
||||
config.assets.precompile += %w{
|
||||
wizard-custom-guest.js
|
||||
wizard-custom-lib.js
|
||||
wizard-custom.js
|
||||
wizard-plugin.js
|
||||
|
@ -36,7 +37,6 @@ end
|
|||
after_initialize do
|
||||
UserHistory.actions[:custom_wizard_step] = 1000
|
||||
|
||||
require_dependency 'application_controller'
|
||||
module ::CustomWizard
|
||||
class Engine < ::Rails::Engine
|
||||
engine_name 'custom_wizard'
|
||||
|
@ -138,10 +138,12 @@ after_initialize do
|
|||
end
|
||||
end
|
||||
|
||||
require_dependency 'invites_controller'
|
||||
class ::InvitesController
|
||||
prepend InvitesControllerCustomWizard
|
||||
end
|
||||
|
||||
require_dependency 'application_controller'
|
||||
class ::ApplicationController
|
||||
before_action :redirect_to_wizard_if_required, if: :current_user
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
class CustomWizard::ApiSerializer < ApplicationSerializer
|
||||
class CustomWizard::ApiSerializer < ::ApplicationSerializer
|
||||
attributes :name,
|
||||
:title,
|
||||
:authorization,
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
class CustomWizard::Api::AuthorizationSerializer < ApplicationSerializer
|
||||
class CustomWizard::Api::AuthorizationSerializer < ::ApplicationSerializer
|
||||
attributes :auth_type,
|
||||
:auth_url,
|
||||
:token_url,
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
class CustomWizard::BasicApiSerializer < ApplicationSerializer
|
||||
class CustomWizard::BasicApiSerializer < ::ApplicationSerializer
|
||||
attributes :name,
|
||||
:title,
|
||||
:endpoints
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
class CustomWizard::Api::BasicEndpointSerializer < ApplicationSerializer
|
||||
class CustomWizard::Api::BasicEndpointSerializer < ::ApplicationSerializer
|
||||
attributes :id,
|
||||
:name
|
||||
end
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
class CustomWizard::Api::EndpointSerializer < ApplicationSerializer
|
||||
class CustomWizard::Api::EndpointSerializer < ::ApplicationSerializer
|
||||
attributes :id,
|
||||
:name,
|
||||
:method,
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
class CustomWizard::Api::LogSerializer < ApplicationSerializer
|
||||
class CustomWizard::Api::LogSerializer < ::ApplicationSerializer
|
||||
attributes :log_id,
|
||||
:time,
|
||||
:status,
|
||||
|
|
|
@ -40,8 +40,12 @@
|
|||
<%= raw theme_lookup("body_tag") %>
|
||||
<%- end %>
|
||||
|
||||
<%= preload_script 'wizard-custom-start' %>
|
||||
<%= preload_script 'wizard-raw-templates' %>
|
||||
<%- if current_user %>
|
||||
<%= 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 class="fontawesome">
|
||||
|
|
Laden …
In neuem Issue referenzieren