user can only clone a board on canManage permissions

Signed-off-by: Jakob Röhrl <jakob.roehrl@web.de>
This commit is contained in:
Jakob Röhrl
2020-05-12 09:17:14 +02:00
parent 1efc58404d
commit 6ea26af9ff
3 changed files with 24 additions and 22 deletions

View File

@@ -153,6 +153,6 @@ class BoardController extends ApiController {
* @return \OCP\Deck\DB\Board * @return \OCP\Deck\DB\Board
*/ */
public function clone($boardId) { public function clone($boardId) {
return $this->boardService->clone($boardId); return $this->boardService->clone($boardId, $this->userId);
} }
} }

View File

@@ -621,13 +621,14 @@ class BoardService {
/** /**
* @param $id * @param $id
* @param $userId
* @return Board * @return Board
* @throws DoesNotExistException * @throws DoesNotExistException
* @throws \OCA\Deck\NoPermissionException * @throws \OCA\Deck\NoPermissionException
* @throws \OCP\AppFramework\Db\MultipleObjectsReturnedException * @throws \OCP\AppFramework\Db\MultipleObjectsReturnedException
* @throws BadRequestException * @throws BadRequestException
*/ */
public function clone($id) { public function clone($id, $userId) {
if (is_numeric($id) === false) { if (is_numeric($id) === false) {
throw new BadRequestException('board id must be a number'); throw new BadRequestException('board id must be a number');
} }
@@ -637,7 +638,7 @@ class BoardService {
$board = $this->boardMapper->find($id); $board = $this->boardMapper->find($id);
$newBoard = new Board(); $newBoard = new Board();
$newBoard->setTitle($board->getTitle() . ' (' . $this->l10n->t('copy') . ')'); $newBoard->setTitle($board->getTitle() . ' (' . $this->l10n->t('copy') . ')');
$newBoard->setOwner($board->getOwner()); $newBoard->setOwner($userId);
$newBoard->setColor($board->getColor()); $newBoard->setColor($board->getColor());
$permissions = $this->permissionService->matchPermissions($board); $permissions = $this->permissionService->matchPermissions($board);
$newBoard->setPermissions([ $newBoard->setPermissions([

View File

@@ -149,26 +149,27 @@ export default {
text: t('deck', 'Edit board'), text: t('deck', 'Edit board'),
}) })
} }
actions.push({
action: async() => {
this.hideMenu()
this.loading = true
try {
const newBoard = await this.$store.dispatch('cloneBoard', this.board)
this.loading = false
const route = this.routeTo
route.params.id = newBoard.id
this.$router.push(route)
} catch (e) {
OC.Notification.showTemporary(t('deck', 'An error occurred'))
console.error(e)
}
},
icon: 'icon-clone',
text: t('deck', 'Clone board'),
})
if (canManage) { if (canManage) {
actions.push({
action: async() => {
this.hideMenu()
this.loading = true
try {
const newBoard = await this.$store.dispatch('cloneBoard', this.board)
this.loading = false
const route = this.routeTo
route.params.id = newBoard.id
this.$router.push(route)
} catch (e) {
OC.Notification.showTemporary(t('deck', 'An error occurred'))
console.error(e)
}
},
icon: 'icon-clone',
text: t('deck', 'Clone board'),
})
if (!this.board.archived) { if (!this.board.archived) {
actions.push({ actions.push({
action: () => { action: () => {