Skip to content

Commit 001263f

Browse files
juliusknorrbackportbot[bot]
authored andcommitted
fix: Handle share attributes in the share provider
Signed-off-by: Julius Knorr <jus@bitgrid.net>
1 parent 1873e38 commit 001263f

1 file changed

Lines changed: 53 additions & 1 deletion

File tree

lib/Sharing/DeckShareProvider.php

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
use OCP\IL10N;
3333
use OCP\Share\Exceptions\GenericShareException;
3434
use OCP\Share\Exceptions\ShareNotFound;
35+
use OCP\Share\IAttributes;
3536
use OCP\Share\IManager;
3637
use OCP\Share\IShare;
3738

@@ -113,6 +114,11 @@ public function create(IShare $share) {
113114
)
114115
);*/
115116

117+
// set share attributes
118+
$shareAttributes = $this->formatShareAttributes(
119+
$share->getAttributes()
120+
);
121+
116122
$shareId = $this->addShareToDB(
117123
$share->getSharedWith(),
118124
$share->getSharedBy(),
@@ -122,7 +128,8 @@ public function create(IShare $share) {
122128
$share->getTarget(),
123129
$share->getPermissions(),
124130
$share->getToken() ?? '',
125-
$share->getExpirationDate()
131+
$share->getExpirationDate(),
132+
$shareAttributes
126133
);
127134
$data = $this->getRawShare($shareId);
128135

@@ -143,6 +150,7 @@ public function create(IShare $share) {
143150
* @param int $permissions
144151
* @param string $token
145152
* @param \DateTime|null $expirationDate
153+
* @param string|null $attributes
146154
* @return int
147155
*/
148156
private function addShareToDB(
@@ -155,6 +163,7 @@ private function addShareToDB(
155163
int $permissions,
156164
string $token,
157165
?\DateTime $expirationDate,
166+
?string $attributes = null,
158167
): int {
159168
$qb = $this->dbConnection->getQueryBuilder();
160169
$qb->insert('share')
@@ -174,6 +183,10 @@ private function addShareToDB(
174183
$qb->setValue('expiration', $qb->createNamedParameter($expirationDate, 'datetime'));
175184
}
176185

186+
if ($attributes !== null) {
187+
$qb->setValue('attributes', $qb->createNamedParameter($attributes));
188+
}
189+
177190
$qb->executeStatement();
178191

179192
return $qb->getLastInsertId();
@@ -244,6 +257,9 @@ private function createShareObject(array $data): IShare {
244257
$entryData['parent'] = $entryData['f_parent'];
245258
$share->setNodeCacheEntry(Cache::cacheEntryFromData($entryData, $this->mimeTypeLoader));
246259
}
260+
261+
$share = $this->updateShareAttributes($share, $data['attributes'] ?? null);
262+
247263
return $share;
248264
}
249265

@@ -1026,6 +1042,42 @@ public function getAllShares(): iterable {
10261042
$cursor->closeCursor();
10271043
}
10281044

1045+
protected function updateShareAttributes(IShare $share, ?string $data): IShare {
1046+
if ($data !== null && $data !== '') {
1047+
$attributes = $share->getAttributes() ?? $share->newAttributes();
1048+
$compressedAttributes = \json_decode($data, true);
1049+
if ($compressedAttributes === false || $compressedAttributes === null) {
1050+
return $share;
1051+
}
1052+
foreach ($compressedAttributes as $compressedAttribute) {
1053+
$attributes->setAttribute(
1054+
$compressedAttribute[0],
1055+
$compressedAttribute[1],
1056+
$compressedAttribute[2]
1057+
);
1058+
}
1059+
$share->setAttributes($attributes);
1060+
}
1061+
1062+
return $share;
1063+
}
1064+
1065+
protected function formatShareAttributes(?IAttributes $attributes): ?string {
1066+
if ($attributes === null || empty($attributes->toArray())) {
1067+
return null;
1068+
}
1069+
1070+
$compressedAttributes = [];
1071+
foreach ($attributes->toArray() as $attribute) {
1072+
$compressedAttributes[] = [
1073+
0 => $attribute['scope'],
1074+
1 => $attribute['key'],
1075+
2 => $attribute['value']
1076+
];
1077+
}
1078+
return \json_encode($compressedAttributes) ?: null;
1079+
}
1080+
10291081
public function getOrphanedAttachmentShares(): array {
10301082
$allCardIds = $this->cardMapper->getAllCardIds();
10311083

0 commit comments

Comments
 (0)