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

Migrate API controllers to lumen #1674

Merged
merged 48 commits into from
May 15, 2017
Merged

Migrate API controllers to lumen #1674

merged 48 commits into from
May 15, 2017

Conversation

rjmackay
Copy link
Contributor

@rjmackay rjmackay commented Apr 6, 2017

This pull request makes the following changes:

  • Define Config Controller
  • Define parent REST controller
  • Connect up laravel passport for oauth
    • Create ushahidiui client
    • Define scopes
    • Set up test data
    • Populate user in aura DI (or something)
  • Set CORS headers and respond to OPTIONS requests
  • Format error responses same as before conversion
  • Convert API controllers
  • Wire up data provider controllers to call back to Kohana (for now)
  • Remove old Kohana controllers

Test these changes by:

  • Run tests

Fixes #1372

Ping @ushahidi/platform


This change is Reviewable

@rjmackay rjmackay force-pushed the lumen-controllers branch 2 times, most recently from 6050834 to cdb48fe Compare April 6, 2017 01:22
@rjmackay rjmackay force-pushed the lumen-controllers branch 2 times, most recently from fcc76b7 to aa96ca9 Compare April 19, 2017 01:51
@rjmackay rjmackay force-pushed the lumen-controllers branch 2 times, most recently from 4f22036 to 4bf6300 Compare April 21, 2017 04:37
@rjmackay rjmackay requested a review from willdoran April 24, 2017 02:32
@rjmackay rjmackay force-pushed the lumen-controllers branch from 282b36a to a0cd168 Compare April 26, 2017 08:30
@rjmackay rjmackay force-pushed the lumen-controllers branch 4 times, most recently from 0248d2f to 9c197a8 Compare May 3, 2017 02:20
@rjmackay rjmackay force-pushed the lumen-controllers branch from 3ea2ab4 to 87e62f1 Compare May 11, 2017 02:38
- Remove custom CORS middleware
- Add tests for preflight requests
- Add tests for CORS requests
- Add tests for vanilla OPTIONS requests
- Add routes for /config and /posts OPTIONS requests
@rjmackay rjmackay changed the title WIP: Migrate REST controller to lumen Migrate API controllers to lumen May 11, 2017
@rjmackay
Copy link
Contributor Author

@willdoran given this is kinda huge heres the minimum that I think you need to review:

  • Double check my changes to the tests
  • Review the code in app/ outside of Http Controllers
    • Particularly check the wiring around Passport/auth
  • Review 1 or 2 controllers. Maybe look at the special cases for Post and Forms
  • Review the base RESTController

@willdoran
Copy link
Contributor

@rjmackay It all looks like it's coming along, I don't see anything wrong, the tests look good generally. I like the directory structure generally, though I wonder about whether we could adopt the approach of moving the tests right beside the code. I found that structure very effective in the rollcall js client. Though it may not be strictly kosher in the lumen structure.

My main concern looking at the Repos is that our data model needs to be restructured specifically for forms, stages, attributes and posts. If nothing else we should take the chance to rename them to match the client. That is probably true for Tags as well.

May be in Ireland we can updatet the data model. I think involving Dale in that would be good. By then we'll have basically 3/3.5 clients(mobile, facebot, comrades, client) and that should give us a good idea of common needs. Mobile particularly seems like it should force us down the road of lighter requests.

@rjmackay
Copy link
Contributor Author

My main concern looking at the Repos is that our data model needs to be restructured specifically for forms, stages, attributes and posts. If nothing else we should take the chance to rename them to match the client. That is probably true for Tags as well.

Agreed. I'm trying to just get rid of Kohana first, without rewriting the world in the process. So I'll get through the bulk of this, and the data provider refactor before I tackle the data model shift...

We'll have to come up with a plan for managing old clients if we shift the data model.

@rjmackay rjmackay merged commit f88979f into lumen May 15, 2017
];
}

protected function getPayload(Request $request)
Copy link
Contributor

Choose a reason for hiding this comment

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

Will this eventually be redundant in relation to the one getFilters(or vice versa) or is it just a place holder for now?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No. Filters are built from the query string, payload is built from the JSON body of a request.

*
* @return void
*/
public function store(Request $request)
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 nice to have clear verbs

class RevisionsController extends PostsController
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

* @return string
* @todo move this somewhere sensible
*/
public static function url($resource, $id = null)
Copy link
Contributor

Choose a reason for hiding this comment

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

I feel like this is part of a Util class - which I think should usually be called a misc class. Would it be better as a service class?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yup. See the @todo move this somewhere sensible :)

}

// Should we prevent this request from being cached?
if (! in_array($request->method(), $this->cacheableMethods)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This seems very manual, should cache control not belong to the web server?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is straight from the Kohana version, but in short no. The web server knows nothing about the content its serving, so it doesn't know if its safe to cache or not.
I think originally this was used to make sure GET responses were cachable, but POST/PUT/DELETE were not. I suspect its not actually working now

Passport::loadKeysFrom(storage_path('passport/'));
// Define possible scopes
// @todo simplify / improve these
Passport::tokensCan([
Copy link
Contributor

Choose a reason for hiding this comment

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

I like that these come with descriptions

@@ -45,7 +45,7 @@ Feature: Testing OAuth2 endpoints
Scenario: Authorized Posts Request
Given that I want to update a "Post"
And that its "id" is "95"
And that the request "Authorization" header is "Bearer testingtoken"
And that the oauth token is "testingtoken"
Copy link
Contributor

Choose a reason for hiding this comment

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

I like the language simplifications

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Mostly due to having to generate JWT tokens in RestContext grr.

@rjmackay rjmackay mentioned this pull request May 16, 2017
13 tasks
@rjmackay rjmackay deleted the lumen-controllers branch May 9, 2018 03:21
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.

2 participants