Remove unneeded cardId parameters

Signed-off-by: Julius Härtl <jus@bitgrid.net>
This commit is contained in:
Julius Härtl
2020-07-11 11:58:53 +02:00
parent cd0b3b29f1
commit 6114c28b10
8 changed files with 46 additions and 88 deletions

View File

@@ -54,8 +54,7 @@ class AttachmentApiController extends ApiController {
* *
*/ */
public function display() { public function display() {
$attachment = $this->attachmentService->display($this->request->getParam('cardId'), $this->request->getParam('attachmentId')); return $this->attachmentService->display($this->request->getParam('attachmentId'));
return $attachment;
} }
/** /**
@@ -76,7 +75,7 @@ class AttachmentApiController extends ApiController {
* *
*/ */
public function update($data) { public function update($data) {
$attachment = $this->attachmentService->update($this->request->getParam('cardId'), $this->request->getParam('attachmentId'), $data); $attachment = $this->attachmentService->update($this->request->getParam('attachmentId'), $data);
return new DataResponse($attachment, HTTP::STATUS_OK); return new DataResponse($attachment, HTTP::STATUS_OK);
} }
@@ -87,7 +86,7 @@ class AttachmentApiController extends ApiController {
* *
*/ */
public function delete() { public function delete() {
$attachment = $this->attachmentService->delete($this->request->getParam('cardId'), $this->request->getParam('attachmentId')); $attachment = $this->attachmentService->delete($this->request->getParam('attachmentId'));
return new DataResponse($attachment, HTTP::STATUS_OK); return new DataResponse($attachment, HTTP::STATUS_OK);
} }
@@ -98,7 +97,7 @@ class AttachmentApiController extends ApiController {
* *
*/ */
public function restore() { public function restore() {
$attachment = $this->attachmentService->restore($this->request->getParam('cardId'), $this->request->getParam('attachmentId')); $attachment = $this->attachmentService->restore($this->request->getParam('attachmentId'));
return new DataResponse($attachment, HTTP::STATUS_OK); return new DataResponse($attachment, HTTP::STATUS_OK);
} }
} }

View File

@@ -52,8 +52,8 @@ class AttachmentController extends Controller {
* @return \OCP\AppFramework\Http\Response * @return \OCP\AppFramework\Http\Response
* @throws \OCA\Deck\NotFoundException * @throws \OCA\Deck\NotFoundException
*/ */
public function display($cardId, $attachmentId) { public function display($attachmentId) {
return $this->attachmentService->display($cardId, $attachmentId); return $this->attachmentService->display($attachmentId);
} }
/** /**
@@ -70,21 +70,21 @@ class AttachmentController extends Controller {
/** /**
* @NoAdminRequired * @NoAdminRequired
*/ */
public function update($cardId, $attachmentId) { public function update($attachmentId) {
return $this->attachmentService->update($cardId, $attachmentId, $this->request->getParam('data')); return $this->attachmentService->update($attachmentId, $this->request->getParam('data'));
} }
/** /**
* @NoAdminRequired * @NoAdminRequired
*/ */
public function delete($cardId, $attachmentId) { public function delete($attachmentId) {
return $this->attachmentService->delete($cardId, $attachmentId); return $this->attachmentService->delete($attachmentId);
} }
/** /**
* @NoAdminRequired * @NoAdminRequired
*/ */
public function restore($cardId, $attachmentId) { public function restore($attachmentId) {
return $this->attachmentService->restore($cardId, $attachmentId); return $this->attachmentService->restore($attachmentId);
} }
} }

View File

