Skip to content

Commit

Permalink
Merge pull request #43278 from nextcloud/backport/43024/stable28
Browse files Browse the repository at this point in the history
[stable28] Consider admin defaults when creating shares
  • Loading branch information
susnux authored Feb 3, 2024
2 parents 44c9651 + 9be6d0f commit 54e8c8f
Show file tree
Hide file tree
Showing 10 changed files with 47 additions and 36 deletions.
6 changes: 0 additions & 6 deletions apps/files_sharing/lib/Listener/LoadSidebarListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,5 @@ public function handle(Event $event): void {
}

Util::addScript(Application::APP_ID, 'files_sharing_tab', 'files');

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

$this->initialState->provideInitialState('shareConfig', $shareConfig);
}
}
29 changes: 18 additions & 11 deletions apps/files_sharing/src/services/ConfigService.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,23 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/

import { loadState } from '@nextcloud/initial-state'
import { getCapabilities } from '@nextcloud/capabilities'

export default class Config {

constructor() {
this._shareConfig = loadState('files_sharing', 'shareConfig', {})
this._capabilities = getCapabilities()
}

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

/**
Expand All @@ -39,7 +48,7 @@ export default class Config {
* @memberof Config
*/
get isPublicUploadEnabled() {
return this._shareConfig.allowPublicUploads
return this._capabilities.files_sharing?.public.upload
}

/**
Expand Down Expand Up @@ -214,11 +223,10 @@ export default class Config {
* @memberof Config
*/
get isMailShareAllowed() {
const capabilities = getCapabilities()
// eslint-disable-next-line camelcase
return capabilities?.files_sharing?.sharebymail !== undefined
return this._capabilities?.files_sharing?.sharebymail !== undefined
// eslint-disable-next-line camelcase
&& capabilities?.files_sharing?.public?.enabled === true
&& this._capabilities?.files_sharing?.public?.enabled === true
}

/**
Expand Down Expand Up @@ -273,7 +281,7 @@ export default class Config {
* @memberof Config
*/
get isPasswordForMailSharesRequired() {
return (getCapabilities().files_sharing.sharebymail === undefined) ? false : getCapabilities().files_sharing.sharebymail.password.enforced
return (this._capabilities.files_sharing.sharebymail === undefined) ? false : this._capabilities.files_sharing.sharebymail.password.enforced
}

/**
Expand All @@ -282,7 +290,7 @@ export default class Config {
* @memberof Config
*/
get shouldAlwaysShowUnique() {
return (getCapabilities().files_sharing?.sharee?.always_show_unique === true)
return (this._capabilities.files_sharing?.sharee?.always_show_unique === true)
}

/**
Expand Down Expand Up @@ -327,8 +335,7 @@ export default class Config {
* @memberof Config
*/
get passwordPolicy() {
const capabilities = getCapabilities()
return capabilities.password_policy ? capabilities.password_policy : {}
return this._capabilities.password_policy ? this._capabilities.password_policy : {}
}

}
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
3 changes: 0 additions & 3 deletions dist/3425-3425.js

This file was deleted.

1 change: 0 additions & 1 deletion dist/3425-3425.js.map

This file was deleted.

3 changes: 3 additions & 0 deletions dist/6411-6411.js

Large diffs are not rendered by default.

File renamed without changes.
1 change: 1 addition & 0 deletions dist/6411-6411.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/files_sharing-files_sharing_tab.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/files_sharing-files_sharing_tab.js.map

Large diffs are not rendered by default.

0 comments on commit 54e8c8f

Please sign in to comment.