Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PL: Submit misc surveys #28850

Merged
merged 12 commits into from
Jun 3, 2019
Merged

PL: Submit misc surveys #28850

merged 12 commits into from
Jun 3, 2019

Conversation

breville
Copy link
Member

@breville breville commented May 31, 2019

This builds on the work in #28703 to allow the hosted submission of a misc survey.

Usage is designed to be largely self-serve: direct users to a URL such as https://studio.code.org/pd/misc_survey/other_workshop, and the matching JotForm survey will be embedded. As it happens, this URL is the first form we're going to use with this system: the Unofficial Workshop Attendance form. (And while it's mostly self-serve, there is for now a table in Pd::MiscSurvey specifying the form ID, its mapping to a URL, and that it can be embedded.)

Following normal practices, the form is set up in JotForm to have a hidden submitRedirect field which takes the URL we pass it, and upon user submission, POSTs to that URL, which submits to our new controller. The controller is set up to only allow one submission per form ID per user, and to restrict submission to teacher accounts with email. If the teacher is missing a school, the interstitial will pop up, encouraging them to enter one first. (Longer term, these requirements should be configurable per form.)

The new form has a JotForm datetime control, and so this change adds support for that answer type. We treat this result specially and translate the incoming hash into a string in the answers like this:

{"workshopDate"=>"05/08/2019", "workshopCourse"=> ...

Because the form is embedded on our site, a placeholder entry is added to Pd::MiscSurvey upon submission, and then the fill_jotform_placeholders cron job fills the entry shortly afterwards. The sync_jotforms cron job will continue to retrieve additional submissions which didn't get a placeholder for some reason.

It turns out that there are different codepaths in Pd::JotFormBackedForm for writing the answers in each of these cases, and so the process_answers_from_submission function has been added to factor out the work of storing the answers using name instead of id keys when possible.

The form

misc survey form with zip 2

Interstitial when missing school

Screenshot 2019-05-31 15 16 45

When signed out

Screenshot 2019-05-31 15 43 14

When not a teacher

Screenshot 2019-05-31 15 53 57

When teacher missing email

Screenshot 2019-05-31 15 55 45

@breville breville changed the title PL: submit misc surveys PL: Submit misc surveys May 31, 2019
@breville breville changed the base branch from pl-ingest-misc-surveys to staging May 31, 2019 20:07
Conflicts:
	dashboard/lib/pd/jot_form/constants.rb
Copy link

@agealy agealy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the in-depth plaintext description 👍

@hacodeorg
Copy link
Contributor

This PR looks good to me! Please add some basic tests when you can.

Copy link
Contributor

@islemaster islemaster left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Woohoo!


if CDO.newrelic_logging
NewRelic::Agent.record_custom_event(
"RenderJotFormView",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎉 Thanks for remembering to include this!

# Update answers for this submission from the JotForm API
# Useful for filling in placeholder response entries (submission id but no answers)
def sync_from_jotform
raise 'Missing submission id' unless submission_id.present?

submission = JotForm::Translation.new(form_id).get_submission(submission_id)
update!(answers: submission[:answers].to_json)
questions_details = self.class.use_names_for_question_ids? ? JSON.parse(questions.questions) : nil
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this means question_details only available if use_names_for_questions_ids is true? Does that affect syncing other forms?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The questions parameter in process_answers_from_submission is optional, and again only attempted to be used when use_names_for_question_ids? is true.

@breville breville merged commit dfecb63 into staging Jun 3, 2019
@breville breville deleted the pl-submit-misc-surveys branch June 3, 2019 22:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants