Skip to content
Open
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
4 changes: 2 additions & 2 deletions js/src-adminsettings.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/src-adminsettings.js.map

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions lib/Controller/CustomPropertiesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public function create(array $customProperty): Entity
$newCustomProperty->setPropertyname($customProperty['propertyname']);
$newCustomProperty->setPropertylabel($customProperty['propertylabel']);
$newCustomProperty->setPropertytype($customProperty['propertytype']);
$newCustomProperty->setPropertyshared($customProperty['propertyshared']);

if (!$newCustomProperty->isValid()) {
throw new CustomPropertyInvalidError();
Expand All @@ -72,6 +73,7 @@ public function update(array $customProperty)

$entity->setPropertyname($customProperty['propertyname']);
$entity->setPropertylabel($customProperty['propertylabel']);
$entity->setPropertyshared($customProperty['propertyshared']);

if (!$entity->isValid()) {
throw new CustomPropertyInvalidError();
Expand Down
3 changes: 3 additions & 0 deletions lib/Db/CustomProperty.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ class CustomProperty extends Entity
public $propertylabel;
/** @var string */
public $propertytype;
/** @var bool*/
public $propertyshared;

/**
* @var string
Expand All @@ -28,6 +30,7 @@ public function __construct()
$this->addType('propertyname', 'string');
$this->addType('propertylabel', 'string');
$this->addType('propertytype', 'string');
$this->addType('propertyshared', 'bool');
}

public static function withNamespaceURI($propertyname): string
Expand Down
31 changes: 31 additions & 0 deletions lib/Migration/Version1000Date20211203000000.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

namespace OCA\CustomProperties\Migration;

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

class Version1000Date20211203000000 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->addColumn('propertyshared', 'boolean', [
'notnull' => false,
'default' => false
]);

return $schema;
}
}
68 changes: 56 additions & 12 deletions lib/Plugin/CustomPropertiesSabreServerPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use OCA\CustomProperties\Db\Property;
use OCA\CustomProperties\Service\PropertyService;
use OCA\DAV\Connector\Sabre\Node;
use OCP\ILogger;
use Sabre\DAV\INode;
use Sabre\DAV\PropFind;
use Sabre\DAV\PropPatch;
Expand Down Expand Up @@ -75,12 +76,10 @@ private function getCustomPropertynames(): array
public function propFind(PropFind $propFind, INode $node)
{
if ($node instanceof Node) {
$path = "files" . DIRECTORY_SEPARATOR . \OC_User::getUser() . $node->getPath();

if ($propFind->isAllProps()) {
$this->handlePropFindAllProps($propFind, $path);
$this->handlePropFindAllProps($propFind, $node->getFileId());
} else {
$this->handlePropFind($propFind, $path);
$this->handlePropFind($propFind, $node->getFileId());
}
}
}
Expand All @@ -100,13 +99,17 @@ public function propPatch($path, PropPatch $propPatch)
return;
}

$propPatch->handle($this->getCustomPropertynames(), function ($a) use ($path) {
$propPatch->handle($this->getCustomPropertynames(), function ($a) use ($node) {
try {
foreach ($a as $key => $value) {
$property = $this->getPropByName($key);

if (!empty(trim($value))) {
$this->propertyService->upsertProperty($path, $key, $value, $this->userId);
$this->propertyService->upsertProperty($node->getFileId(), $key, $value,
$this->getEffectiveUserId($property));
} else {
$this->propertyService->deleteProperty($path, $key, $this->userId);
$this->propertyService->deleteProperty($node->getFileId(), $key,
$this->getEffectiveUserId($property));
}
}
return true;
Expand All @@ -122,8 +125,11 @@ public function propPatch($path, PropPatch $propPatch)
*/
private function handlePropFindAllProps(PropFind $propFind, string $path): void
{
foreach ($this->getCustomPropertynames() as $propertyname) {
$entity = $this->propertyService->getCustomProperty($path, $propertyname, $this->userId);
foreach ($this->customPropertyDefinitions as $property) {
$propertyname = "{" . Application::NAMESPACE_URL . "}" . $property->propertyname;

$entity = $this->propertyService->getCustomProperty($path, $propertyname,
$this->getEffectiveUserId($property));
$value = $entity === null ? null : $entity->propertyvalue;

$propFind->set($propertyname, $value);
Expand All @@ -136,10 +142,48 @@ private function handlePropFindAllProps(PropFind $propFind, string $path): void
*/
private function handlePropFind(PropFind $propFind, string $path): void
{
foreach ($this->getCustomPropertynames() as $propertyname) {
$propFind->handle($propertyname, function () use ($path, $propertyname) {
return $this->propertyService->getCustomProperty($path, $propertyname, $this->userId);
foreach ($this->customPropertyDefinitions as $property) {
$propertyname = "{" . Application::NAMESPACE_URL . "}" . $property->propertyname;

$propFind->handle($property->propertyname, function () use ($path, $property, $propertyname) {
return $this->propertyService->getCustomProperty($path, $propertyname,
$this->getEffectiveUserId($property));
});
}
}

/**
* Finds a property in the list of property definitions by name.
*
* @param string $name The property name
*/
private function getPropByName(string $name): ?CustomProperty
{
$property = current(array_filter($this->customPropertyDefinitions, function ($elem) use ($name) {
return "{" . Application::NAMESPACE_URL . "}" . $elem->propertyname === $name;
}));

if ($property === false) {
return null;
}
else {
return $property;
}
}

/**
* Gets the effective user id for the given property: an empty string for a shared property, $this->userId otherwise
*
* @param Property property
*/
private function getEffectiveUserId(CustomProperty $property): string
{
if ($property->propertyshared == true) {
return "";
}
else {
return $this->userId;
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ describe('CreateCustomPropertyForm.vue', () => {
propertytype: 'text',
propertyname: 'name',
propertylabel: 'label',
propertyshared: false,
})
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export default {
propertyname: null,
propertylabel: null,
propertytype: 'text',
propertyshared: false,
},
}
},
Expand All @@ -43,6 +44,7 @@ export default {
propertyname: null,
propertylabel: null,
propertytype: 'text',
propertyshared: false,
}
},
isBlank(str) {
Expand Down
23 changes: 22 additions & 1 deletion src/components/customPropertyForm/CustomPropertyForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,23 @@
required
type="text">
</div>
<div class="form-group form-group__propertyshared">
<select
v-model="property_.propertyshared"
:disabled="disabled.includes('propertyshared')"
aria-label="propertyshared"
class="propertyshared"
required>
<option
:key="false"
:value="false"
v-text="t('private', 'Private')" />
<option
:key="true"
:value="true"
v-text="t('shared', 'Shared')" />
</select>
</div>
</div>
</template>

Expand Down Expand Up @@ -85,7 +102,7 @@ export default {

.propertytype { margin-right: 3px; }

.propertytype, .propertyname, .propertylabel {
.propertytype, .propertyname, .propertylabel, .propertyshared {
width: 100%;
}

Expand All @@ -104,5 +121,9 @@ export default {
&__propertylabel {
flex: 4 0 0;
}

&__propertyshared {
flex: 0 0 95px;
}
}
</style>