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 <fenn25.fn@gmail.com>
  • Loading branch information
nfebe committed Feb 3, 2024
1 parent b410c0f commit 62c92ad
Show file tree
Hide file tree
Showing 3 changed files with 34 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 @@ -54,6 +54,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 @@ -30,6 +30,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 @@ -718,7 +717,7 @@ export default {
}
},
initializePermissions() {
handleShareType() {
if (this.share.share_type) {
this.share.type = this.share.share_type
}
Expand All @@ -727,23 +726,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

0 comments on commit 62c92ad

Please sign in to comment.