-
-
Notifications
You must be signed in to change notification settings - Fork 3.2k
FIX #35655 Check if API user has rights to see all thirdparties #36024
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
base: 22.0
Are you sure you want to change the base?
Conversation
|
The new error message |
|
errors does not seem to be in my changes |
|
@JonBendtsen |
if they have How do I check if they are a sales person for the client? |
|
If the user does not have "$user->hasRight('societe', 'lire')", they do not have the right. If the user has "$user->hasRight('societe', 'lire')" but not "$user->hasRight('societe', 'client', 'voir')", it is necessary to check if they are associated as a salesperson with the client. |
|
@JonBendtsen check function getSalesRepresentatives() in societe.class.php (use $mode parameter with value 1) |
|
@JonBendtsen maybe you can see and use the "protected static function _checkAccessToResource()" in api.class.php |
yeah, but I need to get the socid, and there is no $socid, would that be during the loop, and field == 'socid' then I use the $value? |
|
@JonBendtsen when you have a fetch of contract before you can use "$contract->socid" and for the "post" check if "socid" exists and use "$request_data['socid']" |
Check if API user has rights to see all thirdparties - though perhaps we should check if the user has rights to this particular thirdparty in this contract?
|
@hregis do you like this solution? See results in comments below |
|
@JonBendtsen no no... Just a moment! |
…f permissions and/or is the sales representative for the thirdparty
@hregis Do you like more the method used in the post function? that does save a lot of coding |
|
PUT updated to use same method as in POST, and "he's checking it twice" ;-) both if there is access to the old socid and the new socid if it is being updated |
|
@eldy did this PR get burried and out of your sight? |
|
|
||
| $socid = (int) $request_data['socid']; | ||
| $thirdparties = new Thirdparties(); | ||
| $thirdparty_result = $thirdparties->get((int) $socid); |
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.
Using the get of another api is doing a different job that what we want. We just want to check if thirdparty exists.
For this, a standard :
$thirdpartytmp = new Societe($db);
$thirdparty_result = $thirdpartytmp>fetch($socid);
if ($thirdparty_result <= 0) {
throw new RestException(404, 'Thirdparty not found or not allowed');
}
is enough (we don't need to load the discounts, check the massemailing status, ... done by the get of API).
If use with permission to create contract has no permission on thirdparties, he should not have more detail if thirdparty exists or not (only the one who haspermission to read thirdparties is allowed to get this information). This is another reason why we should not use the getofapi but the get of thirdparty here.
It is samefor the put.
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.
@eldy I have made the requested changes - but I can not get PUT to work reliably
If I use a non existing socid, then it fails as it should.
If I don't have access to the existing socid in the contract, then it fails as it should.
If I do have access to the existing socid in the contract and I update with the same socid id it works, BUT if I try to change this to a new socid that I do not have access to, then it does indeed make the change to the socid to the one without access, and then it tells me I have no access.
I do not know how to fix this issue :-(
…at the user does not have permission to, then it STILL updates the contract, and then it gets the contract after update and tells me I do not have access



FIX #35655 Check if API user has rights to see all thirdparties
This PR is a fix for #35655, checking if the api user/key has access to the thirdparty used in the contract