-
Notifications
You must be signed in to change notification settings - Fork 19
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
Fixes #65: Submit online application to Prof M School #78
Conversation
lschaefer-sugarcrm
commented
Jun 20, 2018
- Add new fields for the application form
- Update the Applicant record view layout
- Create Online Application Form
- Create page that is displayed when user submits application form
- Update Postman Collection to create campaigns
- Update Postman sample data to include application data
- Add unit tests
- Add acceptance tests
- Add documentation
d098dc7
to
5805fc5
Compare
* | ||
* @return \SugarQuery | ||
*/ | ||
protected function getSugarQuery() |
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.
What's the motivation of this helper? It would seem to me like you'd want to build the SQL query in this method instead of in getOnlineApplicationCampaignId()?
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 created this helper so that I would be able to mock the SugarQuery in automated tests. I followed a similar pattern in https://github.com/sugarcrm/school/blob/master/package/src/custom/modules/Contacts/Students_Gradebook.php.
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.
Could we add a comment to PHPdoc that explains purpose?
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.
Yes, updated
* | ||
* @return null|\SugarBean | ||
*/ | ||
protected function getNewCampaignBean() |
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 meant to be overridable? Is the idea we could support different types of SugarBeans?
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.
Same idea for this one. I broke out the Campaign bean so I could mock it in automated tests.
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.
Same.
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.
Yes, updated
$results = $q->execute(); | ||
|
||
if(sizeof($results) != 1 || !$results[0]['id']){ | ||
throw new \Exception("Unable to find ID for the Campaign named Online Applications"); |
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.
Does this message get displayed to user? If so, we should consider using a language label.
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! I tried to find a way to display this message to the user, but I couldn't figure out how. No matter what I did, the page just displayed "We are sorry, the server is currently unavailable, please try again later." and the error message never displayed in the console. Is there a way to push a more informative message to the browser?
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.
Yeah, you could echo
a message/HTML here which should get displayed in browser. Throwing an exception will cause server to treat it like an HTTP error response. This exception message is likely only placed in php error log.
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 played around with this some more. If I echo a message, it gets sent back as the Campaign ID, which isn't great. I decided to add some extra error handling to the Application Form to display an alert if the Campaign ID comes back empty (this would happen if someone installed Prof M without inserting the sample data).
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.
If you convert this to a REST API then you can throw a SugarApiException or extend SugarAPiExcpeiont to create your own. That'll return a JSON encoded error message that'll allow a consumer to do error handling.
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've updated the exception and error handling.
- Add new fields for the application form - Update the Applicant record view layout - Create Online Application Form - Create page that is displayed when user submits application form - Update Postman Collection to create campaigns - Update Postman sample data to include application data - Add unit tests - Add acceptance tests - Add documentation
5805fc5
to
a34a0b4
Compare
} | ||
}); | ||
// Get the ID of the Online Applications Campaign | ||
xhr.open("GET", urlBase + "/index.php?entryPoint=getOnlineApplicationsCampaign"); |
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 an entrypoint? This is simply returning a record ID. If it's meant to be machine consumable then it should be a REST API endpoint. You can make it a public endpoint which should allow it to be accessible without an OAuth token. It should be relatively straight forward to convert to a public rest API.
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've updated the code to be an endpoint instead of an entrypoint. I've emailed @rhoggSugarcrm to see if I'm testing the endpoint in the best way.
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 currently recommend using Thorn to test REST API endpoints, but it may be a bit of work to get it set up.
PHPUnit is certainly adequate until then.
06c9be3
to
a3bb8fc
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.
One last nitpick.
|
||
} | ||
|
||
?> |
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.
Remove pls. :)
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 catch! Updated.
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.
May I make a recommendation (as the guy who was pinged on a totally unrelated issue and is now butting in because he didn't unsubscribe 😝)?
If you add some sort of linting checks to .travis.yml hopefully PHP closing tags and similar would be caught automatically. IMHO that's a best practice anyhow 😸
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.
Lol - feel free to butt in! We have #41 on the backlog.
Remove entrypoint code and add tests Update Application Form to use REST endpoint Update Exception type Remove closing tag
a3bb8fc
to
2b32eb8
Compare