aboutsummaryrefslogtreecommitdiffstats
path: root/apps/dav/lib/DAV/Sharing/SharingService.php
diff options
context:
space:
mode:
Diffstat (limited to 'apps/dav/lib/DAV/Sharing/SharingService.php')
-rw-r--r--apps/dav/lib/DAV/Sharing/SharingService.php53
1 files changed, 53 insertions, 0 deletions
diff --git a/apps/dav/lib/DAV/Sharing/SharingService.php b/apps/dav/lib/DAV/Sharing/SharingService.php
new file mode 100644
index 00000000000..11459e12d74
--- /dev/null
+++ b/apps/dav/lib/DAV/Sharing/SharingService.php
@@ -0,0 +1,53 @@
+<?php
+
+declare(strict_types=1);
+/**
+ * SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ */
+namespace OCA\DAV\DAV\Sharing;
+
+abstract class SharingService {
+ protected string $resourceType = '';
+ public function __construct(
+ protected SharingMapper $mapper,
+ ) {
+ }
+
+ public function getResourceType(): string {
+ return $this->resourceType;
+ }
+ public function shareWith(int $resourceId, string $principal, int $access): void {
+ // remove the share if it already exists
+ $this->mapper->deleteShare($resourceId, $this->getResourceType(), $principal);
+ $this->mapper->share($resourceId, $this->getResourceType(), $access, $principal);
+ }
+
+ public function unshare(int $resourceId, string $principal): void {
+ $this->mapper->unshare($resourceId, $this->getResourceType(), $principal);
+ }
+
+ public function deleteShare(int $resourceId, string $principal): void {
+ $this->mapper->deleteShare($resourceId, $this->getResourceType(), $principal);
+ }
+
+ public function deleteAllShares(int $resourceId): void {
+ $this->mapper->deleteAllShares($resourceId, $this->getResourceType());
+ }
+
+ public function deleteAllSharesByUser(string $principaluri): void {
+ $this->mapper->deleteAllSharesByUser($principaluri, $this->getResourceType());
+ }
+
+ public function getShares(int $resourceId): array {
+ return $this->mapper->getSharesForId($resourceId, $this->getResourceType());
+ }
+
+ public function getUnshares(int $resourceId): array {
+ return $this->mapper->getUnsharesForId($resourceId, $this->getResourceType());
+ }
+
+ public function getSharesForIds(array $resourceIds): array {
+ return $this->mapper->getSharesForIds($resourceIds, $this->getResourceType());
+ }
+}