diff --git a/src/app/group/controllers/PrivilegeController.php b/src/app/group/controllers/PrivilegeController.php index c28e033b2b9e86910baf77b0b93edd058b1d5b8c..4b6928b961315191039a9272ec8ac811fc5f941b 100644 --- a/src/app/group/controllers/PrivilegeController.php +++ b/src/app/group/controllers/PrivilegeController.php @@ -4,6 +4,7 @@ namespace Group\controllers; use Basket\models\BasketModel; use Basket\models\GroupBasketModel; +use Basket\models\RedirectBasketModel; use Group\models\GroupModel; use Group\models\PrivilegeModel; use Resource\controllers\ResController; @@ -239,43 +240,59 @@ class PrivilegeController public static function canUpdateResource(array $args) { - ValidatorModel::notEmpty($args, ['currentUserId', 'resId']); - ValidatorModel::intVal($args, ['currentUserId', 'resId']); - ValidatorModel::arrayType($args, ['queryParams']); - - if (!empty($args['queryParams']['userId']) && !empty($args['queryParams']['groupId']) && !empty($args['queryParams']['basketId'])) { - $errors = ResourceListController::listControl(['groupId' => $args['queryParams']['groupId'], 'userId' => $args['queryParams']['userId'], 'basketId' => $args['queryParams']['basketId'], 'currentUserId' => $args['currentUserId']]); - if (!empty($errors['errors'])) { - return ['errors' => $errors['errors']]; - } + ValidatorModel::notEmpty($args, ['userId', 'resId']); + ValidatorModel::intVal($args, ['userId', 'resId']); - $user = UserModel::getById(['id' => $args['queryParams']['userId'], 'select' => ['user_id']]); - $basket = BasketModel::getById(['id' => $args['queryParams']['basketId'], 'select' => ['basket_id', 'basket_clause']]); - $group = GroupModel::getById(['id' => $args['queryParams']['groupId'], 'select' => ['group_id']]); + if (PrivilegeController::hasPrivilege(['privilegeId' => 'edit_resource', 'userId' => $args['userId']])) { + return ResController::hasRightByResId(['resId' => [$args['resId']], 'userId' => $args['userId']]); + } else { + $basketsClause = ''; - $groupBasket = GroupBasketModel::get(['select' => ['list_event_data', 'list_event'], 'where' => ['basket_id = ?', 'group_id = ?'], 'data' => [$basket['basket_id'], $group['group_id']]]); - $listEventData = json_decode($groupBasket[0]['list_event_data'], true); - if ($groupBasket[0]['list_event'] != 'processDocument' || !$listEventData['canUpdate']) { - return ['errors' => 'Basket can not update resources']; + $currentUser = UserModel::getById(['id' => $args['userId'], 'select' => ['id', 'user_id']]); + $groups = UserGroupModel::get(['select' => ['group_id'], 'where' => ['user_id = ?'], 'data' => [$currentUser['id']]]); + $groups = array_column($groups, 'group_id'); + if (!empty($groups)) { + $groups = GroupModel::get(['select' => ['group_id'], 'where' => ['id in (?)'], 'data' => [$groups]]); + $groups = array_column($groups, 'group_id'); + + $baskets = GroupBasketModel::get(['select' => ['basket_id'], 'where' => ['group_id in (?)', 'list_event = ?', "list_event_data->>'canUpdate' = ?"], 'data' => [$groups, 'processDocument', 'true']]); + $baskets = array_column($baskets, 'basket_id'); + if (!empty($baskets)) { + $clauses = BasketModel::get(['select' => ['basket_clause'], 'where' => ['basket_id in (?)'], 'data' => [$baskets]]); + + foreach ($clauses as $clause) { + $basketClause = PreparedClauseController::getPreparedClause(['clause' => $clause['basket_clause'], 'login' => $currentUser['user_id']]); + if (!empty($basketsClause)) { + $basketsClause .= ' or '; + } + $basketsClause .= "({$basketClause})"; + } + } } - $whereClause = PreparedClauseController::getPreparedClause(['clause' => $basket['basket_clause'], 'login' => $user['user_id']]); - $resource = ResModel::getOnView([ - 'select' => [1], - 'where' => [$whereClause, 'res_view_letterbox.res_id = ?'], - 'data' => [$args['resId']] - ]); - if (empty($resource)) { - return ['errors' => 'Resource does not belong to this basket']; + $assignedBaskets = RedirectBasketModel::getAssignedBasketsByUserId(['userId' => $currentUser['id']]); + foreach ($assignedBaskets as $basket) { + $hasProcessBaskets = GroupBasketModel::get(['select' => [1], 'where' => ['basket_id = ?', 'group_id = ?', 'list_event = ?', "list_event_data->>'canUpdate' = ?"], 'data' => [$basket['basket_id'], $basket['oldGroupId'], 'processDocument', 'true']]); + if (!empty($hasProcessBaskets)) { + $basketOwner = UserModel::getById(['id' => $basket['owner_user_id'], 'select' => ['user_id']]); + $basketClause = PreparedClauseController::getPreparedClause(['clause' => $basket['basket_clause'], 'login' => $basketOwner['user_id']]); + if (!empty($basketsClause)) { + $basketsClause .= ' or '; + } + $basketsClause .= "({$basketClause})"; + } } - } else { - if (!Validator::intVal()->validate($args['resId']) || !ResController::hasRightByResId(['resId' => [$args['resId']], 'userId' => $args['currentUserId']])) { - return ['errors' => 'Resource out of perimeter']; - } elseif (!PrivilegeController::hasPrivilege(['privilegeId' => 'edit_resource', 'userId' => $args['currentUserId']])) { - return ['errors' => 'Service forbidden']; + + try { + $res = ResModel::getOnView(['select' => [1], 'where' => ['res_id = ?', "({$basketsClause})"], 'data' => [$args['resId']]]); + if (empty($res)) { + return false; + } + } catch (\Exception $e) { + return false; } - } - return true; + return true; + } } } diff --git a/src/app/resource/controllers/ResController.php b/src/app/resource/controllers/ResController.php index c1a92e9f23a729411b0e59ccca338bdbba6c975a..88db020288b19a56e5c7ebffd2a8e8b29dbdd6fd 100755 --- a/src/app/resource/controllers/ResController.php +++ b/src/app/resource/controllers/ResController.php @@ -235,24 +235,18 @@ class ResController extends ResourceControlController public function update(Request $request, Response $response, array $args) { - $queryParams = $request->getQueryParams(); - - $control = PrivilegeController::canUpdateResource(['currentUserId' => $GLOBALS['id'], 'resId' => $args['resId'], 'queryParams' => $queryParams]); - if (!empty($control['errors'])) { - return $response->withStatus(403)->withJson(['errors' => $control['errors']]); + if (!Validator::intVal()->validate($args['resId'])) { + return ['errors' => 'Route resId is not an integer']; + } elseif (!PrivilegeController::canUpdateResource(['userId' => $GLOBALS['id'], 'resId' => $args['resId']])) { + return $response->withStatus(403)->withJson(['errors' => 'Service forbidden']); } $body = $request->getParsedBody(); - - $isProcessing = !empty($queryParams['basketId']); - if ($isProcessing) { - unset($body['destination']); - unset($body['diffusionList']); - } + $queryParams = $request->getQueryParams(); $onlyDocument = !empty($queryParams['onlyDocument']); - $control = ResourceControlController::controlUpdateResource(['body' => $body, 'resId' => $args['resId'], 'isProcessing' => $isProcessing, 'onlyDocument' => $onlyDocument]); + $control = ResourceControlController::controlUpdateResource(['body' => $body, 'resId' => $args['resId'], 'onlyDocument' => $onlyDocument]); if (!empty($control['errors'])) { return $response->withStatus(400)->withJson(['errors' => $control['errors']]); } diff --git a/src/app/resource/controllers/ResourceControlController.php b/src/app/resource/controllers/ResourceControlController.php index 14011286e00b1ba9955add1cbddce3cb632c9d28..04612c30d455fafaee6f837deea60521b79311be 100644 --- a/src/app/resource/controllers/ResourceControlController.php +++ b/src/app/resource/controllers/ResourceControlController.php @@ -165,7 +165,7 @@ class ResourceControlController } $body['modelId'] = $resource['model_id']; - $control = ResourceControlController::controlIndexingModelFields(['body' => $body, 'isProcessing' => $args['isProcessing']]); + $control = ResourceControlController::controlIndexingModelFields(['body' => $body, 'isUpdating' => true]); if (!empty($control['errors'])) { return ['errors' => $control['errors']]; } @@ -364,7 +364,7 @@ class ResourceControlController return ['errors' => "Body customFields[{$customFieldId}] is not a date"]; } } - } elseif ($indexingModelField['identifier'] == 'destination' && !empty($args['isProcessing'])) { + } elseif ($indexingModelField['identifier'] == 'destination' && !empty($args['isUpdating'])) { continue; } elseif ($indexingModelField['mandatory'] && !isset($body[$indexingModelField['identifier']])) { return ['errors' => "Body {$indexingModelField['identifier']} is not set"]; diff --git a/src/app/signatureBook/controllers/SignatureBookController.php b/src/app/signatureBook/controllers/SignatureBookController.php index 5f75f4eea80483978d5622d8dd4e5b906cc808e0..b2a22395f1d91cabb54a64004c12c45bbf8c3d2f 100755 --- a/src/app/signatureBook/controllers/SignatureBookController.php +++ b/src/app/signatureBook/controllers/SignatureBookController.php @@ -26,7 +26,6 @@ use Convert\models\AdrModel; use Entity\models\ListInstanceModel; use Group\controllers\PrivilegeController; use Group\models\GroupModel; -use Link\models\LinkModel; use Note\models\NoteModel; use Priority\models\PriorityModel; use Resource\controllers\ResController; diff --git a/src/frontend/app/indexation/indexing-form/indexing-form.component.ts b/src/frontend/app/indexation/indexing-form/indexing-form.component.ts index b605a59c510985ef4e9d4102d3d6541bb9a04393..2b9043fd02305cd05214d5fbfdc674174cb69fae 100644 --- a/src/frontend/app/indexation/indexing-form/indexing-form.component.ts +++ b/src/frontend/app/indexation/indexing-form/indexing-form.component.ts @@ -5,8 +5,8 @@ import { NotificationService } from '../../notification.service'; import { HeaderService } from '../../../service/header.service'; import { MatDialog } from '@angular/material/dialog'; import { AppService } from '../../../service/app.service'; -import { tap, catchError, finalize, exhaustMap, map, filter } from 'rxjs/operators'; -import { of, forkJoin, Subject, Observable } from 'rxjs'; +import { tap, catchError, exhaustMap, filter } from 'rxjs/operators'; +import { of} from 'rxjs'; import { SortPipe } from '../../../plugins/sorting.pipe'; import { CdkDragDrop, moveItemInArray, transferArrayItem } from '@angular/cdk/drag-drop'; import { FormControl, Validators, FormGroup, ValidationErrors, ValidatorFn, AbstractControl } from '@angular/forms'; @@ -337,14 +337,14 @@ export class IndexingFormComponent implements OnInit { return arrIndexingModels; } - saveData(userId: number, groupId: number, basketId: number) { + saveData() { return new Promise((resolve, reject) => { if (this.isValidForm()) { const formatdatas = this.formatDatas(this.getDatas()); - this.http.put(`../../rest/resources/${this.resId}?userId=${userId}&groupId=${groupId}&basketId=${basketId}`, formatdatas).pipe( + this.http.put(`../../rest/resources/${this.resId}`, formatdatas).pipe( tap(() => { - this.currentResourceValues = JSON.parse(JSON.stringify(this.getDatas(false)));; + this.currentResourceValues = JSON.parse(JSON.stringify(this.getDatas(false))); this.notify.success(this.lang.dataUpdated); resolve(true); }), diff --git a/src/frontend/app/process/process.component.ts b/src/frontend/app/process/process.component.ts index 6ba5f02d17f8bf98c160b7f524755e83dcdd6b8f..8bd742c04608cd17d1cc1fc9b2d42566bbb4670d 100755 --- a/src/frontend/app/process/process.component.ts +++ b/src/frontend/app/process/process.component.ts @@ -478,7 +478,7 @@ export class ProcessComponent implements OnInit { }), filter((data: string) => data === 'ok'), tap(() => { - this.indexingForm.saveData(this.currentUserId, this.currentGroupId, this.currentBasketId); + this.indexingForm.saveData(); setTimeout(() => { this.loadResource(); }, 400); @@ -537,7 +537,7 @@ export class ProcessComponent implements OnInit { } confirmModification() { - this.indexingForm.saveData(this.currentUserId, this.currentGroupId, this.currentBasketId); + this.indexingForm.saveData(); setTimeout(() => { this.loadResource(); }, 400); @@ -585,7 +585,7 @@ export class ProcessComponent implements OnInit { async saveTool() { if (this.currentTool === 'info' && this.indexingForm !== undefined) { - await this.indexingForm.saveData(this.currentUserId, this.currentGroupId, this.currentBasketId); + await this.indexingForm.saveData(); this.loadResource(); } else if (this.currentTool === 'diffusionList' && this.appDiffusionsList !== undefined) { await this.appDiffusionsList.saveListinstance();