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

Automatically assign workshops on application submission #19722

Merged
merged 10 commits into from Jan 4, 2018

Conversation

Hamms
Copy link
Contributor

@Hamms Hamms commented Jan 2, 2018

If we can find an applicable workshop, based on the teacher's assciated
regional partner

# If this application is associated with a G3 partner who in turn is
# associated with a specific teachercon, return the workshop for that
# teachercon
if regional_partner.group == 3
Copy link
Contributor

Choose a reason for hiding this comment

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

Some group 3 partners have local summer workshops, instead of teachercon :(

Probably better to check the form data for regional_partner_workshop_ids. You could also check form data for teachercon instead of calling get_matching_teachercon directly (note the API that supplies that teachercon text uses the same call)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Right, but aren't those partners just unrepresented in get_matching_teachercon, and so we'll fall through to our base case?

Copy link
Contributor

Choose a reason for hiding this comment

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

Presumably yes. Good point.

user: user,
full_name: user.name,
email: user.email,
)
Copy link
Contributor

@aoby aoby Jan 2, 2018

Choose a reason for hiding this comment

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

Do we want this "assignment" to only be tracked by the external enrollment? As it stands this is not editable / retrievable here. We can call workshop again, but if the enrollment changes, it won't reflect the actual assigned workshop.

I'd like to see this be idempotent and retrievable. I suggest changing workshop (maybe rename to assigned_workshop?) to inspect enrollments and return the one that is enrolled if any, rather than first, with first as a default when none are enrolled. Then, with assign_workshop! (maybe renamed enroll_in_assigned_workshop?), we should use find_or_create_by! rather than new.

We could make it even more flexible for reassignment by allowing an optional argument for the specific workshop to be assigned and first deleting any other relevant enrollments (same course and subject).

What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree that this should be explicitly set rather than inferred.

I think the answer to how best to build this is actually going to kind of depend on the answer to whether we need to filter by course and/or subject. Is it the case that all the workshops we will want to be assignable to a teacher application are going to share some data, or do we want to allow partners to assign whatever workshop they want? I think it's gonna be the latter, since some of the G3-associated teachers are going to end up going to Local Summer Workshops and we'll want to handle those differently.

If we want that flexibility, it seems to me that we'll want an actual direct relation from application to workshop or enrollment, and assign_workshop! is refactored to something like self.enrollment = Pd::Enrollment.new(...) unless self.enrollment

Copy link
Contributor

Choose a reason for hiding this comment

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

The teachercon vs. local summer thing does muddy this up a bit, but the course should always be the applied-for course (CSD vs. CSP), exposed as course in the application, though it will need to be translated to be used in a workshop query (see

name: Pd::Workshop::COURSE_CSD,
).

I suppose subject could be the set of

[
  Pd::Workshop::SUBJECT_TEACHER_CON, 
  Pd::Workshop::SUBJECT_FIT
]

# Default to just assigning whichever of the partner's workshops is
# scheduled to start first. We expect to hit this case for G1 and G2
# partners, and for any G3 partners without an associated teachercon
regional_partner.workshops.order_by_scheduled_start.first
Copy link
Contributor

Choose a reason for hiding this comment

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

Don't we need to filter this by course and subject?
And isn't the association pd_workshops_organized (rather than workshops)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

d'oh, yes, that is definitely the association.

The first question is probably one for Tanya; I built it off of this comment but it does seem like we'll want to do some kind of filtering.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think that comment implies workshop to mean of the relevant course (CSD vs. CSP) and subject (5-day summer).

@Hamms Hamms force-pushed the assign-application-workshops branch from d3cbeb0 to bb66751 Compare January 3, 2018 01:47
@Hamms
Copy link
Contributor Author

Hamms commented Jan 3, 2018

@aoby what do you think of this approach? We associate the application with a workshop explicitly, and upon creation try to find a default workshop. Then we just need to add the ability to edit the associated workshop and we should be good to go

@aoby
Copy link
Contributor

aoby commented Jan 3, 2018

@Hamms I like this approach. It seems cleaner.

One question: might it be better to instead add a properties field and include SerializedProperties so we can more flexibly store fields like this with the applications outside form data, rather than explicitly adding pd_workshop_id? For instance, facilitator applications don't need a workshop, but might want to store some other kind of data. Thoughts?

@Hamms Hamms force-pushed the assign-application-workshops branch from ec8da8d to 1f207b5 Compare January 4, 2018 19:52
@Hamms
Copy link
Contributor Author

Hamms commented Jan 4, 2018

@aoby PTAL

This feature still needs tests; in the interest of unblocking everyone else, I'm inclined to do them in a separate PR. Any opposition?

def enroll_user
return unless pd_workshop_id

::Pd::Enrollment.find_or_create(
Copy link
Contributor

Choose a reason for hiding this comment

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

It's find_or_create_by (missing _by at the end), and we might as well use the bang version find_or_create_by!

Note there is also a first_or_create, but it works on a relation (where clause) and I find it to be less readable.

course: workshop_course,
subject: [
Pd::Workshop::SUBJECT_TEACHER_CON,
Pd::Workshop::SUBJECT_FIT,
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think we want FIT workshops included here for teacher application, do we? My understanding is those are only for facilitators, i.e. facilitator application.

@aoby
Copy link
Contributor

aoby commented Jan 4, 2018

LGTM (with a few suggestions and questions). I'd like to see tests as a followup, but I agree we should get this out to unblock others first.

@Hamms Hamms merged commit 7295bb6 into staging Jan 4, 2018
@Hamms Hamms deleted the assign-application-workshops branch May 31, 2018 18:50
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

2 participants