Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions appinfo/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
['name' => 'board#update', 'url' => '/boards/{boardId}', 'verb' => 'PUT'],
['name' => 'board#delete', 'url' => '/boards/{boardId}', 'verb' => 'DELETE'],
['name' => 'board#deleteUndo', 'url' => '/boards/{boardId}/deleteUndo', 'verb' => 'POST'],
['name' => 'board#leave', 'url' => '/boards/{boardId}/leave', 'verb' => 'POST'],
['name' => 'board#getUserPermissions', 'url' => '/boards/{boardId}/permissions', 'verb' => 'GET'],
['name' => 'board#addAcl', 'url' => '/boards/{boardId}/acl', 'verb' => 'POST'],
['name' => 'board#updateAcl', 'url' => '/boards/{boardId}/acl/{aclId}', 'verb' => 'PUT'],
Expand Down
9 changes: 9 additions & 0 deletions lib/Controller/BoardController.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,15 @@ public function deleteUndo($boardId) {
return $this->boardService->deleteUndo($boardId);
}

/**
* @NoAdminRequired
* @param $boardId
* @return \OCP\AppFramework\Db\Entity|null
*/
public function leave(int $boardId) {
return $this->boardService->leave($boardId);
}

/**
* @NoAdminRequired
* @param $boardId
Expand Down
10 changes: 10 additions & 0 deletions lib/Db/AclMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,16 @@ public function findByParticipant($type, $participant): array {
return $this->findEntities($qb);
}

public function findParticipantFromBoard(int $boardId, int $type, string $participant): ?Acl {
$qb = $this->db->getQueryBuilder();
$qb->select('*')
->from('deck_board_acl')
->where($qb->expr()->eq('type', $qb->createNamedParameter($type, IQueryBuilder::PARAM_INT)))
->where($qb->expr()->eq('participant', $qb->createNamedParameter($participant, IQueryBuilder::PARAM_STR)))
->andWhere($qb->expr()->eq('board_id', $qb->createNamedParameter($boardId, IQueryBuilder::PARAM_INT)));
return $this->findEntity($qb);
}

/**
* @throws \OCP\DB\Exception
*/
Expand Down
31 changes: 31 additions & 0 deletions lib/Service/BoardService.php
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,37 @@ public function deleteAcl(int $id): ?Acl {
return $deletedAcl;
}

public function leave(int $boardId): ?Acl {
if ($this->permissionService->userIsBoardOwner($boardId)) {
throw new BadRequestException('Board owner cannot leave board');
}

$acl = $this->aclMapper->findParticipantFromBoard($boardId, Acl::PERMISSION_TYPE_USER, $this->userId);

if (!$acl) {
throw new BadRequestException('Not a participant of this board');
}

$this->assignedUsersMapper->deleteByParticipantOnBoard($acl->getParticipant(), $acl->getBoardId());

$this->activityManager->triggerEvent(ActivityManager::DECK_OBJECT_BOARD, $acl, ActivityManager::SUBJECT_BOARD_UNSHARE);
$this->changeHelper->boardChanged($acl->getBoardId());

$version = \OCP\Util::getVersion()[0];
if ($version >= 16) {
try {
$resourceProvider = Server::get(\OCA\Deck\Collaboration\Resources\ResourceProvider::class);
$resourceProvider->invalidateAccessCache($acl->getBoardId());
} catch (\Exception $e) {
}
}

$deletedAcl = $this->aclMapper->delete($acl);
$this->eventDispatcher->dispatchTyped(new AclDeletedEvent($acl));

return $deletedAcl;
}

/**
* @throws BadRequestException
* @throws DbException
Expand Down
45 changes: 45 additions & 0 deletions src/components/navigation/AppNavigationBoard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,16 @@
@click="actionDelete">
{{ t('deck', 'Delete board') }}
</NcActionButton>

<NcActionButton v-if="canLeave && !isDueSubmenuActive"
icon="icon-delete"
:close-after-click="true"
@click="actionLeave">
<template #icon>
<LeaveIcon :size="20" decorative />
</template>
{{ t('deck', 'Leave board') }}
</NcActionButton>
</template>
</NcAppNavigationItem>
<div v-else-if="editing" class="board-edit">
Expand Down Expand Up @@ -152,12 +162,15 @@ import { NcAppNavigationIconBullet, NcAppNavigationItem, NcColorPicker, NcButton
import ClickOutside from 'vue-click-outside'
import ArchiveIcon from 'vue-material-design-icons/Archive.vue'
import CloneIcon from 'vue-material-design-icons/ContentDuplicate.vue'
import LeaveIcon from 'vue-material-design-icons/ExitRun.vue'
import AccountIcon from 'vue-material-design-icons/Account.vue'
import CloseIcon from 'vue-material-design-icons/Close.vue'
import CheckIcon from 'vue-material-design-icons/Check.vue'

import { loadState } from '@nextcloud/initial-state'
import { emit } from '@nextcloud/event-bus'
import { getCurrentUser } from '@nextcloud/auth'
import { showError } from '@nextcloud/dialogs'

import isTouchDevice from '../../mixins/isTouchDevice.js'
import BoardCloneModal from './BoardCloneModal.vue'
Expand All @@ -178,6 +191,7 @@ export default {
CloneIcon,
CloseIcon,
CheckIcon,
LeaveIcon,
BoardCloneModal,
},
directives: {
Expand Down Expand Up @@ -207,6 +221,7 @@ export default {
updateDueSetting: null,
canCreate: canCreateState,
cloneModalOpen: false,
currentUser: getCurrentUser(),
}
},
computed: {
Expand All @@ -228,6 +243,9 @@ export default {
canManage() {
return this.board.permissions.PERMISSION_MANAGE
},
canLeave() {
return this.board.acl?.find((acl) => acl.participant.uid === this.currentUser?.uid && acl.participant.type === 0) !== undefined
},
dueDateReminderIcon() {
if (this.board.settings['notify-due'] === 'all') {
return 'icon-sound'
Expand Down Expand Up @@ -318,6 +336,33 @@ export default {
true,
)
},
actionLeave() {
OC.dialogs.confirmDestructive(
t('deck', 'Are you sure you want to leave the board {title}?', { title: this.board.title }),
t('deck', 'Leave the board?'),
{
type: OC.dialogs.YES_NO_BUTTONS,
confirm: t('deck', 'Leave'),
confirmClasses: 'error',
cancel: t('deck', 'Cancel'),
},
(result) => {
if (result) {
this.loading = true
this.boardApi.leaveBoard(this.board)
.then(() => {
this.loading = false
this.$store.dispatch('removeBoard', this.board)
})
.catch(() => {
showError(t('deck', 'Failed to leave the board'))
this.loading = false
})
}
},
true,
)
},
actionDetails() {
this.$router.push({ name: 'board.details', params: { id: this.board.id } })
},
Expand Down
15 changes: 15 additions & 0 deletions src/services/BoardApi.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,21 @@ export class BoardApi {
})
}

leaveBoard(board) {
return axios.post(this.url(`/boards/${board.id}/leave`))
.then(
() => {
return Promise.resolve()
},
(err) => {
return Promise.reject(err)
},
)
.catch((err) => {
return Promise.reject(err)
})
}

loadBoards() {
return axios.get(this.url('/boards'))
.then(
Expand Down
Loading