Custom Wizard Plugin


#247

The wizard has been great however I am having a couple issues I am hoping someone can help with. The first is on validation. I have set up a few text and textarea fields that have a minimum length. I have found however that there does not appear to be any checking against white spaces. For example when I require an answer to be 10 characters however simply adding 10 spaces satisfies that requirement. Is this the expected behavior? To temporarily resolve this I added .strip to the end of the first line in the method “validate_field” which does resolve the issue though probably not the best solution to that.

The second issue I have been running into is that my wizard is setup to create a topic on completion and it is not working. I started looking through the code and noticed there is a call to self.fill_placeholders which populates the title and post. The method however does not actually return a value. Adding “return result” as the last line in that method appears to have resolved the issue. However as I do not see a lot of people reporting this behavior so I am wondering how others have made this function correctly.


#248

Wizards are returning blank pages for me, with the following in my production log:

production.log
Started GET "/w/test" for 172.68.47.144 at 2019-01-20 20:02:26 +0000
Processing by CustomWizard::WizardController#index as HTML
  Parameters: {"wizard_id"=>"test"}
  Rendering default/empty.html.erb within layouts/wizard
  Rendered default/empty.html.erb within layouts/wizard (0.1ms)
  Rendered layouts/_head.html.erb (5.8ms)
Completed 200 OK in 131ms (Views: 25.6ms | ActiveRecord: 47.2ms)
Started GET "/extra-locales/wizard" for 172.68.47.144 at 2019-01-20 20:02:27 +0000
Processing by ExtraLocalesController#show as */*
  Parameters: {"bundle"=>"wizard"}
  Rendering text template
  Rendered text template (0.0ms)
Completed 200 OK in 12ms (Views: 0.7ms | ActiveRecord: 2.5ms)
Started GET "/w/test?_=1548014547550" for 172.68.47.144 at 2019-01-20 20:02:27 +0000
Processing by CustomWizard::WizardController#index as JSON
  Parameters: {"_"=>"1548014547550", "wizard_id"=>"test"}
