Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ js/
.code-workspace
.DS_Store
.idea/
.phpunit.result.cache
.vscode/
.vscode-upload.json
.*.sw*
Expand Down
7 changes: 4 additions & 3 deletions appinfo/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,6 @@
['name' => 'page#getPublicFileShare', 'url' => '/getPublicFileShare', 'verb' => 'POST'],
['name' => 'page#importCsvProject', 'url' => '/import-csv-project', 'verb' => 'GET'],
['name' => 'page#importSWProject', 'url' => '/import-sw-project', 'verb' => 'GET'],
['name' => 'page#exportCsvProject', 'url' => '/export-csv-project/{projectid}', 'verb' => 'GET'],
['name' => 'page#exportCsvStatistics', 'url' => '/export-csv-statistics/{projectid}', 'verb' => 'GET'],
['name' => 'page#exportCsvSettlement', 'url' => '/export-csv-settlement/{projectid}', 'verb' => 'GET'],
['name' => 'page#webGetProjects', 'url' => '/projects', 'verb' => 'GET'],
['name' => 'page#webGetProjects2', 'url' => '/getProjects', 'verb' => 'POST'],
['name' => 'page#webCreateProject', 'url' => '/projects', 'verb' => 'POST'],
Expand All @@ -154,5 +151,9 @@
['name' => 'page#pubLogin', 'url' => 'login', 'verb' => 'GET'],
['name' => 'page#pubProject', 'url' => 'project', 'verb' => 'POST'],
['name' => 'page#publicShareLinkPage', 'url' => 's/{token}', 'verb' => 'GET'],

['name' => 'export#exportCsvProject', 'url' => '/export-csv-project/{projectId}', 'verb' => 'GET'],
['name' => 'export#exportCsvSettlement', 'url' => '/export-csv-settlement/{projectId}', 'verb' => 'GET'],
['name' => 'export#exportCsvStatistics', 'url' => '/export-csv-statistics/{projectId}', 'verb' => 'GET'],
]
];
130 changes: 130 additions & 0 deletions lib/Controller/ExportController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
<?php

/**
* Nextcloud - cospend
*
* This file is licensed under the Affero General Public License version 3 or
* later. See the COPYING file.
*/

namespace OCA\Cospend\Controller;

use OCA\Cospend\Service\ExportService;
use OCA\Cospend\Service\ProjectService;
use OCP\AppFramework\ApiController;
use OCP\AppFramework\Http\DataResponse;
use OCP\IL10N;
use OCP\IRequest;

class ExportController extends ApiController {
/**
* @var IL10N
*/
protected $translation;

/**
* @var ProjectService
*/
protected $projectService;

/**
* @var ExportService
*/
protected $exportService;

/**
* @var string|null
*/
private $userId;

/**
* @param string $appName
* @param IRequest $request
* @param IL10N $translation
* @param ProjectService $projectService
* @param ExportService $exportService
* @param string|null $userId
*/
public function __construct(string $appName,
IRequest $request,
IL10N $translation,
ProjectService $projectService,
ExportService $exportService,
?string $userId) {
parent::__construct($appName, $request, 'GET');

$this->translation = $translation;
$this->projectService = $projectService;
$this->exportService = $exportService;
$this->userId = $userId;
}

/**
* @NoAdminRequired
*/
public function exportCsvProject(string $projectId, ?string $name = null, ?string $uid = null): DataResponse {
$userId = $uid;
if ($this->userId) {
$userId = $this->userId;
}

if ($this->projectService->userCanAccessProject($userId, $projectId)) {
$result = $this->exportService->exportCsvProject($projectId, $userId, $name);
if (isset($result['path'])) {
return new DataResponse($result);
} else {
return new DataResponse($result, 400);
}
} else {
return new DataResponse(
['message' => $this->translation->t('You are not allowed to export this project')],
403
);
}
}

/**
* @NoAdminRequired
*/
public function exportCsvSettlement(string $projectId, ?int $centeredOn = null, ?int $maxTimestamp = null): DataResponse {
if ($this->projectService->userCanAccessProject($this->userId, $projectId)) {
$result = $this->exportService->exportCsvSettlement($projectId, $this->userId, $centeredOn, $maxTimestamp);
if (isset($result['path'])) {
return new DataResponse($result);
} else {
return new DataResponse($result, 400);
}
} else {
return new DataResponse(
['message' => $this->translation->t('You are not allowed to export this project settlement')],
403
);
}
}

/**
* @NoAdminRequired
*/
public function exportCsvStatistics(string $projectId, ?int $tsMin = null, ?int $tsMax = null,
?int $paymentModeId = null, ?int $category = null,
?float $amountMin = null, ?float $amountMax = null, int $showDisabled = 1,
?int $currencyId = null): DataResponse {
if ($this->projectService->userCanAccessProject($this->userId, $projectId)) {
$result = $this->exportService->exportCsvStatistics(
$projectId, $this->userId, $tsMin, $tsMax,
$paymentModeId, $category, $amountMin, $amountMax,
$showDisabled !== 0, $currencyId
);
if (isset($result['path'])) {
return new DataResponse($result);
} else {
return new DataResponse($result, 400);
}
} else {
return new DataResponse(
['message' => $this->translation->t('You are not allowed to export this project statistics')],
403
);
}
}
}
69 changes: 0 additions & 69 deletions lib/Controller/PageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3143,75 +3143,6 @@ public function getPublicFileShare(string $path): DataResponse {
return $response;
}

