X Tutup
Skip to content
Merged
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
22 changes: 17 additions & 5 deletions apps/files_sharing/lib/Controller/Share20OcsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -393,10 +393,12 @@ public function createShare() {
}

$shareType = (int)$this->request->getParam('shareType', '-1');
$noPermissionFromRequest = false;

// Parse permissions (if available)
$permissions = $this->getPermissionsFromRequest();
if ($permissions === null) {
$noPermissionFromRequest = true;
if ($shareType !== Share::SHARE_TYPE_LINK) {
$permissions = $this->config->getAppValue('core', 'shareapi_default_permissions', Constants::PERMISSION_ALL);
} else {
Expand Down Expand Up @@ -486,12 +488,14 @@ public function createShare() {
return new Result(null, 403, $this->l->t('Public link creation is only possible for certain groups'));
}

$publicUploadAllowed = $this->shareManager->shareApiLinkAllowPublicUpload();

// legacy way, expecting that this won't be used together with "create-only" shares
$publicUpload = $this->request->getParam('publicUpload', null);
// a few permission checks
if ($publicUpload === 'true' || $permissions === Constants::PERMISSION_CREATE) {
// Check if public upload is allowed
if (!$this->shareManager->shareApiLinkAllowPublicUpload()) {
if (!$publicUploadAllowed) {
$share->getNode()->unlock(ILockingProvider::LOCK_SHARED);
return new Result(null, 403, $this->l->t('Public upload disabled by the administrator'));
}
Expand All @@ -503,6 +507,15 @@ public function createShare() {
}
}

// don't allow "create"-permission if public upload is not allowed.
// we only need this check if permissions were passed via the request, otherwise
// it is already being handled.
$includesCreatePermission = $permissions & Constants::PERMISSION_CREATE;
if (!$noPermissionFromRequest && !$publicUploadAllowed && $includesCreatePermission) {
$share->getNode()->unlock(ILockingProvider::LOCK_SHARED);
return new Result(null, 403, $this->l->t('Public upload disabled by the administrator'));
}

// convert to permissions
if ($publicUpload === 'true') {
$share->setPermissions(
Expand Down Expand Up @@ -886,10 +899,9 @@ public function updateShare($id) {
}
}

// create-only (upload-only)
if (
$newPermissions === Constants::PERMISSION_CREATE
) {
// create (upload)
$includesCreatePermission = $newPermissions & Constants::PERMISSION_CREATE;
if ($includesCreatePermission) {
if (!$this->shareManager->shareApiLinkAllowPublicUpload()) {
$share->getNode()->unlock(ILockingProvider::LOCK_SHARED);
return new Result(null, 403, $this->l->t('Public upload disabled by the administrator'));
Expand Down
10 changes: 10 additions & 0 deletions changelog/unreleased/39194
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Enhancement: Unify API responses when setting permissions for public links

Setting (and changing) the permissions of public links via the OCS API
will now return proper and unified API responses. Adding create
permissions while public uploading is disabled globally will always
return a 403 response.

https://github.com/owncloud/core/pull/39194
https://github.com/owncloud/core/issues/36442
https://github.com/owncloud/core/issues/36443
Original file line number Diff line number Diff line change
Expand Up @@ -291,64 +291,40 @@ Feature: create a public link share
| 1 | 100 | new |
| 2 | 200 | new |

@issue-36442 @skipOnOcV10
Scenario Outline: Creating a public link share with read+create permissions defaults to read permissions when public upload disabled globally

Scenario Outline: Creating a public link share with read+create permissions is forbidden when public upload is disabled globally
Given using OCS API version "<ocs_api_version>"
And parameter "shareapi_allow_public_upload" of app "core" has been set to "no"
And user "Alice" has created folder "/afolder"
When user "Alice" creates a public link share using the sharing API with settings
| path | /afolder |
| permissions | read,create |
Then the fields of the last response to user "Alice" should include
| id | A_STRING |
| share_type | public_link |
| permissions | read |
And the OCS status code should be "<ocs_status_code>"
And the HTTP status code should be "200"
And the public upload to the last publicly shared folder using the <webdav_api_version> public WebDAV API should fail with HTTP status code "403"
Then the OCS status code should be "<ocs_status_code>"

@notToImplementOnOCIS @issue-ocis-2079 @issue-36442 @skipOnOcV10
@notToImplementOnOCIS @issue-ocis-2079
Examples:
| ocs_api_version | ocs_status_code | webdav_api_version |
| 1 | 100 | old |
| 2 | 200 | old |
| ocs_api_version | ocs_status_code |
| 1 | 403 |
| 2 | 403 |

@issue-36442 @skipOnOcV10
Examples:
| ocs_api_version | ocs_status_code | webdav_api_version |
| 1 | 100 | new |
| 2 | 200 | new |

@issue-36442 @skipOnOcV10
Scenario Outline: Creating a public link share with create permissions defaults to read permissions when public upload is disabled globally and accessing using the public WebDAV api
Scenario Outline: Creating a public link share with create permissions is forbidden when public upload is disabled globally
Given using OCS API version "<ocs_api_version>"
And parameter "shareapi_allow_public_upload" of app "core" has been set to "no"
And user "Alice" has created folder "/afolder"
When user "Alice" creates a public link share using the sharing API with settings
| path | /afolder |
| permissions | create |
Then the fields of the last response to user "Alice" should include
| id | A_STRING |
| share_type | public_link |
| permissions | read |
And the OCS status code should be "<ocs_status_code>"
And the HTTP status code should be "200"
And the public upload to the last publicly shared folder using the <webdav_api_version> public WebDAV API should fail with HTTP status code "403"
Then the OCS status code should be "<ocs_status_code>"

@notToImplementOnOCIS @issue-ocis-2079
@notToImplementOnOCIS @issue-ocis-2079 @issue-ocis-reva-41
Examples:
| ocs_api_version | ocs_status_code | webdav_api_version |
| 1 | 100 | old |
| 2 | 200 | old |
| ocs_api_version | ocs_status_code |
| 1 | 403 |
| 2 | 403 |

@issue-ocis-reva-41
Examples:
| ocs_api_version | ocs_status_code | webdav_api_version |
| 1 | 100 | new |
| 2 | 200 | new |

@issue-36442 @skipOnOcV10
Scenario Outline: Updating a public link share with read+create permissions defaults to read permissions when public upload is disabled globally and accessing using the public WebDAV API
Scenario Outline: Updating a public link share with read+create permissions is forbidden when public upload is disabled globally
Given using OCS API version "<ocs_api_version>"
And user "Alice" has created folder "/afolder"
And user "Alice" has created a public link share with settings
Expand All @@ -357,91 +333,31 @@ Feature: create a public link share
And parameter "shareapi_allow_public_upload" of app "core" has been set to "no"
When user "Alice" tries to update the last share using the sharing API with
| permissions | read,create |
Then the fields of the last response to user "Alice" should include
| id | A_STRING |
| share_type | public_link |
| permissions | read |
And the OCS status code should be "<ocs_status_code>"
And the HTTP status code should be "200"
And the public upload to the last publicly shared folder using the <webdav_api_version> public WebDAV API should fail with HTTP status code "403"

@notToImplementOnOCIS @issue-ocis-2079
Examples:
| ocs_api_version | ocs_status_code | webdav_api_version |
| 1 | 100 | old |
| 2 | 200 | old |

@issue-ocis-reva-41
Examples:
| ocs_api_version | ocs_status_code | webdav_api_version |
| 1 | 100 | new |
| 2 | 200 | new |

@issue-36442 @skipOnOcV10
Scenario Outline: Creating a public link share with read+create permissions defaults to read permissions when public upload is disabled globally and accessing using the public WebDAV API
Given using OCS API version "<ocs_api_version>"
And user "Alice" has created folder "/afolder"
And user "Alice" has created a public link share with settings
| path | /afolder |
| permissions | read |
And parameter "shareapi_allow_public_upload" of app "core" has been set to "no"
When user "Alice" tries to update the last share using the sharing API with
| permissions | <permission> |
Then the fields of the last response to user "Alice" should include
| id | A_STRING |
| share_type | public_link |
| permissions | read |
And the OCS status code should be "<ocs_status_code>"
And the HTTP status code should be "<http_status_code>"
And the public upload to the last publicly shared folder using the <webdav_api_version> public WebDAV API should fail with HTTP status code "403"
Then the OCS status code should be "<ocs_status_code>"

@notToImplementOnOCIS @issue-ocis-2079
@notToImplementOnOCIS @issue-ocis-2079 @issue-ocis-reva-41
Examples:
| ocs_api_version | ocs_status_code | http_status_code | permission | webdav_api_version |
| 1 | 100 | 200 | create | old |
| 2 | 200 | 200 | create | old |
| 1 | 100 | 200 | create,read,update | old |
| 2 | 200 | 200 | create,read,update | old |
| 1 | 100 | 200 | read,create,update,delete | old |
| 2 | 200 | 200 | read,create,update,delete | old |

| ocs_api_version | ocs_status_code |
| 1 | 403 |
| 2 | 403 |

Examples:
| ocs_api_version | ocs_status_code | http_status_code | permission | webdav_api_version |
| 1 | 100 | 200 | create | new |
| 2 | 200 | 200 | create | new |
| 1 | 100 | 200 | create,read,update | new |
| 2 | 200 | 200 | create,read,update | new |
| 1 | 100 | 200 | read,create,update,delete | new |
| 2 | 200 | 200 | read,create,update,delete | new |

@issue-ocis-reva-41
Scenario Outline: Creating a link share with read+update+create permissions defaults to read permissions when public upload is disabled globally and accessing using the public webDAV API
Scenario Outline: Creating a link share with read+update+create permissions is forbidden when public upload is disabled globally
Given using OCS API version "<ocs_api_version>"
And parameter "shareapi_allow_public_upload" of app "core" has been set to "no"
And user "Alice" has created folder "/afolder"
When user "Alice" creates a public link share using the sharing API with settings
| path | /afolder |
| permissions | read,update,create |
Then the OCS status code should be "<ocs_status_code>"
And the HTTP status code should be "200"
And the fields of the last response to user "Alice" should include
| id | A_STRING |
| share_type | public_link |
| permissions | read |
And the public upload to the last publicly shared folder using the <webdav_api_version> public WebDAV API should fail with HTTP status code "403"

@notToImplementOnOCIS @issue-ocis-2079
Examples:
| ocs_api_version | ocs_status_code | webdav_api_version |
| 1 | 100 | old |
| 2 | 200 | old |

| ocs_api_version | ocs_status_code |
| 1 | 403 |
| 2 | 403 |

Examples:
| ocs_api_version | ocs_status_code | webdav_api_version |
| 1 | 100 | new |
| 2 | 200 | new |

@issue-ocis-reva-41
Scenario Outline: Creating a link share with update permissions defaults to read permissions when public upload disabled globally
Expand Down
Loading
X Tutup