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;
|
namespace OCA\Deck\Controller;
|
||||||
|
|
||||||
|
use OCA\Deck\AppInfo\Application;
|
||||||
use OCA\Deck\Service\PermissionService;
|
use OCA\Deck\Service\PermissionService;
|
||||||
|
use OCP\IInitialStateService;
|
||||||
use OCP\IRequest;
|
use OCP\IRequest;
|
||||||
use OCP\AppFramework\Http\TemplateResponse;
|
use OCP\AppFramework\Http\TemplateResponse;
|
||||||
use OCP\AppFramework\Controller;
|
use OCP\AppFramework\Controller;
|
||||||
@@ -34,11 +36,13 @@ class PageController extends Controller {
|
|||||||
private $permissionService;
|
private $permissionService;
|
||||||
private $userId;
|
private $userId;
|
||||||
private $l10n;
|
private $l10n;
|
||||||
|
private $initialState;
|
||||||
|
|
||||||
public function __construct(
|
public function __construct(
|
||||||
$AppName,
|
$AppName,
|
||||||
IRequest $request,
|
IRequest $request,
|
||||||
PermissionService $permissionService,
|
PermissionService $permissionService,
|
||||||
|
IInitialStateService $initialStateService,
|
||||||
IL10N $l10n,
|
IL10N $l10n,
|
||||||
$userId
|
$userId
|
||||||
) {
|
) {
|
||||||
@@ -46,6 +50,7 @@ class PageController extends Controller {
|
|||||||
|
|
||||||
$this->userId = $userId;
|
$this->userId = $userId;
|
||||||
$this->permissionService = $permissionService;
|
$this->permissionService = $permissionService;
|
||||||
|
$this->initialState = $initialStateService;
|
||||||
$this->l10n = $l10n;
|
$this->l10n = $l10n;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -57,13 +62,10 @@ class PageController extends Controller {
|
|||||||
* @NoCSRFRequired
|
* @NoCSRFRequired
|
||||||
*/
|
*/
|
||||||
public function index() {
|
public function index() {
|
||||||
$params = [
|
$this->initialState->provideInitialState(Application::APP_ID, 'maxUploadSize', (int)\OCP\Util::uploadLimit());
|
||||||
'user' => $this->userId,
|
$this->initialState->provideInitialState(Application::APP_ID, 'canCreate', $this->permissionService->canCreate());
|
||||||
'maxUploadSize' => (int)\OCP\Util::uploadLimit(),
|
|
||||||
'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": {
|
"@nextcloud/l10n": {
|
||||||
"version": "1.1.0",
|
"version": "1.1.0",
|
||||||
"resolved": "https://registry.npmjs.org/@nextcloud/l10n/-/l10n-1.1.0.tgz",
|
"resolved": "https://registry.npmjs.org/@nextcloud/l10n/-/l10n-1.1.0.tgz",
|
||||||
|
|||||||
@@ -31,9 +31,10 @@
|
|||||||
"@juliushaertl/vue-richtext": "^0.3.0",
|
"@juliushaertl/vue-richtext": "^0.3.0",
|
||||||
"@nextcloud/auth": "^1.2.1",
|
"@nextcloud/auth": "^1.2.1",
|
||||||
"@nextcloud/axios": "^1.3.1",
|
"@nextcloud/axios": "^1.3.1",
|
||||||
"@nextcloud/l10n": "^1.1.0",
|
|
||||||
"@nextcloud/dialogs": "^1.2.1",
|
"@nextcloud/dialogs": "^1.2.1",
|
||||||
"@nextcloud/files": "^1.0.0",
|
"@nextcloud/files": "^1.0.0",
|
||||||
|
"@nextcloud/initial-state": "^1.1.0",
|
||||||
|
"@nextcloud/l10n": "^1.1.0",
|
||||||
"@nextcloud/moment": "^1.1.0",
|
"@nextcloud/moment": "^1.1.0",
|
||||||
"@nextcloud/router": "^1.0.0",
|
"@nextcloud/router": "^1.0.0",
|
||||||
"@nextcloud/vue": "^1.4.0",
|
"@nextcloud/vue": "^1.4.0",
|
||||||
|
|||||||
@@ -84,6 +84,9 @@ import { Actions, ActionButton, Modal } from '@nextcloud/vue'
|
|||||||
import { showError } from '@nextcloud/dialogs'
|
import { showError } from '@nextcloud/dialogs'
|
||||||
import { formatFileSize } from '@nextcloud/files'
|
import { formatFileSize } from '@nextcloud/files'
|
||||||
import relativeDate from '../../mixins/relativeDate'
|
import relativeDate from '../../mixins/relativeDate'
|
||||||
|
import { loadState } from '@nextcloud/initial-state'
|
||||||
|
|
||||||
|
const maxUploadSizeState = loadState('deck', 'maxUploadSize')
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'CardSidebarTabAttachments',
|
name: 'CardSidebarTabAttachments',
|
||||||
@@ -104,6 +107,7 @@ export default {
|
|||||||
modalShow: false,
|
modalShow: false,
|
||||||
file: '',
|
file: '',
|
||||||
overwriteAttachment: null,
|
overwriteAttachment: null,
|
||||||
|
maxUploadSize: maxUploadSizeState,
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
@@ -140,11 +144,21 @@ export default {
|
|||||||
this.$refs.localAttachments.click()
|
this.$refs.localAttachments.click()
|
||||||
},
|
},
|
||||||
async onLocalAttachmentSelected(event) {
|
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()
|
const bodyFormData = new FormData()
|
||||||
bodyFormData.append('cardId', this.card.id)
|
bodyFormData.append('cardId', this.card.id)
|
||||||
bodyFormData.append('type', 'deck_file')
|
bodyFormData.append('type', 'deck_file')
|
||||||
bodyFormData.append('file', event.target.files[0])
|
bodyFormData.append('file', file)
|
||||||
this.file = event.target.files[0]
|
|
||||||
try {
|
try {
|
||||||
await this.$store.dispatch('createAttachment', { cardId: this.card.id, formData: bodyFormData })
|
await this.$store.dispatch('createAttachment', { cardId: this.card.id, formData: bodyFormData })
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
|||||||
@@ -39,7 +39,7 @@
|
|||||||
:text="t('deck', 'Shared boards')"
|
:text="t('deck', 'Shared boards')"
|
||||||
:boards="sharedBoards"
|
:boards="sharedBoards"
|
||||||
icon="icon-shared" />
|
icon="icon-shared" />
|
||||||
<AppNavigationAddBoard />
|
<AppNavigationAddBoard v-if="canCreate" />
|
||||||
</ul>
|
</ul>
|
||||||
<div v-if="isAdmin"
|
<div v-if="isAdmin"
|
||||||
id="app-settings"
|
id="app-settings"
|
||||||
@@ -73,6 +73,9 @@ import { Multiselect } from '@nextcloud/vue'
|
|||||||
|
|
||||||
import AppNavigationAddBoard from './AppNavigationAddBoard'
|
import AppNavigationAddBoard from './AppNavigationAddBoard'
|
||||||
import AppNavigationBoardCategory from './AppNavigationBoardCategory'
|
import AppNavigationBoardCategory from './AppNavigationBoardCategory'
|
||||||
|
import { loadState } from '@nextcloud/initial-state'
|
||||||
|
|
||||||
|
const canCreateState = loadState('deck', 'canCreate')
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'AppNavigation',
|
name: 'AppNavigation',
|
||||||
@@ -96,6 +99,7 @@ export default {
|
|||||||
groups: [],
|
groups: [],
|
||||||
groupLimit: [],
|
groupLimit: [],
|
||||||
groupLimitDisabled: true,
|
groupLimitDisabled: true,
|
||||||
|
canCreate: canCreateState,
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
|
|||||||
@@ -25,6 +25,7 @@
|
|||||||
namespace OCA\Deck\Controller;
|
namespace OCA\Deck\Controller;
|
||||||
|
|
||||||
use OCA\Deck\Service\PermissionService;
|
use OCA\Deck\Service\PermissionService;
|
||||||
|
use OCP\IInitialStateService;
|
||||||
use OCP\IL10N;
|
use OCP\IL10N;
|
||||||
use OCP\IRequest;
|
use OCP\IRequest;
|
||||||
use PHPUnit_Framework_TestCase;
|
use PHPUnit_Framework_TestCase;
|
||||||
@@ -38,8 +39,8 @@ class PageControllerTest extends \Test\TestCase {
|
|||||||
private $request;
|
private $request;
|
||||||
private $l10n;
|
private $l10n;
|
||||||
private $userId = 'john';
|
private $userId = 'john';
|
||||||
private $defaultBoardService;
|
|
||||||
private $permissionService;
|
private $permissionService;
|
||||||
|
private $initialState;
|
||||||
private $config;
|
private $config;
|
||||||
|
|
||||||
public function setUp(): void {
|
public function setUp(): void {
|
||||||
@@ -47,9 +48,10 @@ class PageControllerTest extends \Test\TestCase {
|
|||||||
$this->request = $this->createMock(IRequest::class);
|
$this->request = $this->createMock(IRequest::class);
|
||||||
$this->permissionService = $this->createMock(PermissionService::class);
|
$this->permissionService = $this->createMock(PermissionService::class);
|
||||||
$this->config = $this->createMock(IConfig::class);
|
$this->config = $this->createMock(IConfig::class);
|
||||||
|
$this->initialState = $this->createMock(IInitialStateService::class);
|
||||||
|
|
||||||
$this->controller = new PageController(
|
$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