Skip to content

Commit

Permalink
Consider admin defaults when creating shares
Browse files Browse the repository at this point in the history
The current share logic always uses the default `BUNDLED_PERMISSIONS.ALL`
which includes everything.

This commit updates share creation logic to use `defaultPermissions` if set
by admin for the creation of new shares.

Signed-off-by: fenn-cs <[email protected]>
  • Loading branch information
nfebe committed Jan 22, 2024
1 parent 93db067 commit e8ff76f
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 0 deletions.
1 change: 1 addition & 0 deletions apps/files_sharing/lib/Listener/LoadSidebarListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public function handle(Event $event): void {

$shareConfig = [
'allowPublicUploads' => $this->shareManager->shareApiLinkAllowPublicUpload(),
'defaultPermissions' => $this->shareManager->shareApiDefaultPermissions(),
];

$this->initialState->provideInitialState('shareConfig', $shareConfig);
Expand Down
11 changes: 11 additions & 0 deletions apps/files_sharing/src/services/ConfigService.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,17 @@ export default class Config {
this._shareConfig = loadState('files_sharing', 'shareConfig', {})
}

/**
* Get default share permissions, if any
*
* @return {boolean}
* @readonly
* @memberof Config
*/
get defaultPermissions() {
return this._shareConfig.defaultPermissions
}

/**
* Is public upload allowed on link shares ?
*
Expand Down
6 changes: 6 additions & 0 deletions apps/files_sharing/src/views/SharingDetailsTab.vue
Original file line number Diff line number Diff line change
Expand Up @@ -754,9 +754,15 @@ export default {
}
if (this.isNewShare) {
if (this.isPublicShare) {
// The default sharing permission for public shares should probably
// come from the backend via the `this.config`.
this.sharingPermission = BUNDLED_PERMISSIONS.READ_ONLY.toString()
} else {
this.sharingPermission = BUNDLED_PERMISSIONS.ALL.toString()
// TEMP COMMENT FOR REVIEW : So apparently, switching to the default permissions
// as below is what is required, however, the default permissions does not neccesarily
// mean "Allow editing"...
// this.sharingPermission = this.config.defaultPermissions
}
} else {
Expand Down
10 changes: 10 additions & 0 deletions lib/private/Share20/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
use OCA\Files_Sharing\AppInfo\Application;
use OCA\Files_Sharing\ISharedStorage;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\Constants;
use OCP\Files\File;
use OCP\Files\Folder;
use OCP\Files\IRootFolder;
Expand Down Expand Up @@ -1791,6 +1792,15 @@ public function shareApiEnabled() {
return $this->config->getAppValue('core', 'shareapi_enabled', 'yes') === 'yes';
}

/**
* Return default share permissions if set
*
* @return int
*/
public function shareApidefaultPermissions(): int {
return (int)$this->config->getAppValue('core', 'shareapi_default_permissions', (string)Constants::PERMISSION_ALL);
}

/**
* Is public link sharing enabled
*
Expand Down
8 changes: 8 additions & 0 deletions lib/public/Share/IManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,14 @@ public function newShare();
*/
public function shareApiEnabled();

/**
* Get default share permissions set by admin
*
* @return int
* @since 27.0.0
*/
public function shareApidefaultPermissions(): int;

/**
* Is public link sharing enabled
*
Expand Down

0 comments on commit e8ff76f

Please sign in to comment.