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
Set correct application status on submit #48949
Conversation
@@ -114,8 +114,6 @@ const FormController = props => { | |||
const [showDataWasLoadedMessage, setShowDataWasLoadedMessage] = useState( | |||
applicationId | |||
); | |||
const applicationStatusOnSave = 'incomplete'; | |||
const applicationStatusOnSubmit = 'unreviewed'; |
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.
These changed because now there are two potential statuses on submit –– instead, let the backend figure out which status it should be
refute TEACHER_APPLICATION_CLASS.last.response_scores | ||
assert_response :created | ||
end | ||
|
||
test 'autoscores and queues email once application is submitted' do | ||
application_hash = build :pd_teacher_application_hash_common, :csp | ||
test 'autoscores and queues emails on submit when approval is required' do |
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.
There's a lot of repeated code in these new tests. I wrote up a .each
way to reduce duplication, but I found the readability hard. Please push back if you think this is too much!
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.
I feel like prioritizing readability might make sense since we are shifting lots of terminology around statuses and desired behaviors so having each one more explicitly laid out might be better as we home in on the desired outcome? That's just a thought though, I'm not dug in on this by any means!
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.
I'm on the same page –– thanks!
ed8e465
to
44789f6
Compare
44789f6
to
d645cc5
Compare
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.
Looks fantastic! I had a couple comments but this looks good to merge!
@@ -61,12 +61,12 @@ class ApplicationBase < ApplicationRecord | |||
validate :status_is_valid_for_application_type | |||
validates_presence_of :type | |||
validates_presence_of :user_id, unless: proc {|application| application.application_type == PRINCIPAL_APPROVAL_APPLICATION} | |||
validates_presence_of :status, unless: proc {|application| application.application_type == PRINCIPAL_APPROVAL_APPLICATION} |
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.
Why is this portion of code being removed? Will this allow both the teacher applicant and the associated admin/principal/school leader to be able to see the status of the same application?
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 line ensures there is a status for each application record (so both teacher applications and principal approval applications, since both inherit from application_base). It doesn't affect who can see what.
We are already checking status_is_valid_for_application_type
, so that line covers it because there are statuses defined for all application_base records here https://github.com/code-dot-org/code-dot-org/blob/staging/dashboard/app/models/pd/application/application_base.rb#L171
(this method is overridden in the teacher application model)
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.
I'm guessing this line was here before we had the more specific validation via status_is_valid_for_application_type
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.
Oh gotcha, thank you!
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.
Just to double check, would any existing entries in this table now be invalid?
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.
Good question. We are removing a validation -- would that spark new validation errors? I can't imagine it would, but is there a better way to check?
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.
It would only cause problems if someone tried to save the old application and it didn't have a status
. You could query the DB to see if any row is in that situation but if you're reasonably confident there isn't one, that's good enough for me.
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.
Ah I see. But if it did not have a status, I would think nothing would be triggered because this validation is now completely removed? It's already passing the other status validation above too.
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.
Just ran this on production, so we're good here 👍
[production] dashboard > Pd::Application::ApplicationBase.where(status: nil)
=> #<ActiveRecord::Relation []>
refute TEACHER_APPLICATION_CLASS.last.response_scores | ||
assert_response :created | ||
end | ||
|
||
test 'autoscores and queues email once application is submitted' do | ||
application_hash = build :pd_teacher_application_hash_common, :csp | ||
test 'autoscores and queues emails on submit when approval is required' do |
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.
I feel like prioritizing readability might make sense since we are shifting lots of terminology around statuses and desired behaviors so having each one more explicitly laid out might be better as we home in on the desired outcome? That's just a thought though, I'm not dug in on this by any means!
|
||
sign_in @applicant | ||
|
||
put :create, params: @test_params | ||
put :create, params: {form_data: application_hash} |
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.
Nit?: I noticed {form_data: application_hash}
a couple times replacing @test_params, would it be worth defining 2 different set of params at the top based on their differences so that this can be re-used more easily? If that wouldn't work or would end up being too cumbersome then please ignore this!
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.
Good call. I just looked to see if we could define something for {form_data: application_hash}
at the top. We're defining different application_hash
variables inside each test based on the regional parter we create inside the test. BUT it looks like we could just have two regional partners created at the top and then create application hashes based on those regional partners! I'll look into that 👍
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.
I made this update!
@@ -11,6 +11,17 @@ def new_form | |||
) | |||
end | |||
|
|||
def new_status | |||
return 'incomplete' if ActiveModel::Type::Boolean.new.cast(params[:isSaving]) |
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.
TIL!
if status | ||
@application.status = status | ||
end | ||
form.status = new_status if form.is_a? Pd::Application::TeacherApplication |
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.
Is this fixing a bug? It makes sense but I'm not sure how it fits into the rest of this PR
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 should only be run for teacher apps because it's not relevant for principal apps (or any other app type that inherits from form).
The previous code was a bit janky (I wrote it so I can say that tehe) because the local status
variable was only set with teacher apps
define_method(:"#{attribute}?") do | ||
status == attribute | ||
end | ||
end | ||
|
||
def set_applied_date | ||
self.applied_at = Time.now if applied_at.nil? && unreviewed? | ||
self.applied_at = Time.now if applied_at.nil? && (unreviewed? || awaiting_admin_approval?) |
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.
You check or either unreviewed?
or awaiting_admin_approval?
a couple times. Would it be worth adding a helper method called something like awaiting_action?
(my knowledge in this space is limited so feel free to wordsmith). It's also only a couple of places so it might not be worth it. Thoughts?
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.
That's a good call. Maybe status_on_submit? Or submitted_status?
This line could also be !incomplete? I'll think on it
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.
Updated to status_on_submit?
–– I'm sure we'll be using this more in the future. Good call!
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.
Looks great!
We have a new status for teacher applications:
awaiting_admin_approval
. The status itself was added in #48804.There are two things that need to happen with this new status:
unreviewed
. Now, it should only beunreviewed
if the RP set that admin approval is "selective," i.e. they manually decide for each application if it requires admin approval. Otherwise, it should beawaiting_admin_approval
. << This PR addresses this part.unreviewed
toawaiting_admin_approval
if it is now required, and it should change fromawaiting_admin_approval
tounreviewed
if it is no longer required. << A future PR will address this part.Links
Update Application Statuses spec
Testing story
I added unit tests for each change. I tested manually that I can still save and submit the teacher application. I will test manually on the adhoc that the statuses are being set correctly once the second task mentioned above is complete, and both are merged into staging.
Deployment strategy
Teacher applications are still closed for this year; the risk is low to merge now and test manually on the adhoc.
Follow-up work
The second task mentioned above will be addressed in a separate PR.
Privacy
Security
Caching
PR Checklist: