Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[stable27] Consider admin defaults when creating shares #43279

Merged
merged 3 commits into from
Feb 4, 2024
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
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 @@ -51,11 +51,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);
}
}
30 changes: 19 additions & 11 deletions apps/files_sharing/src/services/ConfigService.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +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 @@ -38,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 @@ -213,11 +223,10 @@ export default class Config {
* @memberof Config
*/
get isMailShareAllowed() {
const capabilities = OC.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 @@ -272,7 +281,7 @@ export default class Config {
* @memberof Config
*/
get isPasswordForMailSharesRequired() {
return (OC.getCapabilities().files_sharing.sharebymail === undefined) ? false : OC.getCapabilities().files_sharing.sharebymail.password.enforced
return (this._capabilities.files_sharing.sharebymail === undefined) ? false : this._capabilities.files_sharing.sharebymail.password.enforced
}

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

/**
Expand Down Expand Up @@ -326,8 +335,7 @@ export default class Config {
* @memberof Config
*/
get passwordPolicy() {
const capabilities = OC.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 @@ -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
4 changes: 2 additions & 2 deletions dist/core-common.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/core-common.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.

Loading