@@ -213,7 +213,6 @@ class AttachmentService {
/** /**
* Display the attachment * Display the attachment
* *
* @param $cardId
* @param $attachmentId * @param $attachmentId
* @return Response * @return Response
* @throws BadRequestException * @throws BadRequestException
@@ -222,11 +221,7 @@ class AttachmentService {
* @throws \OCP\AppFramework\Db\DoesNotExistException * @throws \OCP\AppFramework\Db\DoesNotExistException
* @throws \OCP\AppFramework\Db\MultipleObjectsReturnedException * @throws \OCP\AppFramework\Db\MultipleObjectsReturnedException
*/ */
public function display($cardId, $attachmentId) { public function display($attachmentId) {
if (is_numeric($cardId) === false) {
throw new BadRequestException('card id must be a number');
}
if (is_numeric($attachmentId) === false) { if (is_numeric($attachmentId) === false) {
throw new BadRequestException('attachment id must be a number'); throw new BadRequestException('attachment id must be a number');
} }
@@ -249,7 +244,6 @@ class AttachmentService {
/** /**
* Update an attachment with custom data * Update an attachment with custom data
* *
* @param $cardId
* @param $attachmentId * @param $attachmentId
* @param $request * @param $request
* @return mixed * @return mixed
@@ -258,11 +252,7 @@ class AttachmentService {
* @throws \OCP\AppFramework\Db\MultipleObjectsReturnedException * @throws \OCP\AppFramework\Db\MultipleObjectsReturnedException
* @throws BadRequestException * @throws BadRequestException
*/ */
public function update($cardId, $attachmentId, $data) { public function update($attachmentId, $data) {
if (is_numeric($cardId) === false) {
throw new BadRequestException('card id must be a number');
}
if (is_numeric($attachmentId) === false) { if (is_numeric($attachmentId) === false) {
throw new BadRequestException('attachment id must be a number'); throw new BadRequestException('attachment id must be a number');
} }
@@ -277,7 +267,7 @@ class AttachmentService {
} }
$this->permissionService->checkPermission($this->cardMapper, $attachment->getCardId(), Acl::PERMISSION_EDIT); $this->permissionService->checkPermission($this->cardMapper, $attachment->getCardId(), Acl::PERMISSION_EDIT);
$this->cache->clear('card-' . $cardId); $this->cache->clear('card-' . $attachment->getCardId());
$attachment->setData($data); $attachment->setData($data);
try { try {
@@ -304,7 +294,6 @@ class AttachmentService {
* Either mark an attachment as deleted for later removal or just remove it depending * Either mark an attachment as deleted for later removal or just remove it depending
* on the IAttachmentService implementation * on the IAttachmentService implementation
* *
* @param $cardId
* @param $attachmentId * @param $attachmentId
* @return \OCP\AppFramework\Db\Entity * @return \OCP\AppFramework\Db\Entity
* @throws \OCA\Deck\NoPermissionException * @throws \OCA\Deck\NoPermissionException
@@ -312,11 +301,7 @@ class AttachmentService {
* @throws \OCP\AppFramework\Db\MultipleObjectsReturnedException * @throws \OCP\AppFramework\Db\MultipleObjectsReturnedException
* @throws BadRequestException * @throws BadRequestException
*/ */
public function delete($cardId, $attachmentId) { public function delete($attachmentId) {
if (is_numeric($cardId) === false) {
throw new BadRequestException('card id must be a number');
}
if (is_numeric($attachmentId) === false) { if (is_numeric($attachmentId) === false) {
throw new BadRequestException('attachment id must be a number'); throw new BadRequestException('attachment id must be a number');
} }
@@ -328,7 +313,7 @@ class AttachmentService {
} }
$this->permissionService->checkPermission($this->cardMapper, $attachment->getCardId(), Acl::PERMISSION_EDIT); $this->permissionService->checkPermission($this->cardMapper, $attachment->getCardId(), Acl::PERMISSION_EDIT);
$this->cache->clear('card-' . $cardId); $this->cache->clear('card-' . $attachment->getCardId());
try { try {
$service = $this->getService($attachment->getType()); $service = $this->getService($attachment->getType());
@@ -347,11 +332,7 @@ class AttachmentService {
return $attachment; return $attachment;
} }
public function restore($cardId, $attachmentId) { public function restore($attachmentId) {
if (is_numeric($cardId) === false) {
throw new BadRequestException('card id must be a number');
}
if (is_numeric($attachmentId) === false) { if (is_numeric($attachmentId) === false) {
throw new BadRequestException('attachment id must be a number'); throw new BadRequestException('attachment id must be a number');
} }
@@ -363,7 +344,7 @@ class AttachmentService {
} }
$this->permissionService->checkPermission($this->cardMapper, $attachment->getCardId(), Acl::PERMISSION_EDIT); $this->permissionService->checkPermission($this->cardMapper, $attachment->getCardId(), Acl::PERMISSION_EDIT);
$this->cache->clear('card-' . $cardId); $this->cache->clear('card-' . $attachment->getCardId());
try { try {
$service = $this->getService($attachment->getType()); $service = $this->getService($attachment->getType());

View File

@@ -133,7 +133,7 @@ class PermissionService {
*/ */
public function checkPermission($mapper, $id, $permission, $userId = null) { public function checkPermission($mapper, $id, $permission, $userId = null) {
$boardId = $id; $boardId = $id;
if ($mapper instanceof IPermissionMapper) { if ($mapper instanceof IPermissionMapper && !($mapper instanceof BoardMapper)) {
$boardId = $mapper->findBoardId($id); $boardId = $mapper->findBoardId($id);
} }
if ($boardId === null) { if ($boardId === null) {

View File

@@ -147,9 +147,7 @@ class StackService {
} }
public function fetchDeleted($boardId) { public function fetchDeleted($boardId) {
$this->permissionService->checkPermission( $this->permissionService->checkPermission($this->boardMapper, $boardId, Acl::PERMISSION_READ);
$this->boardMapper, $boardId, Acl::PERMISSION_READ
);
$stacks = $this->stackMapper->findDeleted($boardId); $stacks = $this->stackMapper->findDeleted($boardId);
$this->enrichStacksWithCards($stacks); $this->enrichStacksWithCards($stacks);

View File

@@ -155,6 +155,7 @@ class AttachmentServiceTest extends TestCase {
$attachment = new Attachment(); $attachment = new Attachment();
$attachment->setType($type); $attachment->setType($type);
$attachment->setData($data); $attachment->setData($data);
$attachment->setCardId(123);
return $attachment; return $attachment;
} }
@@ -255,7 +256,7 @@ class AttachmentServiceTest extends TestCase {
->method('display') ->method('display')
->with($attachment) ->with($attachment)
->willReturn($response); ->willReturn($response);
$actual = $this->attachmentService->display(123, 1); $actual = $this->attachmentService->display(1);
$this->assertEquals($response, $actual); $this->assertEquals($response, $actual);
} }
@@ -272,7 +273,7 @@ class AttachmentServiceTest extends TestCase {
->method('display') ->method('display')
->with($attachment) ->with($attachment)
->will($this->throwException(new InvalidAttachmentType('deck_file'))); ->will($this->throwException(new InvalidAttachmentType('deck_file')));
$this->attachmentService->display(123, 1); $this->attachmentService->display(1);
} }
public function testUpdate() { public function testUpdate() {
$attachment = $this->createAttachment('deck_file', 'file_name.jpg'); $attachment = $this->createAttachment('deck_file', 'file_name.jpg');
@@ -294,7 +295,7 @@ class AttachmentServiceTest extends TestCase {
$a->setExtendedData(['mime' => 'image/jpeg']); $a->setExtendedData(['mime' => 'image/jpeg']);
}); });
$actual = $this->attachmentService->update(123, 1, 'file_name.jpg'); $actual = $this->attachmentService->update(1, 'file_name.jpg');
$expected->setExtendedData(['mime' => 'image/jpeg']); $expected->setExtendedData(['mime' => 'image/jpeg']);
$expected->setLastModified($attachment->getLastModified()); $expected->setLastModified($attachment->getLastModified());
@@ -318,7 +319,7 @@ class AttachmentServiceTest extends TestCase {
$this->attachmentMapper->expects($this->once()) $this->attachmentMapper->expects($this->once())
->method('delete') ->method('delete')
->willReturn($attachment); ->willReturn($attachment);
$actual = $this->attachmentService->delete(123, 1); $actual = $this->attachmentService->delete(1);
$this->assertEquals($expected, $actual); $this->assertEquals($expected, $actual);
} }
@@ -343,7 +344,7 @@ class AttachmentServiceTest extends TestCase {
->method('update') ->method('update')
->willReturn($attachment); ->willReturn($attachment);
$expected->setDeletedAt(23); $expected->setDeletedAt(23);
$actual = $this->attachmentService->delete(123, 1); $actual = $this->attachmentService->delete(1);
$this->assertEquals($expected, $actual); $this->assertEquals($expected, $actual);
} }
@@ -363,7 +364,7 @@ class AttachmentServiceTest extends TestCase {
->method('update') ->method('update')
->willReturn($attachment); ->willReturn($attachment);
$expected->setDeletedAt(0); $expected->setDeletedAt(0);
$actual = $this->attachmentService->restore(123, 1); $actual = $this->attachmentService->restore(1);
$this->assertEquals($expected, $actual); $this->assertEquals($expected, $actual);
} }
@@ -380,6 +381,6 @@ class AttachmentServiceTest extends TestCase {
$this->attachmentServiceImpl->expects($this->once()) $this->attachmentServiceImpl->expects($this->once())
->method('allowUndo') ->method('allowUndo')
->willReturn(false); ->willReturn(false);
$actual = $this->attachmentService->restore(123, 1); $actual = $this->attachmentService->restore(1);
} }
} }

View File

@@ -73,14 +73,9 @@ class AttachmentApiControllerTest extends \Test\TestCase {
->method('display') ->method('display')
->willReturn($this->attachmentExample); ->willReturn($this->attachmentExample);
$this->request->expects($this->exactly(2)) $this->request->expects($this->once())
->method('getParam') ->method('getParam')
->withConsecutive( ->willReturn($this->attachmentExample->getId());
['cardId'],
['attachmentId']
)->willReturnonConsecutiveCalls(
$this->cardId,
$this->attachmentExample->getId());
$expected = $this->attachmentExample; $expected = $this->attachmentExample;
$actual = $this->controller->display(); $actual = $this->controller->display();
@@ -114,14 +109,9 @@ class AttachmentApiControllerTest extends \Test\TestCase {
->method('update') ->method('update')
->willReturn($this->attachmentExample); ->willReturn($this->attachmentExample);
$this->request->expects($this->exactly(2)) $this->request->expects($this->once())
->method('getParam') ->method('getParam')
->withConsecutive( ->willReturn($this->attachmentExample->getId());
['cardId'],
['attachmentId']
)->willReturnonConsecutiveCalls(
$this->cardId,
$this->attachmentExample->getId());
$expected = new DataResponse($this->attachmentExample, HTTP::STATUS_OK); $expected = new DataResponse($this->attachmentExample, HTTP::STATUS_OK);
$actual = $this->controller->update($data); $actual = $this->controller->update($data);
@@ -133,14 +123,9 @@ class AttachmentApiControllerTest extends \Test\TestCase {
->method('delete') ->method('delete')
->willReturn($this->attachmentExample); ->willReturn($this->attachmentExample);
$this->request->expects($this->exactly(2)) $this->request->expects($this->once())
->method('getParam') ->method('getParam')
->withConsecutive( ->willReturn($this->attachmentExample->getId());
['cardId'],
['attachmentId']
)->willReturnonConsecutiveCalls(
$this->cardId,
$this->attachmentExample->getId());
$expected = new DataResponse($this->attachmentExample, HTTP::STATUS_OK); $expected = new DataResponse($this->attachmentExample, HTTP::STATUS_OK);
$actual = $this->controller->delete(); $actual = $this->controller->delete();
@@ -152,14 +137,9 @@ class AttachmentApiControllerTest extends \Test\TestCase {
->method('restore') ->method('restore')
->willReturn($this->attachmentExample); ->willReturn($this->attachmentExample);
$this->request->expects($this->exactly(2)) $this->request->expects($this->once())
->method('getParam') ->method('getParam')
->withConsecutive( ->willReturn($this->attachmentExample->getId());
['cardId'],
['attachmentId']
)->willReturnonConsecutiveCalls(
$this->cardId,
$this->attachmentExample->getId());
$expected = new DataResponse($this->attachmentExample, HTTP::STATUS_OK); $expected = new DataResponse($this->attachmentExample, HTTP::STATUS_OK);
$actual = $this->controller->restore(); $actual = $this->controller->restore();

View File

@@ -44,8 +44,7 @@ class AttachmentControllerTest extends \Test\TestCase {
$this->controller = new AttachmentController( $this->controller = new AttachmentController(
'deck', 'deck',
$this->request, $this->request,
$this->attachmentService, $this->attachmentService
$this->userId
); );
} }
@@ -55,8 +54,8 @@ class AttachmentControllerTest extends \Test\TestCase {
} }
public function testDisplay() { public function testDisplay() {
$this->attachmentService->expects($this->once())->method('display')->with(1, 2); $this->attachmentService->expects($this->once())->method('display')->with(2);
$this->controller->display(1, 2); $this->controller->display(2);
} }
public function testCreate() { public function testCreate() {
@@ -76,25 +75,25 @@ class AttachmentControllerTest extends \Test\TestCase {
->will($this->onConsecutiveCalls('data')); ->will($this->onConsecutiveCalls('data'));
$this->attachmentService->expects($this->once()) $this->attachmentService->expects($this->once())
->method('update') ->method('update')
->with(1, 2, 'data') ->with(2, 'data')
->willReturn(1); ->willReturn(1);
$this->assertEquals(1, $this->controller->update(1, 2)); $this->assertEquals(1, $this->controller->update(2));
} }
public function testDelete() { public function testDelete() {
$this->attachmentService->expects($this->once()) $this->attachmentService->expects($this->once())
->method('delete') ->method('delete')
->with(123, 234) ->with(234)
->willReturn(1); ->willReturn(1);
$this->assertEquals(1, $this->controller->delete(123, 234)); $this->assertEquals(1, $this->controller->delete(234));
} }
public function testRestore() { public function testRestore() {
$this->attachmentService->expects($this->once()) $this->attachmentService->expects($this->once())
->method('restore') ->method('restore')
->with(123, 234) ->with(234)
->willReturn(1); ->willReturn(1);
$this->assertEquals(1, $this->controller->restore(123, 234)); $this->assertEquals(1, $this->controller->restore(234));
} }
} }