mirror of
https://github.com/nextcloud/server.git
synced 2026-02-03 20:41:22 -05:00
fix(comments): Check comment object
Signed-off-by: Joas Schilling <coding@schilljs.com>
This commit is contained in:
parent
11a19adc48
commit
7b274fa48c
3 changed files with 33 additions and 7 deletions
|
|
@ -102,6 +102,10 @@ class EntityCollection extends RootCollection implements IProperties {
|
|||
public function getChild($name) {
|
||||
try {
|
||||
$comment = $this->commentsManager->get($name);
|
||||
if ($comment->getObjectType() !== $this->name
|
||||
|| $comment->getObjectId() !== $this->id) {
|
||||
throw new NotFound();
|
||||
}
|
||||
return new CommentNode(
|
||||
$this->commentsManager,
|
||||
$comment,
|
||||
|
|
@ -155,8 +159,9 @@ class EntityCollection extends RootCollection implements IProperties {
|
|||
*/
|
||||
public function childExists($name) {
|
||||
try {
|
||||
$this->commentsManager->get($name);
|
||||
return true;
|
||||
$comment = $this->commentsManager->get($name);
|
||||
return $comment->getObjectType() === $this->name
|
||||
&& $comment->getObjectId() === $this->id;
|
||||
} catch (NotFoundException $e) {
|
||||
return false;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -77,14 +77,16 @@ class EntityCollectionTest extends \Test\TestCase {
|
|||
}
|
||||
|
||||
public function testGetChild() {
|
||||
$comment = $this->createMock(IComment::class);
|
||||
$comment->method('getObjectType')
|
||||
->willReturn('files');
|
||||
$comment->method('getObjectId')
|
||||
->willReturn('19');
|
||||
|
||||
$this->commentsManager->expects($this->once())
|
||||
->method('get')
|
||||
->with('55')
|
||||
->willReturn(
|
||||
$this->getMockBuilder(IComment::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock()
|
||||
);
|
||||
->willReturn($comment);
|
||||
|
||||
$node = $this->collection->getChild('55');
|
||||
$this->assertTrue($node instanceof \OCA\DAV\Comments\CommentNode);
|
||||
|
|
@ -136,6 +138,17 @@ class EntityCollectionTest extends \Test\TestCase {
|
|||
}
|
||||
|
||||
public function testChildExistsTrue() {
|
||||
$comment = $this->createMock(IComment::class);
|
||||
$comment->method('getObjectType')
|
||||
->willReturn('files');
|
||||
$comment->method('getObjectId')
|
||||
->willReturn('19');
|
||||
|
||||
$this->commentsManager->expects($this->once())
|
||||
->method('get')
|
||||
->with('44')
|
||||
->willReturn($comment);
|
||||
|
||||
$this->assertTrue($this->collection->childExists('44'));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1056,6 +1056,10 @@ class QueryBuilder implements IQueryBuilder {
|
|||
* @return $this This QueryBuilder instance.
|
||||
*/
|
||||
public function orderBy($sort, $order = null) {
|
||||
if ($order !== null && !in_array(strtoupper((string) $order), ['ASC', 'DESC'], true)) {
|
||||
$order = null;
|
||||
}
|
||||
|
||||
$this->queryBuilder->orderBy(
|
||||
$this->helper->quoteColumnName($sort),
|
||||
$order
|
||||
|
|
@ -1073,6 +1077,10 @@ class QueryBuilder implements IQueryBuilder {
|
|||
* @return $this This QueryBuilder instance.
|
||||
*/
|
||||
public function addOrderBy($sort, $order = null) {
|
||||
if ($order !== null && !in_array(strtoupper((string) $order), ['ASC', 'DESC'], true)) {
|
||||
$order = null;
|
||||
}
|
||||
|
||||
$this->queryBuilder->addOrderBy(
|
||||
$this->helper->quoteColumnName($sort),
|
||||
$order
|
||||
|
|
|
|||
Loading…
Reference in a new issue