Skip to content

Commit

Permalink
Log in audit log federated shares events
Browse files Browse the repository at this point in the history
Signed-off-by: Carl Schwan <carl@carlschwan.eu>
  • Loading branch information
CarlSchwan committed Mar 16, 2022
1 parent d59179a commit b17a148
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
use OCP\AppFramework\OCS\OCSForbiddenException;
use OCP\AppFramework\OCSController;
use OCP\Constants;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\Federation\Exceptions\ProviderCouldNotAddShareException;
use OCP\Federation\Exceptions\ProviderDoesNotExistsException;
use OCP\Federation\ICloudFederationFactory;
Expand All @@ -44,6 +45,7 @@
use OCP\IDBConnection;
use OCP\IRequest;
use OCP\IUserManager;
use OCP\Log\Audit\CriticalActionPerformedEvent;
use OCP\Share;
use OCP\Share\Exceptions\ShareNotFound;
use Psr\Log\LoggerInterface;
Expand Down Expand Up @@ -83,6 +85,9 @@ class RequestHandlerController extends OCSController {
/** @var ICloudFederationProviderManager */
private $cloudFederationProviderManager;

/** @var IEventDispatcher */
private $eventDispatcher;

public function __construct(string $appName,
IRequest $request,
FederatedShareProvider $federatedShareProvider,
Expand All @@ -94,7 +99,8 @@ public function __construct(string $appName,
ICloudIdManager $cloudIdManager,
LoggerInterface $logger,
ICloudFederationFactory $cloudFederationFactory,
ICloudFederationProviderManager $cloudFederationProviderManager
ICloudFederationProviderManager $cloudFederationProviderManager,
IEventDispatcher $eventDispatcher
) {
parent::__construct($appName, $request);

Expand All @@ -108,6 +114,7 @@ public function __construct(string $appName,
$this->logger = $logger;
$this->cloudFederationFactory = $cloudFederationFactory;
$this->cloudFederationProviderManager = $cloudFederationProviderManager;
$this->eventDispatcher = $eventDispatcher;
}

/**
Expand Down Expand Up @@ -243,6 +250,7 @@ public function acceptShare($id) {
try {
$provider = $this->cloudFederationProviderManager->getCloudFederationProvider('file');
$provider->notificationReceived('SHARE_ACCEPTED', $id, $notification);
$this->eventDispatcher->dispatchTyped(new CriticalActionPerformedEvent('Federated share with id "%s" was accepted', [$id]));
} catch (ProviderDoesNotExistsException $e) {
throw new OCSException('Server does not support federated cloud sharing', 503);
} catch (ShareNotFound $e) {
Expand Down Expand Up @@ -275,6 +283,7 @@ public function declineShare($id) {
try {
$provider = $this->cloudFederationProviderManager->getCloudFederationProvider('file');
$provider->notificationReceived('SHARE_DECLINED', $id, $notification);
$this->eventDispatcher->dispatchTyped(new CriticalActionPerformedEvent('Federated share with id "%s" was accepted', [$id]));
} catch (ProviderDoesNotExistsException $e) {
throw new OCSException('Server does not support federated cloud sharing', 503);
} catch (ShareNotFound $e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
use OCP\Federation\ICloudFederationProviderManager;
use OCP\Federation\ICloudFederationShare;
use OCP\Federation\ICloudIdManager;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\IDBConnection;
use OCP\IRequest;
use OCP\IUserManager;
Expand Down Expand Up @@ -100,6 +101,9 @@ class RequestHandlerControllerTest extends \Test\TestCase {
/** @var ICloudFederationShare|\PHPUnit\Framework\MockObject\MockObject */
private $cloudFederationShare;

/** @var IEventDispatcher|\PHPUnit\Framework\MockObject\MockObject */
private $eventDispatcher;

protected function setUp(): void {
$this->share = $this->getMockBuilder(IShare::class)->getMock();
$this->federatedShareProvider = $this->getMockBuilder('OCA\FederatedFileSharing\FederatedShareProvider')
Expand All @@ -124,7 +128,8 @@ protected function setUp(): void {
$this->cloudFederationProviderManager = $this->createMock(ICloudFederationProviderManager::class);
$this->cloudFederationProvider = $this->createMock(ICloudFederationProvider::class);
$this->cloudFederationShare = $this->createMock(ICloudFederationShare::class);

$this->eventDispatcher = $this->createMock(IEventDispatcher::class);
$this->eventDispatcher->expects($this->any())->method('dispatchTyped');

$this->logger = $this->createMock(LoggerInterface::class);

Expand All @@ -140,7 +145,8 @@ protected function setUp(): void {
$this->cloudIdManager,
$this->logger,
$this->cloudFederationFactory,
$this->cloudFederationProviderManager
$this->cloudFederationProviderManager,
$this->eventDispatcher
);
}

Expand Down

0 comments on commit b17a148

Please sign in to comment.