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 30, 2024
1 parent e224432 commit db03ac1
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 12 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
34 changes: 22 additions & 12 deletions apps/files_sharing/src/views/SharingDetailsTab.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@
</span>
</div>
<div class="sharingTabDetailsView__wrapper">
<div ref="quickPermissions"
class="sharingTabDetailsView__quick-permissions">
<div ref="quickPermissions" class="sharingTabDetailsView__quick-permissions">
<div>
<NcCheckboxRadioSwitch :button-variant="true"
:checked.sync="sharingPermission"
Expand Down Expand Up @@ -743,7 +742,7 @@ export default {
}
},
initializePermissions() {
handleShareType() {
if (this.share.share_type) {
this.share.type = this.share.share_type
}
Expand All @@ -752,23 +751,34 @@ export default {
if ('shareType' in this.share) {
this.share.type = this.share.shareType
}
},
handleDefaultPermissions() {
if (this.isNewShare) {
if (this.isPublicShare) {
this.sharingPermission = BUNDLED_PERMISSIONS.READ_ONLY.toString()
const defaultPermissions = this.config.defaultPermissions
if (defaultPermissions === BUNDLED_PERMISSIONS.READ_ONLY || defaultPermissions === BUNDLED_PERMISSIONS.ALL) {
this.sharingPermission = defaultPermissions.toString()
} else {
this.sharingPermission = BUNDLED_PERMISSIONS.ALL.toString()
}
} else {
if (this.hasCustomPermissions || this.share.setCustomPermissions) {
this.sharingPermission = 'custom'
this.share.permissions = defaultPermissions
this.advancedSectionAccordionExpanded = true
this.setCustomPermissions = true
} else {
this.sharingPermission = this.share.permissions.toString()
}
}
},
handleCustomPermissions() {
if (!this.isNewShare && (this.hasCustomPermissions || this.share.setCustomPermissions)) {
this.sharingPermission = 'custom'
this.advancedSectionAccordionExpanded = true
this.setCustomPermissions = true
} else {
this.sharingPermission = this.share.permissions.toString()
}
},
initializePermissions() {
this.handleShareType()
this.handleDefaultPermissions()
this.handleCustomPermissions()
},
async saveShare() {
const permissionsAndAttributes = ['permissions', 'attributes', 'note', 'expireDate']
const publicShareAttributes = ['label', 'password', 'hideDownload']
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 db03ac1

Please sign in to comment.