Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
Hide upload button with zero quota
Whenever a user has zero quota, for example like guest app users, don't
display the upload button.

The quota value is retrieved for the attachment folder.

Signed-off-by: Vincent Petry <[email protected]>
  • Loading branch information
PVince81 committed Jan 28, 2021
commit b8fd42777240075f6452fc13f8a384c5b94ca679
26 changes: 21 additions & 5 deletions lib/TInitialState.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,17 +98,23 @@ protected function publishInitialStateForUser(IUser $user, IRootFolder $rootFold
);

$attachmentFolder = $this->talkConfig->getAttachmentFolder($user->getUID());
$freeSpace = 0;

if ($attachmentFolder) {
try {
$userFolder = $rootFolder->getUserFolder($user->getUID());

if (!$userFolder->nodeExists($attachmentFolder)) {
$userFolder->newFolder($attachmentFolder);
try {
if (!$userFolder->nodeExists($attachmentFolder)) {
$userFolder->newFolder($attachmentFolder);
}

$freeSpace = $userFolder->get($attachmentFolder)->getFreeSpace();
} catch (NotPermittedException $e) {
$attachmentFolder = '/';
$this->serverConfig->setUserValue($user->getUID(), 'spreed', 'attachment_folder', '/');
$freeSpace = $userFolder->getFreeSpace();
}
} catch (NotPermittedException $e) {
$attachmentFolder = '/';
$this->serverConfig->setUserValue($user->getUID(), 'spreed', 'attachment_folder', '/');
} catch (NoUserException $e) {
}
}
Expand All @@ -118,6 +124,11 @@ protected function publishInitialStateForUser(IUser $user, IRootFolder $rootFold
$attachmentFolder
);

$this->initialState->provideInitialState(
'attachment_folder_free_space',
$freeSpace
);

$this->initialState->provideInitialState(
'enable_matterbridge',
$this->serverConfig->getAppValue('spreed', 'enable_matterbridge', '0') === '1'
Expand Down Expand Up @@ -147,6 +158,11 @@ protected function publishInitialStateForGuest(): void {
''
);

$this->initialState->provideInitialState(
'attachment_folder_free_space',
''
);

$this->initialState->provideInitialState(
'enable_matterbridge',
false
Expand Down
18 changes: 12 additions & 6 deletions src/components/NewMessageForm/NewMessageForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,14 @@
:aria-label="t('spreed', 'Share files to the conversation')"
:aria-haspopup="true">
<ActionButton
v-if="canShareAndUploadFiles"
v-if="canUploadFiles"
:close-after-click="true"
icon="icon-upload"
@click.prevent="clickImportInput">
{{ t('spreed', 'Upload new files') }}
</ActionButton>
<ActionButton
v-if="canShareAndUploadFiles"
v-if="canShareFiles"
:close-after-click="true"
icon="icon-folder"
@click.prevent="handleFileShare">
Expand Down Expand Up @@ -195,13 +195,19 @@ export default {
return this.$store.getters.getUserId() === null
},

canShareAndUploadFiles() {
canShareFiles() {
return !this.currentUserIsGuest && !this.isReadOnly
},

canUploadFiles() {
const allowed = getCapabilities()?.spreed?.config?.attachments?.allowed
return allowed && !this.currentUserIsGuest && !this.isReadOnly
return allowed
&& this.attachmentFolderFreeSpace !== 0
&& this.canShareFiles
},

attachmentFolder() {
return this.$store.getters.getAttachmentFolder()
attachmentFolderFreeSpace() {
return this.$store.getters.getAttachmentFolderFreeSpace()
},
},

Expand Down
6 changes: 6 additions & 0 deletions src/store/fileUploadStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import { shareFile } from '../services/filesSharingServices'

const state = {
attachmentFolder: loadState('spreed', 'attachment_folder'),
attachmentFolderFreeSpace: loadState('spreed', 'attachment_folder_free_space'),
uploads: {
},
currentUploadId: undefined,
Expand Down Expand Up @@ -76,6 +77,11 @@ const getters = {
return state.attachmentFolder
},

// gets the current attachment folder
getAttachmentFolderFreeSpace: (state) => () => {
return state.attachmentFolderFreeSpace
},

uploadProgress: (state) => (uploadId, index) => {
if (state.uploads[uploadId].files[index]) {
return state.uploads[uploadId].files[index].uploadedSize / state.uploads[uploadId].files[index].totalSize * 100
Expand Down