/**
* @NoAdminRequired
*/
public function exportCsvSettlement(string $projectid, ?int $centeredOn = null, ?int $maxTimestamp = null): DataResponse {
if ($this->projectService->userCanAccessProject($this->userId, $projectid)) {
$result = $this->projectService->exportCsvSettlement($projectid, $this->userId, $centeredOn, $maxTimestamp);
if (isset($result['path'])) {
return new DataResponse($result);
} else {
return new DataResponse($result, 400);
}
} else {
return new DataResponse(
['message' => $this->trans->t('You are not allowed to export this project settlement')],
403
);
}
}

/**
* @NoAdminRequired
*/
public function exportCsvStatistics(string $projectid, ?int $tsMin = null, ?int $tsMax = null,
?int $paymentModeId = null, ?int $category = null,
?float $amountMin = null, ?float $amountMax = null, int $showDisabled = 1,
?int $currencyId = null): DataResponse {
if ($this->projectService->userCanAccessProject($this->userId, $projectid)) {
$result = $this->projectService->exportCsvStatistics(
$projectid, $this->userId, $tsMin, $tsMax,
$paymentModeId, $category, $amountMin, $amountMax,
$showDisabled !== 0, $currencyId
);
if (isset($result['path'])) {
return new DataResponse($result);
} else {
return new DataResponse($result, 400);
}
} else {
return new DataResponse(
['message' => $this->trans->t('You are not allowed to export this project statistics')],
403
);
}
}

/**
* @NoAdminRequired
*/
public function exportCsvProject(string $projectid, ?string $name = null, ?string $uid = null): DataResponse {
$userId = $uid;
if ($this->userId) {
$userId = $this->userId;
}

if ($this->projectService->userCanAccessProject($userId, $projectid)) {
$result = $this->projectService->exportCsvProject($projectid, $userId, $name);
if (isset($result['path'])) {
return new DataResponse($result);
} else {
return new DataResponse($result, 400);
}
} else {
return new DataResponse(
['message' => $this->trans->t('You are not allowed to export this project')],
403
);
}
}

/**
* @NoAdminRequired
*/
Expand Down
17 changes: 8 additions & 9 deletions lib/Cron/AutoExport.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,33 +9,32 @@

namespace OCA\Cospend\Cron;

use OCA\Cospend\Service\ProjectService;
use OCA\Cospend\Service\ExportService;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\BackgroundJob\TimedJob;

class AutoExport extends TimedJob {
/**
* @var ProjectService
* @var ExportService
*/
private $projectService;
private $exportService;

/**
* @param ITimeFactory $time
* @param ProjectService $projectService
* @param ExportService $exportService
*/
public function __construct(ITimeFactory $time, ProjectService $projectService) {
public function __construct(ITimeFactory $time, ExportService $exportService) {
parent::__construct($time);
$this->projectService = $projectService;

// Run each day
$this->setInterval(24 * 60 * 60);
$this->exportService = $exportService;
$this->setInterval(24 * 60 * 60); // Run each day
}

/**
* @param $argument
* @return void
*/
protected function run($argument): void {
$this->projectService->cronAutoExport();
$this->exportService->cronAutoExport();
}
}
15 changes: 15 additions & 0 deletions lib/Exception/ErrorMessageException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

/**
* Nextcloud - cospend
*
* This file is licensed under the Affero General Public License version 3 or
* later. See the COPYING file.
*/

namespace OCA\Cospend\Exception;

use Exception;

class ErrorMessageException extends Exception {
}
64 changes: 64 additions & 0 deletions lib/Service/AbstractService.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?php

/**
* Nextcloud - cospend
*
* This file is licensed under the Affero General Public License version 3 or
* later. See the COPYING file.
*/

namespace OCA\Cospend\Service;

use OCP\Files\IRootFolder;
use OCP\IConfig;
use OCP\IL10N;
use OCP\IUserManager;
use Psr\Log\LoggerInterface;

abstract class AbstractService
{
/**
* @var IL10N
*/
protected $translation;

/**
* @var IConfig
*/
protected $config;

/**
* @var IUserManager
*/
protected $userManager;

/**
* @var IRootFolder
*/
protected $rootFolder;

/**
* @var LoggerInterface
*/
protected $logger;

/**
* @param IL10N $translation
* @param IConfig $config
* @param IUserManager $userManager
* @param IRootFolder $rootFolder
* @param LoggerInterface $logger
*/
public function __construct(IL10N $translation,
IConfig $config,
IUserManager $userManager,
IRootFolder $rootFolder,
LoggerInterface $logger)
{
$this->translation = $translation;
$this->config = $config;
$this->userManager = $userManager;
$this->rootFolder = $rootFolder;
$this->logger = $logger;
}
}
Loading