Add back initial state and check for filesize and canCreate permissions
Signed-off-by: Julius Härtl <jus@bitgrid.net>
This commit is contained in:
@@ -23,7 +23,9 @@
|
||||
|
||||
namespace OCA\Deck\Controller;
|
||||
|
||||
use OCA\Deck\AppInfo\Application;
|
||||
use OCA\Deck\Service\PermissionService;
|
||||
use OCP\IInitialStateService;
|
||||
use OCP\IRequest;
|
||||
use OCP\AppFramework\Http\TemplateResponse;
|
||||
use OCP\AppFramework\Controller;
|
||||
@@ -34,11 +36,13 @@ class PageController extends Controller {
|
||||
private $permissionService;
|
||||
private $userId;
|
||||
private $l10n;
|
||||
private $initialState;
|
||||
|
||||
public function __construct(
|
||||
$AppName,
|
||||
IRequest $request,
|
||||
PermissionService $permissionService,
|
||||
IInitialStateService $initialStateService,
|
||||
IL10N $l10n,
|
||||
$userId
|
||||
) {
|
||||
@@ -46,6 +50,7 @@ class PageController extends Controller {
|
||||
|
||||
$this->userId = $userId;
|
||||
$this->permissionService = $permissionService;
|
||||
$this->initialState = $initialStateService;
|
||||
$this->l10n = $l10n;
|
||||
}
|
||||
|
||||
@@ -57,13 +62,10 @@ class PageController extends Controller {
|
||||
* @NoCSRFRequired
|
||||
*/
|
||||
public function index() {
|
||||
$params = [
|
||||
'user' => $this->userId,
|
||||
'maxUploadSize' => (int)\OCP\Util::uploadLimit(),
|
||||
'canCreate' => $this->permissionService->canCreate()
|
||||
];
|
||||
$this->initialState->provideInitialState(Application::APP_ID, 'maxUploadSize', (int)\OCP\Util::uploadLimit());
|
||||
$this->initialState->provideInitialState(Application::APP_ID, 'canCreate', $this->permissionService->canCreate());
|
||||
|
||||
return new TemplateResponse('deck', 'main', $params);
|
||||
return new TemplateResponse('deck', 'main');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
15
package-lock.json
generated
15
package-lock.json
generated
@@ -3500,6 +3500,21 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"@nextcloud/initial-state": {
|
||||
"version": "1.1.0",
|
||||
"resolved": "https://registry.npmjs.org/@nextcloud/initial-state/-/initial-state-1.1.0.tgz",
|
||||
"integrity": "sha512-c8VNSv7CbcPdaMNQO3ERJUMhsGyCvAgSBlvBHhugYHxGqlySjE+J+SqkpXmqB+eQ/DujDTahBX1IwoF3zjPtOw==",
|
||||
"requires": {
|
||||
"core-js": "3.6.1"
|
||||
},
|
||||
"dependencies": {
|
||||
"core-js": {
|
||||
"version": "3.6.1",
|
||||
"resolved": "https://registry.npmjs.org/core-js/-/core-js-3.6.1.tgz",
|
||||
"integrity": "sha512-186WjSik2iTGfDjfdCZAxv2ormxtKgemjC3SI6PL31qOA0j5LhTDVjHChccoc7brwLvpvLPiMyRlcO88C4l1QQ=="
|
||||
}
|
||||
}
|
||||
},
|
||||
"@nextcloud/l10n": {
|
||||
"version": "1.1.0",
|
||||
"resolved": "https://registry.npmjs.org/@nextcloud/l10n/-/l10n-1.1.0.tgz",
|
||||
|
||||
@@ -31,9 +31,10 @@
|
||||
"@juliushaertl/vue-richtext": "^0.3.0",
|
||||
"@nextcloud/auth": "^1.2.1",
|
||||
"@nextcloud/axios": "^1.3.1",
|
||||
"@nextcloud/l10n": "^1.1.0",
|
||||
"@nextcloud/dialogs": "^1.2.1",
|
||||
"@nextcloud/files": "^1.0.0",
|
||||
"@nextcloud/initial-state": "^1.1.0",
|
||||
"@nextcloud/l10n": "^1.1.0",
|
||||
"@nextcloud/moment": "^1.1.0",
|
||||
"@nextcloud/router": "^1.0.0",
|
||||
"@nextcloud/vue": "^1.4.0",
|
||||
|
||||
@@ -84,6 +84,9 @@ import { Actions, ActionButton, Modal } from '@nextcloud/vue'
|
||||
import { showError } from '@nextcloud/dialogs'
|
||||
import { formatFileSize } from '@nextcloud/files'
|
||||
import relativeDate from '../../mixins/relativeDate'
|
||||
import { loadState } from '@nextcloud/initial-state'
|
||||
|
||||
const maxUploadSizeState = loadState('deck', 'maxUploadSize')
|
||||
|
||||
export default {
|
||||
name: 'CardSidebarTabAttachments',
|
||||
@@ -104,6 +107,7 @@ export default {
|
||||
modalShow: false,
|
||||
file: '',
|
||||
overwriteAttachment: null,
|
||||
maxUploadSize: maxUploadSizeState,
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
@@ -140,11 +144,21 @@ export default {
|
||||
this.$refs.localAttachments.click()
|
||||
},
|
||||
async onLocalAttachmentSelected(event) {
|
||||
const file = event.target.files[0]
|
||||
if (this.maxUploadSize > 0 && this.file.size > this.maxUploadSize) {
|
||||
showError(
|
||||
t('deck', `Failed to upload {name}`, { name: this.file.name }) + ' - '
|
||||
+ t('deck', 'Maximum file size of {size} exceeded', { size: formatFileSize(this.maxUploadSize) })
|
||||
)
|
||||
event.target.value = ''
|
||||
return
|
||||
}
|
||||
|
||||
const bodyFormData = new FormData()
|
||||
bodyFormData.append('cardId', this.card.id)
|
||||
bodyFormData.append('type', 'deck_file')
|
||||
bodyFormData.append('file', event.target.files[0])
|
||||
this.file = event.target.files[0]
|
||||
bodyFormData.append('file', file)
|
||||
|
||||
try {
|
||||
await this.$store.dispatch('createAttachment', { cardId: this.card.id, formData: bodyFormData })
|
||||
} catch (err) {
|
||||
|
||||
@@ -39,7 +39,7 @@
|
||||
:text="t('deck', 'Shared boards')"
|
||||
:boards="sharedBoards"
|
||||
icon="icon-shared" />
|
||||
<AppNavigationAddBoard />
|
||||
<AppNavigationAddBoard v-if="canCreate" />
|
||||
</ul>
|
||||
<div v-if="isAdmin"
|
||||
id="app-settings"
|
||||
@@ -73,6 +73,9 @@ import { Multiselect } from '@nextcloud/vue'
|
||||
|
||||
import AppNavigationAddBoard from './AppNavigationAddBoard'
|
||||
import AppNavigationBoardCategory from './AppNavigationBoardCategory'
|
||||
import { loadState } from '@nextcloud/initial-state'
|
||||
|
||||
const canCreateState = loadState('deck', 'canCreate')
|
||||
|
||||
export default {
|
||||
name: 'AppNavigation',
|
||||
@@ -96,6 +99,7 @@ export default {
|
||||
groups: [],
|
||||
groupLimit: [],
|
||||
groupLimitDisabled: true,
|
||||
canCreate: canCreateState,
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
namespace OCA\Deck\Controller;
|
||||
|
||||
use OCA\Deck\Service\PermissionService;
|
||||
use OCP\IInitialStateService;
|
||||
use OCP\IL10N;
|
||||
use OCP\IRequest;
|
||||
use PHPUnit_Framework_TestCase;
|
||||
@@ -38,8 +39,8 @@ class PageControllerTest extends \Test\TestCase {
|
||||
private $request;
|
||||
private $l10n;
|
||||
private $userId = 'john';
|
||||
private $defaultBoardService;
|
||||
private $permissionService;
|
||||
private $initialState;
|
||||
private $config;
|
||||
|
||||
public function setUp(): void {
|
||||
@@ -47,9 +48,10 @@ class PageControllerTest extends \Test\TestCase {
|
||||
$this->request = $this->createMock(IRequest::class);
|
||||
$this->permissionService = $this->createMock(PermissionService::class);
|
||||
$this->config = $this->createMock(IConfig::class);
|
||||
$this->initialState = $this->createMock(IInitialStateService::class);
|
||||
|
||||
$this->controller = new PageController(
|
||||
'deck', $this->request, $this->permissionService, $this->l10n, $this->userId
|
||||
'deck', $this->request, $this->permissionService, $this->initialState, $this->l10n, $this->userId
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user