diff --git a/lib/Service/AssignmentService.php b/lib/Service/AssignmentService.php index 9d19bf663..418bbd9fa 100644 --- a/lib/Service/AssignmentService.php +++ b/lib/Service/AssignmentService.php @@ -86,7 +86,8 @@ class AssignmentService { NotificationHelper $notificationHelper, ActivityManager $activityManager, ChangeHelper $changeHelper, - IEventDispatcher $eventDispatcher + IEventDispatcher $eventDispatcher, + $userId ) { $this->permissionService = $permissionService; $this->cardMapper = $cardMapper; @@ -96,6 +97,7 @@ class AssignmentService { $this->changeHelper = $changeHelper; $this->activityManager = $activityManager; $this->eventDispatcher = $eventDispatcher; + $this->currentUser = $userId; } /** @@ -107,7 +109,7 @@ class AssignmentService { * @throws MultipleObjectsReturnedException * @throws DoesNotExistException */ - public function assignUser($cardId, $userId, int $type = 0) { + public function assignUser($cardId, $userId, int $type = AssignedUsers::TYPE_USER) { if (is_numeric($cardId) === false) { throw new BadRequestException('card id must be a number'); diff --git a/src/components/board/SharingTabSidebar.vue b/src/components/board/SharingTabSidebar.vue index 53bb7e402..be1789178 100644 --- a/src/components/board/SharingTabSidebar.vue +++ b/src/components/board/SharingTabSidebar.vue @@ -60,7 +60,7 @@ diff --git a/src/components/cards/CardItem.vue b/src/components/cards/CardItem.vue index ba8e8e553..795fbdb33 100644 --- a/src/components/cards/CardItem.vue +++ b/src/components/cards/CardItem.vue @@ -196,8 +196,13 @@ export default { }, assignCardToMe() { this.copiedCard = Object.assign({}, this.card) - this.copiedCard.newUserUid = this.card.owner.uid - this.$store.dispatch('assignCardToUser', this.copiedCard) + this.$store.dispatch('assignCardToUser', { + card: this.copiedCard, + assignee: { + userId: OC.getCurrentUser().uid, + type: 0, + }, + }) }, async loadStacksFromBoard(board) { try { @@ -234,6 +239,7 @@ export default { } .card { + transition: box-shadow 0.1s ease-in-out; box-shadow: 0 0 2px 0 var(--color-box-shadow); border-radius: 3px; font-size: 100%; diff --git a/src/services/CardApi.js b/src/services/CardApi.js index b439b45bd..c5d7037af 100644 --- a/src/services/CardApi.js +++ b/src/services/CardApi.js @@ -105,8 +105,8 @@ export class CardApi { }) } - assignUser(card) { - return axios.post(this.url(`/cards/${card.id}/assign`), { userId: card.newUserUid }) + assignUser(cardId, id, type) { + return axios.post(this.url(`/cards/${cardId}/assign`), { userId: id, type: type }) .then( (response) => { return Promise.resolve(response.data) @@ -120,8 +120,8 @@ export class CardApi { }) } - removeUser(card) { - return axios.delete(this.url(`/cards/${card.id}/assign/${card.removeUserUid}`)) + removeUser(cardId, id, type) { + return axios.put(this.url(`/cards/${cardId}/unassign`), { userId: id, type: type }) .then( (response) => { return Promise.resolve(response.data) diff --git a/src/store/card.js b/src/store/card.js index 306749c6b..4e9b40f89 100644 --- a/src/store/card.js +++ b/src/store/card.js @@ -198,12 +198,12 @@ export default { const updatedCard = await apiClient[call](card) commit('deleteCard', updatedCard) }, - async assignCardToUser({ commit }, card) { - const user = await apiClient.assignUser(card) + async assignCardToUser({ commit }, { card, assignee }) { + const user = await apiClient.assignUser(card.id, assignee.userId, assignee.type) commit('assignCardToUser', user) }, - async removeUserFromCard({ commit }, card) { - const user = await apiClient.removeUser(card) + async removeUserFromCard({ commit }, { card, assignee }) { + const user = await apiClient.removeUser(card.id, assignee.userId, assignee.type) commit('removeUserFromCard', user) }, async addLabel({ commit }, data) { @@ -219,7 +219,7 @@ export default { commit('updateCardProperty', { property: 'description', card: updatedCard }) }, async updateCardDue({ commit }, card) { - const updatedCard = apiClient.updateCard(card) + const updatedCard = await apiClient.updateCard(card) commit('updateCardProperty', { property: 'duedate', card: updatedCard }) }, }, diff --git a/src/store/main.js b/src/store/main.js index 1fef80971..3339ad5e4 100644 --- a/src/store/main.js +++ b/src/store/main.js @@ -78,8 +78,12 @@ export default new Vuex.Store({ boards: state => { return state.boards }, - sharees: state => { - return state.sharees + assignables: state => { + return [ + ...state.assignableUsers.map((user) => ({ ...user, type: 0 })), + ...state.currentBoard.acl.filter((acl) => acl.type === 1 && typeof acl.participant === 'object').map((group) => ({ ...group.participant, type: 1 })), + ...state.currentBoard.acl.filter((acl) => acl.type === 7 && typeof acl.participant === 'object').map((circle) => ({ ...circle.participant, type: 7 })), + ] }, noneArchivedBoards: state => { return state.boards.filter(board => { diff --git a/tests/unit/Service/CardServiceTest.php b/tests/unit/Service/CardServiceTest.php index 5871b333d..b6b6b033e 100644 --- a/tests/unit/Service/CardServiceTest.php +++ b/tests/unit/Service/CardServiceTest.php @@ -39,6 +39,9 @@ use OCA\Deck\Notification\NotificationHelper; use OCA\Deck\StatusException; use OCP\Activity\IEvent; use OCP\Comments\ICommentsManager; +use OCP\EventDispatcher\ABroadcastedEvent; +use OCP\EventDispatcher\Event; +use OCP\EventDispatcher\IEventDispatcher; use OCP\IUser; use OCP\IUserManager; use PHPUnit\Framework\MockObject\MockObject; @@ -91,7 +94,7 @@ class CardServiceTest extends TestCase { $this->activityManager = $this->createMock(ActivityManager::class); $this->commentsManager = $this->createMock(ICommentsManager::class); $this->userManager = $this->createMock(IUserManager::class); - $this->eventDispatcher = $this->createMock(EventDispatcherInterface::class); + $this->eventDispatcher = $this->createMock(IEventDispatcher::class); $this->changeHelper = $this->createMock(ChangeHelper::class); $this->cardService = new CardService( $this->cardMapper, @@ -318,102 +321,4 @@ class CardServiceTest extends TestCase { $this->cardService->removeLabel(123, 999); } - public function testAssignUser() { - $assignments = []; - $this->assignedUsersMapper->expects($this->once()) - ->method('find') - ->with(123) - ->willReturn($assignments); - $assignment = new AssignedUsers(); - $assignment->setCardId(123); - $assignment->setParticipant('admin'); - $this->cardMapper->expects($this->once()) - ->method('findBoardId') - ->willReturn(1); - $this->permissionService->expects($this->once()) - ->method('findUsers') - ->with(1) - ->willReturn(['admin' => 'admin', 'user1' => 'user1']); - $this->assignedUsersMapper->expects($this->once()) - ->method('insert') - ->with($assignment) - ->willReturn($assignment); - $actual = $this->cardService->assignUser(123, 'admin'); - $this->assertEquals($assignment, $actual); - } - - public function testAssignUserNoParticipant() { - $this->expectException(BadRequestException::class); - $this->expectExceptionMessage('The user is not part of the board'); - $assignments = []; - $this->assignedUsersMapper->expects($this->once()) - ->method('find') - ->with(123) - ->willReturn($assignments); - $assignment = new AssignedUsers(); - $assignment->setCardId(123); - $assignment->setParticipant('admin'); - $this->cardMapper->expects($this->once()) - ->method('findBoardId') - ->willReturn(1); - $this->permissionService->expects($this->once()) - ->method('findUsers') - ->with(1) - ->willReturn(['user2' => 'user2', 'user1' => 'user1']); - $actual = $this->cardService->assignUser(123, 'admin'); - } - - public function testAssignUserExisting() { - $this->expectException(BadRequestException::class); - $this->expectExceptionMessage('The user is already assigned to the card'); - $assignment = new AssignedUsers(); - $assignment->setCardId(123); - $assignment->setParticipant('admin'); - $assignments = [ - $assignment - ]; - $this->assignedUsersMapper->expects($this->once()) - ->method('find') - ->with(123) - ->willReturn($assignments); - $actual = $this->cardService->assignUser(123, 'admin'); - $this->assertFalse($actual); - } - - public function testUnassignUserExisting() { - $assignment = new AssignedUsers(); - $assignment->setCardId(123); - $assignment->setParticipant('admin'); - $assignments = [ - $assignment - ]; - $this->assignedUsersMapper->expects($this->once()) - ->method('find') - ->with(123) - ->willReturn($assignments); - $this->assignedUsersMapper->expects($this->once()) - ->method('delete') - ->with($assignment) - ->willReturn($assignment); - $actual = $this->cardService->unassignUser(123, 'admin'); - $this->assertEquals($assignment, $actual); - } - - public function testUnassignUserNotExisting() { - $this->expectException(NotFoundException::class); - $assignment = new AssignedUsers(); - $assignment->setCardId(123); - $assignment->setParticipant('admin'); - $assignments = [ - $assignment - ]; - $this->assignedUsersMapper->expects($this->once()) - ->method('find') - ->with(123) - ->willReturn($assignments); - $this->expectException(NotFoundException::class); - $actual = $this->cardService->unassignUser(123, 'user'); - } - - } diff --git a/tests/unit/controller/CardApiControllerTest.php b/tests/unit/controller/CardApiControllerTest.php index 2956b239c..7299da9dc 100644 --- a/tests/unit/controller/CardApiControllerTest.php +++ b/tests/unit/controller/CardApiControllerTest.php @@ -22,6 +22,7 @@ */ namespace OCA\Deck\Controller; +use OCA\Deck\Service\AssignmentService; use OCP\AppFramework\Http; use OCP\AppFramework\Http\DataResponse; use OCP\IRequest; @@ -37,12 +38,14 @@ class CardApiControllerTest extends \Test\TestCase { private $userId = 'admin'; private $cardExample; private $stackExample; + private $assignmentService; public function setUp(): void { parent::setUp(); $this->request = $this->createMock(IRequest::class); $this->cardService = $this->createMock(CardService::class); + $this->assignmentService = $this->createMock(AssignmentService::class); $this->cardExample['id'] = 1; $this->stackExample['id'] = 1; @@ -51,6 +54,7 @@ class CardApiControllerTest extends \Test\TestCase { $appName = 'deck', $this->request, $this->cardService, + $this->assignmentService, $this->userId ); }