Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions lib/Service/ShareService.php
Original file line number Diff line number Diff line change
Expand Up @@ -604,6 +604,10 @@ public function updatePermission(int $id, array $permissions): Share {
throw new InternalError(get_class($this) . ' - ' . __FUNCTION__ . ': ' . $e->getMessage());
}

if ($item->getNodeType() === 'context') {
throw new PermissionError('PermissionError: cannot update permissions on context shares');
}

$this->assertSharePermissionUpdateAllowedWhenSharingRestricted($item, $permissions);

// security
Expand Down
7 changes: 7 additions & 0 deletions lib/Share/SharePageShareDataDecorator.php
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,13 @@ public function getPassword(): string {
return $this->share->getPassword();
}

/**
* Forward-compatibility with Nextcloud v35
*/
public function isPasswordProtected(): bool {
return $this->share->getPassword() !== '';
}

public function setToken($token): never {
throw new LogicException('Not implemented: read only object');
}
Expand Down
102 changes: 102 additions & 0 deletions tests/integration/features/bootstrap/FeatureContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -2788,6 +2788,108 @@ public function userSharesTheContextTo(string $sharer, string $contextAlias, str
}
}

/**
* @Given user :sharer shares the Context :contextAlias to :shareeType :sharee with permissions :permissions
*/
public function userSharesTheContextToWithPermissions(string $sharer, string $contextAlias, string $shareeType, string $sharee, string $permissions): void {
$this->setCurrentUser($sharer);
$context = $this->collectionManager->getByAlias('context', $contextAlias);

$permissionMap = [
'read' => 'permissionRead',
'create' => 'permissionCreate',
'update' => 'permissionUpdate',
'delete' => 'permissionDelete',
'manage' => 'permissionManage',
];

$permissionList = explode(',', $permissions);
$permissionData = [
'permissionRead' => false,
'permissionCreate' => false,
'permissionUpdate' => false,
'permissionDelete' => false,
'permissionManage' => false,
];

foreach ($permissionList as $perm) {
$perm = trim($perm);
if (isset($permissionMap[$perm])) {
$permissionData[$permissionMap[$perm]] = true;
}
}

$this->sendRequest(
'POST',
'/apps/tables/api/1/shares',
array_merge($permissionData, [
'nodeId' => $context['id'],
'nodeType' => 'context',
'receiver' => $sharee,
'receiverType' => $shareeType,
'displayMode' => 2,
])
);

if ($this->response->getStatusCode() === 200) {
$share = $this->getDataFromResponse($this->response);
$this->shareId = $share['id'];

Assert::assertEquals($share['nodeType'], 'context');
Assert::assertEquals($share['nodeId'], $context['id']);
Assert::assertEquals($share['receiverType'], $shareeType);
Assert::assertEquals($share['receiver'], $sharee);
}
}

/**
* @Then user :user has the following context permissions for :contextAlias
*/
public function userHasTheFollowingContextPermissionsFor(string $user, string $contextAlias, TableNode $table): void {
$this->setCurrentUser($user);
$context = $this->collectionManager->getByAlias('context', $contextAlias);

$this->sendOcsRequest(
'GET',
sprintf('/apps/tables/api/2/contexts/%d', $context['id'])
);

$contextData = $this->getDataFromResponse($this->response)['ocs']['data'];
Assert::assertEquals(200, $this->response->getStatusCode());

foreach ($table->getRows() as $row) {
$permissionName = $row[0];
$expectedValue = (int)$row[1];

$permissionField = match ($permissionName) {
'read' => 'permissionRead',
'create' => 'permissionCreate',
'update' => 'permissionUpdate',
'delete' => 'permissionDelete',
'manage' => 'permissionManage',
default => throw new \InvalidArgumentException("Unknown permission: $permissionName"),
};

Assert::assertEquals($expectedValue, (int)($contextData['onSharePermissions'][$permissionField] ?? 0), "Permission $permissionName mismatch");
}
}

/**
* @When user :user tries to set permission :permission to :value for context :contextAlias and user :targetUser
*/
public function userTriesToSetPermissionToForContextAndUser(string $user, string $permission, string $value, string $contextAlias, string $targetUser): void {
$this->setCurrentUser($user);

$this->sendRequest(
'PUT',
'/apps/tables/api/1/shares/' . $this->shareId,
[
'permissionType' => $permission,
'permissionValue' => (bool)$value
]
);
}

/**
* @Then user :initiator shares view :viewAlias with :recipient
*/
Expand Down
4 changes: 2 additions & 2 deletions tests/integration/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,12 @@ echo ''
echo '#'
echo '# Running tests'
echo '#'
vendor/bin/behat --colors -f junit -f pretty $SCENARIO
vendor/bin/behat --strict --colors -f junit -f pretty $SCENARIO
RESULT=$?

echo ''
echo '#'
echo '# Stopping PHP webserver and disabling spreedcheats'
echo '# Stopping PHP webserver and disabling spreadsheets'
echo '#'

if ps --pid ${PHPPID1} > /dev/null; then
Expand Down
Loading