-
Notifications
You must be signed in to change notification settings - Fork 481
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
PL: Submit misc surveys #28850
Conversation
Conflicts: dashboard/lib/pd/jot_form/constants.rb
There was a problem hiding this 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 👍
This PR looks good to me! Please add some basic tests when you can. |
There was a problem hiding this 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", |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
.
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:Because the form is embedded on our site, a placeholder entry is added to
Pd::MiscSurvey
upon submission, and then thefill_jotform_placeholders
cron job fills the entry shortly afterwards. Thesync_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 theprocess_answers_from_submission
function has been added to factor out the work of storing the answers usingname
instead ofid
keys when possible.The form
Interstitial when missing school
When signed out
When not a teacher
When teacher missing email