3636use OCP \AppFramework \OCS \OCSForbiddenException ;
3737use OCP \AppFramework \OCSController ;
3838use OCP \Constants ;
39+ use OCP \EventDispatcher \IEventDispatcher ;
3940use OCP \Federation \Exceptions \ProviderCouldNotAddShareException ;
4041use OCP \Federation \Exceptions \ProviderDoesNotExistsException ;
4142use OCP \Federation \ICloudFederationFactory ;
4445use OCP \IDBConnection ;
4546use OCP \IRequest ;
4647use OCP \IUserManager ;
48+ use OCP \Log \Audit \CriticalActionPerformedEvent ;
4749use OCP \Share ;
4850use OCP \Share \Exceptions \ShareNotFound ;
4951use Psr \Log \LoggerInterface ;
@@ -83,6 +85,9 @@ class RequestHandlerController extends OCSController {
8385 /** @var ICloudFederationProviderManager */
8486 private $ cloudFederationProviderManager ;
8587
88+ /** @var IEventDispatcher */
89+ private $ eventDispatcher ;
90+
8691 public function __construct (string $ appName ,
8792 IRequest $ request ,
8893 FederatedShareProvider $ federatedShareProvider ,
@@ -94,7 +99,8 @@ public function __construct(string $appName,
9499 ICloudIdManager $ cloudIdManager ,
95100 LoggerInterface $ logger ,
96101 ICloudFederationFactory $ cloudFederationFactory ,
97- ICloudFederationProviderManager $ cloudFederationProviderManager
102+ ICloudFederationProviderManager $ cloudFederationProviderManager ,
103+ IEventDispatcher $ eventDispatcher
98104 ) {
99105 parent ::__construct ($ appName , $ request );
100106
@@ -108,6 +114,7 @@ public function __construct(string $appName,
108114 $ this ->logger = $ logger ;
109115 $ this ->cloudFederationFactory = $ cloudFederationFactory ;
110116 $ this ->cloudFederationProviderManager = $ cloudFederationProviderManager ;
117+ $ this ->eventDispatcher = $ eventDispatcher ;
111118 }
112119
113120 /**
@@ -156,6 +163,11 @@ public function createShare() {
156163 try {
157164 $ provider = $ this ->cloudFederationProviderManager ->getCloudFederationProvider ('file ' );
158165 $ provider ->shareReceived ($ share );
166+ if ($ sharedByFederatedId === $ ownerFederatedId ) {
167+ $ this ->eventDispatcher ->dispatchTyped (new CriticalActionPerformedEvent ('A new federated share with "%s" was created by "%s" and shared with "%s" ' , [$ name , $ ownerFederatedId , $ shareWith ]));
168+ } else {
169+ $ this ->eventDispatcher ->dispatchTyped (new CriticalActionPerformedEvent ('A new federated share with "%s" was shared by "%s" (resource owner is: "%s") and shared with "%s" ' , [$ name , $ sharedByFederatedId , $ ownerFederatedId , $ shareWith ]));
170+ }
159171 } catch (ProviderDoesNotExistsException $ e ) {
160172 throw new OCSException ('Server does not support federated cloud sharing ' , 503 );
161173 } catch (ProviderCouldNotAddShareException $ e ) {
@@ -243,6 +255,7 @@ public function acceptShare($id) {
243255 try {
244256 $ provider = $ this ->cloudFederationProviderManager ->getCloudFederationProvider ('file ' );
245257 $ provider ->notificationReceived ('SHARE_ACCEPTED ' , $ id , $ notification );
258+ $ this ->eventDispatcher ->dispatchTyped (new CriticalActionPerformedEvent ('Federated share with id "%s" was accepted ' , [$ id ]));
246259 } catch (ProviderDoesNotExistsException $ e ) {
247260 throw new OCSException ('Server does not support federated cloud sharing ' , 503 );
248261 } catch (ShareNotFound $ e ) {
@@ -275,6 +288,7 @@ public function declineShare($id) {
275288 try {
276289 $ provider = $ this ->cloudFederationProviderManager ->getCloudFederationProvider ('file ' );
277290 $ provider ->notificationReceived ('SHARE_DECLINED ' , $ id , $ notification );
291+ $ this ->eventDispatcher ->dispatchTyped (new CriticalActionPerformedEvent ('Federated share with id "%s" was declined ' , [$ id ]));
278292 } catch (ProviderDoesNotExistsException $ e ) {
279293 throw new OCSException ('Server does not support federated cloud sharing ' , 503 );
280294 } catch (ShareNotFound $ e ) {
@@ -307,6 +321,7 @@ public function unshare($id) {
307321 $ provider = $ this ->cloudFederationProviderManager ->getCloudFederationProvider ('file ' );
308322 $ notification = ['sharedSecret ' => $ token ];
309323 $ provider ->notificationReceived ('SHARE_UNSHARED ' , $ id , $ notification );
324+ $ this ->eventDispatcher ->dispatchTyped (new CriticalActionPerformedEvent ('Federated share with id "%s" was unshared ' , [$ id ]));
310325 } catch (\Exception $ e ) {
311326 $ this ->logger ->debug ('processing unshare notification failed: ' . $ e ->getMessage (), ['exception ' => $ e ]);
312327 }
@@ -381,6 +396,7 @@ public function updatePermissions($id) {
381396 $ ocmPermissions = $ this ->ncPermissions2ocmPermissions ((int )$ ncPermissions );
382397 $ notification = ['sharedSecret ' => $ token , 'permission ' => $ ocmPermissions ];
383398 $ provider ->notificationReceived ('RESHARE_CHANGE_PERMISSION ' , $ id , $ notification );
399+ $ this ->eventDispatcher ->dispatchTyped (new CriticalActionPerformedEvent ('Federated share with id "%s" has updated permissions "%s" ' , [$ id , implode (', ' , $ ocmPermissions )]));
384400 } catch (\Exception $ e ) {
385401 $ this ->logger ->debug ($ e ->getMessage (), ['exception ' => $ e ]);
386402 throw new OCSBadRequestException ();
0 commit comments