Completed 500 Internal Server Error in 24ms (ActiveRecord: 12.7ms)
NoMethodError (undefined method `subject' for nil:NilClass)
/var/www/discourse/plugins/discourse-custom-wizard/lib/wizard.rb:85:in `unfinished?'

I have no plugins or custom themes installed. Any idea on how to resolve this issue?

Thanks.


(Angus McLeod) #249

I’ve removed that rule

@thisnthat Thanks for the feedback :+1:

Thanks. Adding .strip to that validation suffices I think. Done.

The last line of the method is

result.gsub!(/w\{(.*?)\}/) { |match| data[$1.to_sym] }

Which returns the result of the substitution (this is used to interpolate wizard fields into custom titles and posts.). Adding return result shouldn’t have changed anything.

There was an issue with the check which determines whether to use the custom title or assigned title. Perhaps you entered something in the custom title input which (incorrectly) would have triggered the use of the custom title

Give it another whirl.

@FoohonPie This should fix your issue


#250

The issue is with gsub!. My custom title does not contain any w{} variables only u{}. As a result result.gsub!(/w{(.*?)}/) will return nil as no matches are found. By adding a “return result” to the end of the method it is returning the value assigned to result rather than the return value of gsub!. gsub! will correctly update the value of result if matches are found, while if no matches are found it will not change the value of result.


(Per Torstensson) #251

Hi!

Love the plugin, it’s really super useful :slight_smile: I have two questions regarding access:

  1. Is it possible to set access to a form based on group?
  2. I see you can set access based on trust level - am I missing something, or does it not have any practical effect if you set a value >4?

All the best
-Per


(Angus McLeod) #252

Yup! You’re right. It should just be gsub not gsub!

@torstensson Glad that you love the plugin!

Not currently.

Yeah, the logic that determines whether you’re permitted to access a wizard is

def permitted?
  user.staff? || user.trust_level.to_i >= min_trust.to_i
end

(Per Torstensson) #253

Understood. If you see it as practically feasible and are available to add this to the plugin on a consultant basis, could you please PM a quote?


#254

Thank you @angus for revamping the location fields!

I have noticed this error displayed when I choose the location from the above fields (postal code, city): apparently the lat/lon fields are expecting integers (unless that’s the validation check that expects them).

The translation strings are missing, but that’s a reminder for all translators to check their YAML files :slight_smile:


(Angus McLeod) #255

@hellekin I’ve just made various updates to improve the use of coordinates in location forms in custom wizards.


#256

Thank you @angus, but the fix is missing something. Looks like the validation is skipping the automatically passed location:

I think we should detail the process more to make the algorithm stronger. A single free form text for input (like in osm.org) and an alternate location/map input would be better. Also the error message / help message should look different, maybe upper in the UI, and differentiate help from error (color).

e.g, on OSM, “1030 schaerbeek, belgium” gives a correct result right away.


#257

Thanks for all the recent work @angus.

I’ve come across an unexpected use case: I’m linking to a custom wizard from my community’s welcome topic. It works great if you’re already logged in, but to those who aren’t yet members, the wizard shows the “Oops! That page doesn’t exist or is private.” page, which suggests a possibly broken link, without any login button being present to guide them through.

Is there a way to instead show the “You need to log in to see that topic.” page or in some other way indicate that something definitely is there, you just have to login to see it? I’m attempting to use the custom wizard itself as a way to get people in.

Thanks.


(Jay Pfaffman) #258

Translation missing?

image


(Pad Pors) #259

is this feature possible to be added to the plugin? and more importantly is it wanted by others?


(Justin DiRose) #260

EDIT: This was user error and a UI bug. Apparently the correct boxes for the create topic action were not showing up when the Create Topic action is selected by default. If you select another option and come back to select it, then the boxes show up and it works correctly.


I’m trying to run this plugin and I’m getting a weird error when a submit action to create a topic is added:

Site’s running on 2.3.0.beta2 +266.

It appears the information is saving but the topic is not being created. This is the very first time I’ve run the plugin so I very well may have something misconfigured, but I did a runthrough and couldn’t find anything initially.

I’m also noticing [Object object] is being stored for a text area field. Related?


(zsean) #261

@angus - excellent plugin!

One quick question, I’ve added a field on one of the steps that allows for a file upload. It works great, but only allows certain file types and I need it to allow some custom file types. Is there an easy way to enable the wizzard to allow the file types I setup in the main Settings -> Files? Seems like it’s only image files and pdfs right now.


(Danny Goodall) #262

Have you looked at the authorized extensions setting?

It allows you to authorise files by their extension. Try adding your custom file type extensions to this list.

Note, I’ve added .csv and .txt to the default extensions in the screenshot above.


(zsean) #263

@bletch - Yes we did try that but no luck. The wizzard still only accepts pdfs and image files so I think this plugin maybe sets authorized extensions from somewhere else… Just not sure where.


(zsean) #265

Does anyone know how to get the value from the upload field? I add this in the post builder:

w{upload}

and it outputs an array:

{“id”=>“19”, “url”=>“example.com”, “original_filename”=>“example.png”, “filesize”=>“77759”, “width”=>“512”, “height”=>“512”, “thumbnail_width”=>“500”, “thumbnail_height”=>“500”, “extension”=>“png”, “short_url”=>“upload://example.png”, “retain_hours”=>"", “human_filesize”=>“75.9 KB”}

So I tried to do: w{upload.url} to output the url and nothing is displayed.


#266

Whoops, there’s a terrible situation now with this plugin.

Situation

I started receiving complaints that people could not click the link of the wizard to go to next step (or exit the wizard), which was related to some CSS issue that I thought @angus had already solved some time ago. So I decided to remove the wizard since I could not find an option to disable it. But then it seems to have not cleanly removed itself since users who could not pass the wizard now get:

But of course I cannot fix it since the wizard is gone. I’m going to try and remove the plugin from the build, but I fear it’s in the database, telling Discourse to redirect the user who did not yet fill the custom required field (in this case to check the box that accepts the terms of service).

I’m pretty sure this is a side effect of the recent change with custom field registration that broke other plugins. The problem now is: how to ensure the plugin can ‘resurrect’ enough of a gone wizard to be able to cleanup after itself? Or, in other words, is there a way to remove the remnants of the gone wizard from database? I hope there’s a solution to this.

:crossed_fingers:


(c0ry) #267

Boot up safe-mode (yoursite.com/safe-mode)
And see what happens there.

Then rebuild your app.yml without the plugin. You should be good.