88namespace OCA \Approval \Controller ;
99
1010use OCA \Approval \AppInfo \Application ;
11+ use OCA \Approval \Exceptions \OutdatedEtagException ;
1112use OCA \Approval \Service \ApprovalService ;
1213use OCA \Approval \Service \RuleService ;
13-
14+ use OCP \ AppFramework \ Http ;
1415use OCP \AppFramework \Http \Attribute \NoAdminRequired ;
1516use OCP \AppFramework \Http \DataResponse ;
1617use OCP \AppFramework \OCSController ;
18+ use OCP \IL10N ;
1719use OCP \IRequest ;
1820
1921class ApprovalController extends OCSController {
@@ -23,6 +25,7 @@ public function __construct(
2325 IRequest $ request ,
2426 private ApprovalService $ approvalService ,
2527 private RuleService $ ruleService ,
28+ private IL10N $ l10n ,
2629 private ?string $ userId ,
2730 ) {
2831 parent ::__construct ($ appName , $ request );
@@ -76,25 +79,39 @@ public function getPendingNodes(?int $since = null): DataResponse {
7679 *
7780 * @param int $fileId
7881 * @param string|null $message
82+ * @param string|null $etag
7983 * @return DataResponse
8084 */
8185 #[NoAdminRequired]
82- public function approve (int $ fileId , ?string $ message = '' ): DataResponse {
83- $ this ->approvalService ->approve ($ fileId , $ this ->userId , $ message );
84- return new DataResponse (1 );
86+ public function approve (int $ fileId , ?string $ message = '' , ?string $ etag = '' ): DataResponse {
87+ try {
88+ if ($ this ->approvalService ->approve ($ fileId , $ this ->userId , $ message , $ etag )) {
89+ return new DataResponse ([]);
90+ }
91+ return new DataResponse ([], Http::STATUS_BAD_REQUEST );
92+ } catch (OutdatedEtagException ) {
93+ return new DataResponse (['error ' => $ this ->l10n ->t ('The file/folder you tried to approve has an outdated content, please reload and review it again ' )], Http::STATUS_BAD_REQUEST );
94+ }
8595 }
8696
8797 /**
8898 * Reject a file
8999 *
90100 * @param int $fileId
91101 * @param string|null $message
102+ * @param string|null $etag
92103 * @return DataResponse
93104 */
94105 #[NoAdminRequired]
95- public function reject (int $ fileId , ?string $ message = '' ): DataResponse {
96- $ this ->approvalService ->reject ($ fileId , $ this ->userId , $ message );
97- return new DataResponse (1 );
106+ public function reject (int $ fileId , ?string $ message = '' , ?string $ etag = '' ): DataResponse {
107+ try {
108+ if ($ this ->approvalService ->reject ($ fileId , $ this ->userId , $ message , $ etag )) {
109+ return new DataResponse ([]);
110+ }
111+ return new DataResponse ([], Http::STATUS_BAD_REQUEST );
112+ } catch (OutdatedEtagException ) {
113+ return new DataResponse (['error ' => $ this ->l10n ->t ('The file/folder you tried to reject has an outdated content, please reload and review it again ' )], Http::STATUS_BAD_REQUEST );
114+ }
98115 }
99116
100117 /**
0 commit comments