Verified Commit 4014f3e8 authored by Florian Azizian's avatar Florian Azizian
Browse files

FEAT #13274 TIME 1 can not add summarySheet after removed + change route to generate summarysheet

parent 0cd64f12
......@@ -427,9 +427,9 @@ $app->put('/resourcesList/users/{userId}/groups/{groupId}/baskets/{basketId}/loc
$app->put('/resourcesList/users/{userId}/groups/{groupId}/baskets/{basketId}/unlock', \Resource\controllers\ResourceListController::class . ':unlock');
$app->get('/resourcesList/users/{userId}/groups/{groupId}/baskets/{basketId}/filters', \Resource\controllers\ResourceListController::class . ':getFilters');
$app->put('/resourcesList/users/{userId}/groups/{groupId}/baskets/{basketId}/exports', \Resource\controllers\ExportController::class . ':updateExport');
$app->post('/resourcesList/users/{userId}/groups/{groupId}/baskets/{basketId}/summarySheets', \Resource\controllers\SummarySheetController::class . ':createList');
$app->put('/resourcesList/users/{userId}/groups/{groupId}/baskets/{basketId}/actions/{actionId}', \Resource\controllers\ResourceListController::class . ':setAction');
$app->put('/resourcesList/users/{userId}/groups/{groupId}/baskets/{basketId}/locked', \Resource\controllers\ResourceListController::class . ':areLocked');
$app->post('/resourcesList/summarySheets', \Resource\controllers\SummarySheetController::class . ':createList');
$app->get('/resourcesList/exportTemplate', \Resource\controllers\ExportController::class . ':getExportTemplates');
$app->put('/resourcesList/integrations', \Resource\controllers\ResController::class . ':setInIntegrations');
......
......@@ -39,40 +39,25 @@ use User\models\UserModel;
class SummarySheetController
{
public function createList(Request $request, Response $response, array $aArgs)
public function createList(Request $request, Response $response)
{
set_time_limit(240);
$errors = ResourceListController::listControl(['groupId' => $aArgs['groupId'], 'userId' => $aArgs['userId'], 'basketId' => $aArgs['basketId'], 'currentUserId' => $GLOBALS['id']]);
if (!empty($errors['errors'])) {
return $response->withStatus($errors['code'])->withJson(['errors' => $errors['errors']]);
}
$bodyData = $request->getParsedBody();
$units = empty($bodyData['units']) ? [] : $bodyData['units'];
if (!Validator::arrayType()->notEmpty()->validate($bodyData['resources'])) {
return $response->withStatus(403)->withJson(['errors' => 'Resources is not set or empty']);
}
if (!ResController::hasRightByResId(['resId' => $bodyData['resources'], 'userId' => $GLOBALS['id']])) {
return $response->withStatus(403)->withJson(['errors' => 'Document out of perimeter']);
}
$units = empty($bodyData['units']) ? [] : $bodyData['units'];
$bodyData['resources'] = array_slice($bodyData['resources'], 0, 500);
$basket = BasketModel::getById(['id' => $aArgs['basketId'], 'select' => ['basket_clause', 'basket_res_order', 'basket_name']]);
$user = UserModel::getById(['id' => $aArgs['userId'], 'select' => ['user_id']]);
$whereClause = PreparedClauseController::getPreparedClause(['clause' => $basket['basket_clause'], 'login' => $user['user_id']]);
$rawResourcesInBasket = ResModel::getOnView([
'select' => ['res_id'],
'where' => [$whereClause, 'res_view_letterbox.res_id in (?)'],
'data' => [$bodyData['resources']]
]);
$allResourcesInBasket = array_column($rawResourcesInBasket, 'res_id');
// $order = 'CASE res_view_letterbox.res_id ';
$order = '';
foreach ($bodyData['resources'] as $key => $resId) {
if (!in_array($resId, $allResourcesInBasket)) {
return $response->withStatus(403)->withJson(['errors' => 'Resources out of perimeter']);
}
$order .= "WHEN {$resId} THEN {$key} ";
}
$order .= 'END';
......
......@@ -154,7 +154,7 @@ export class SummarySheetComponent implements OnInit {
this.loading = true;
this.http.post('../rest/resourcesList/users/' + this.data.ownerId + '/groups/' + this.data.groupId + '/baskets/' + this.data.basketId + '/summarySheets', { units: this.formatSummarySheet(), resources: this.data.selectedRes }, { responseType: 'blob' })
this.http.post('../rest/resourcesList/summarySheets', { units: this.formatSummarySheet(), resources: this.data.selectedRes }, { responseType: 'blob' })
.subscribe((data) => {
if (data.type !== 'text/html') {
const downloadLink = document.createElement('a');
......
......@@ -102,7 +102,7 @@
<input matInput [placeholder]="this.translate.instant('lang.object')" [readonly]="!canManageMail()" [(ngModel)]="emailsubject"
maxlength="255">
<button mat-icon-button matSuffix *ngFor="let keyVal of emailAttachTool | keyvalue"
[disabled]="!canManageMail() ||(keyVal.key !== 'summarySheet' && (emailAttachTool[keyVal.key].list.length === 0) || (keyVal.key === 'summarySheet' && summarySheetUnits.length !== 0))"
[disabled]="!canManageMail() ||(keyVal.key !== 'summarySheet' && (emailAttachTool[keyVal.key].list.length === 0) || (keyVal.key === 'summarySheet' && !functions.empty(emailAttach['summarySheet'])))"
[title]="emailAttachTool[keyVal.key].title"
(click)="$event.stopPropagation();currentEmailAttachTool=keyVal.key;openSummarySheetModal(keyVal.key)"
[matMenuTriggerFor]="emailAttachListMenu">
......
......@@ -940,7 +940,7 @@ export class SentResourcePageComponent implements OnInit {
async createSummarySheet() {
return new Promise(resolve => {
this.http.post('../rest/resourcesList/users/' + this.data.currentUserId + '/groups/' + this.data.currentGroupId + '/baskets/' + this.data.currentBasketId + '/summarySheets?mode=base64', {
this.http.post('../rest/resourcesList/summarySheets?mode=base64', {
units: this.summarySheetUnits,
resources: [this.data.resId]
})
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment