Add conditional check for self-request in userRoute and fix customer_number type in orderBookingRoute
- Updated `getUserId` logic in `userRoute` to allow users to fetch their own user ID without requiring additional permissions. - Corrected `customer_number` type in `orderBookingRoute` to always return an array.
This commit is contained in:
@@ -110,7 +110,7 @@ class orderBookingRoute
|
||||
'department' => $user->getGroup()->getDepartments()
|
||||
] : []),
|
||||
...(!$has_permission_other ? [
|
||||
'customer_number' => (int)$user->customer_number->value()
|
||||
'customer_number' => [(int)$user->customer_number->value()]
|
||||
] : [])
|
||||
])
|
||||
));
|
||||
|
||||
@@ -148,9 +148,19 @@ class userRoute
|
||||
$this->get('/admin/customer/getUserId', function () {
|
||||
// Require the user to be logged in
|
||||
global $response;
|
||||
$this->requirePermission('get_user_id');
|
||||
// Get the user object
|
||||
$user = (new authentication())->get_user();
|
||||
// Check if it's the users own id request
|
||||
if (!!$user && $this->isParametersSet(['customer_number']) && (int)$this->fromRequest('customer_number') === (int)$user->customer_number->value()) {
|
||||
$response->success(
|
||||
[
|
||||
'user_id' => $user->id
|
||||
]
|
||||
);
|
||||
}
|
||||
// Otherwise, require permission.
|
||||
$this->requirePermission('get_user_id');
|
||||
|
||||
// Check if the request was successful
|
||||
if ($user) {
|
||||
// Log the incident
|
||||
|
||||
Reference in New Issue
Block a user