Skip to content

Commit

Permalink
Use @nextcloud/capabilities to obtain share api defaults
Browse files Browse the repository at this point in the history
- Remove redundant initial state added

- Call `getCapabilities()` in share config file.

Signed-off-by: fenn-cs <fenn25.fn@gmail.com>
  • Loading branch information
Fenn-CS authored and JuliaKirschenheuter committed Feb 5, 2024
1 parent ce7261e commit 253785f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 19 deletions.
7 changes: 0 additions & 7 deletions apps/files_sharing/lib/Listener/LoadSidebarListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,5 @@ public function handle(Event $event): void {
}

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

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

$this->initialState->provideInitialState('shareConfig', $shareConfig);
}
}
20 changes: 8 additions & 12 deletions apps/files_sharing/src/services/ConfigService.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,12 @@
* 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()
}

/**
Expand All @@ -39,7 +37,7 @@ export default class Config {
* @memberof Config
*/
get defaultPermissions() {
return this._shareConfig.defaultPermissions
return this._capabilities.files_sharing?.default_permissions
}

/**
Expand All @@ -50,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 @@ -225,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 @@ -284,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 @@ -293,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 @@ -338,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 : {}
}

}

0 comments on commit 253785f

Please sign in to comment.