marcj / php-rest-service

Php-Rest-Service is a very simple and fast PHP class for server-side RESTful JSON APIs.
MIT License
216 stars 74 forks source link

Advice Needed - How can I globally restrict results based on clients User ID matched to a column in all tables #44

Closed Fever905 closed 4 years ago

Fever905 commented 4 years ago

Hey this isn't an issue but I'm looking for customization advice - or maybe there is a way to do this without modifying?

I'm looking to base the GET requests on all tables based on a column in that matches the authenticated user's username.

For example we have a field called LAB_CODE which contains the user's ID. When a GET is performed we want to only return results that match the user ID of the system making the request. Basically it's like a pre-set hidden filter.

Is this possible to implement and can you give me a high level idea of where I should start to implement this? I am an experienced programmer so I just need some basic advice on how you would do something like this.

Thank you so much in advance.

Michael DeMutis / Fever905

marcj commented 4 years ago

I wouldn't use php-rest-service anymore for anything more complicated.

However, if you stick with php-rest-service, you should put those information LAB_CODE into the php session and request it quere necessary via $_SESSION['LAB_CODE']. You have to set it tho initially when your user logs in.

Fever905 commented 4 years ago

No this php-rest-service is perfect for our needs. I've already got it setup and running and exported the open-api dump into Postman. We're just sharing data between our labs around the world. It's just oil-analysis test result data for construction equipment, truck fleets stuff like that so it doesn't need to be super secure or complex. And we've got it assigned to its own database so that they can only access the data that we put in there.

The LAB_CODE will be the same as the username which is set after the first request is made I think. So I guess I would need to add this to $whereClause on selectSingle and selectMultiple ?

marcj commented 4 years ago

Exactly

Fever905 commented 4 years ago

Awesome, thank you. :)

Fever905 commented 4 years ago

LOL oops sorry this isn't the REST service I'm using hehe. I got mixed up between yours and this one!! https://github.com/mevdschee/php-crud-api