Skip to content

Commit

Permalink
Fix error when calling REPORTs (#29)
Browse files Browse the repository at this point in the history
  • Loading branch information
SteKoe committed Jun 13, 2021
1 parent da96734 commit 007e777
Show file tree
Hide file tree
Showing 11 changed files with 73 additions and 184 deletions.
7 changes: 6 additions & 1 deletion .github/workflows/build-main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,13 @@ jobs:
- uses: actions/setup-node@v1
with:
node-version: "14.x"
- uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- run: npm ci
- run: npm run test:js
- run: npm run test

build:
name: Build
Expand Down
149 changes: 0 additions & 149 deletions Dockerfile

This file was deleted.

2 changes: 1 addition & 1 deletion appinfo/info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
Changing the property in the tab will also change the DAV property and hence it will be possible to access the
properties via DAV call `PROPFIND`.
]]></description>
<version>2.0.2</version>
<version>2.0.3</version>
<licence>apache</licence>
<author mail="nextcloud@stekoe.de">SteKoe</author>
<namespace>CustomProperties</namespace>
Expand Down
27 changes: 0 additions & 27 deletions docker-compose.yml

This file was deleted.

12 changes: 12 additions & 0 deletions infrastructure/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
version: '3'

services:
app:
image: ghcr.io/stekoe/nextcloud-docker-testing:main
ports:
- 80:80
volumes:
# - ../../nextcloud-server:/var/www/html
- ../:/var/www/html/apps/customproperties
- ~/.nextcloud:/.nextcloud

7 changes: 7 additions & 0 deletions lib/Error/CustomPropertyAlreadyExistsError.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

namespace OCA\CustomProperties\Error;

class CustomPropertyAlreadyExistsError extends \Exception
{
}
28 changes: 28 additions & 0 deletions lib/Migration/Version1000Date20210611000000.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

namespace OCA\CustomProperties\Migration;

use Closure;
use OCP\DB\ISchemaWrapper;
use OCP\Migration\IOutput;
use OCP\Migration\SimpleMigrationStep;

class Version1000Date20210611000000 extends SimpleMigrationStep
{
/**
* @param IOutput $output
* @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
* @param array $options
* @return null|ISchemaWrapper
*/
public function changeSchema(IOutput $output, Closure $schemaClosure, array $options)
{
/** @var ISchemaWrapper $schema */
$schema = $schemaClosure();
$table = $schema->getTable('customproperties');

$table->addUniqueIndex(['user_id','propertylabel']);

return $schema;
}
}
9 changes: 7 additions & 2 deletions lib/Plugin/CustomPropertiesSabreServerPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@

use OCA\CustomProperties\AppInfo\Application;
use OCA\CustomProperties\Db\CustomProperty;
use OCA\CustomProperties\Db\Property;
use OCA\CustomProperties\Service\PropertyService;
use OCA\DAV\Connector\Sabre\Node;
use Sabre\DAV\INode;
use Sabre\DAV\PropFind;
use Sabre\DAV\PropPatch;
use Sabre\DAV\Server;
use Sabre\DAV\ServerPlugin;
use function PHPUnit\Framework\isEmpty;
use Sabre\Xml\Writer;

class CustomPropertiesSabreServerPlugin extends ServerPlugin
{
Expand Down Expand Up @@ -51,6 +52,10 @@ public function initialize(Server $server)
{
$this->server = $server;

$this->server->xml->classMap[Property::class] = function (Writer $writer, Property $value) {
$writer->write($value->propertyvalue);
};

$this->server->on('propFind', [$this, 'propFind']);
$this->server->on('propPatch', [$this, 'propPatch']);
}
Expand Down Expand Up @@ -98,7 +103,7 @@ public function propPatch($path, PropPatch $propPatch)
$propPatch->handle($this->getCustomPropertynames(), function ($a) use ($path) {
try {
foreach ($a as $key => $value) {
if(!empty(trim($value))) {
if (!empty(trim($value))) {
$this->propertyService->upsertProperty($path, $key, $value, $this->userId);
} else {
$this->propertyService->deleteProperty($path, $key, $this->userId);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"watch": "NODE_ENV=development webpack --progress --watch --config webpack.config.js",
"test": "npm-run-all --parallel test:js test:php",
"test:js": "jest --env=jsdom",
"test:php": "docker-compose exec app phpunit --bootstrap tests/bootstrap.php tests/.",
"test:php": "docker-compose -f infrastructure/docker-compose.yml run app phpunit --bootstrap tests/bootstrap.php apps/customproperties/tests/.",
"lint:fix": "npm-run-all --parallel eslint:fix stylelint:fix",
"eslint": "eslint --ext .js,.vue src",
"eslint:fix": "eslint --ext .js,.vue src --fix",
Expand Down
1 change: 1 addition & 0 deletions tests/Controller/CustomPropertiesControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use OCA\CustomProperties\AppInfo\Application;
use OCA\CustomProperties\Db\CustomPropertiesMapper;
use OCA\CustomProperties\Db\CustomProperty;
use OCA\CustomProperties\Error\CustomPropertyAlreadyExistsError;
use OCA\CustomProperties\Error\CustomPropertyInvalidError;
use OCP\IRequest;
use PHPUnit\Framework\TestCase;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
use Sabre\DAV\Server;
use Sabre\DAV\Tree;

class SabreServerPluginTest extends TestCase
class CustomPropertiesSabreServerPluginTest extends TestCase
{
/**
* @var CustomPropertiesSabreServerPlugin
Expand Down Expand Up @@ -154,6 +154,13 @@ function testPropFindForCustomPropertyHavingAValue()
$this->assertEquals($this->createProperty(), $propFind->get($propertyname));
}

function testWriterCanWriteProperties() {
$writer = $this->server->xml->getWriter();
$writer->openMemory();

$this->assertNotNull($writer->writeElement("test", self::createProperty()));
}

/**
* @param CustomProperty $customProperty
* @throws \Sabre\DAV\Exception
Expand Down Expand Up @@ -185,7 +192,7 @@ private function createMocks(CustomProperty $customProperty, ?Property $property
/**
* @return CustomProperty
*/
protected function createCustomProperty(): CustomProperty
private function createCustomProperty(): CustomProperty
{
$customProperty = new CustomProperty();
$customProperty->id = 1;
Expand All @@ -198,7 +205,7 @@ protected function createCustomProperty(): CustomProperty
/**
* @return Property
*/
protected function createProperty(): Property
private function createProperty(): Property
{
$property = new Property();
$property->propertyvalue = "value";
Expand Down

0 comments on commit 007e777

Please sign in to comment.