diff --git a/composer.json b/composer.json index 16da91c..44fe665 100644 --- a/composer.json +++ b/composer.json @@ -18,7 +18,7 @@ "monolog/monolog": "^1.22", "zendframework/zend-config": "*", "pimple/pimple": "^1.1", - "phonetworks/pho-lib-graph": "^7.1", + "phonetworks/pho-lib-graph": "^7.3", "phonetworks/pho-framework": "^10.0", "webmozart/assert": "^1.2", "danielstjules/stringy": "^3.0", diff --git a/src/Pho/Kernel/Foundation/AbstractActor.php b/src/Pho/Kernel/Foundation/AbstractActor.php index 7a7eb58..a416a35 100644 --- a/src/Pho/Kernel/Foundation/AbstractActor.php +++ b/src/Pho/Kernel/Foundation/AbstractActor.php @@ -5,6 +5,8 @@ use Pho\Framework; use Pho\Kernel\Kernel; use Pho\Kernel\Standards; +use Pho\Lib\Graph\EntityInterface; +use Pho\Lib\Graph\EdgeInterface; abstract class AbstractActor extends Framework\Actor implements ParticleInterface { @@ -50,8 +52,15 @@ public function __construct(Kernel $kernel, Framework\ContextInterface $graph) } } - public function edit(ParticleInterface $obj): ParticleInterface + public function edit(EntityInterface $obj): EntityInterface { + if($obj instanceof EdgeInterface) + { + if($this->equals($obj->tail()->node())) + return $obj; + else + throw new Exceptions\WriteForEdgePermissionException($obj, $this); + } if(!$obj->acl()->writeable($this)) throw new Exceptions\WriteByPermissionException($obj, $this); // $obj->lock($this); diff --git a/src/Pho/Kernel/Foundation/Exceptions/WriteForEdgePermissionException.php b/src/Pho/Kernel/Foundation/Exceptions/WriteForEdgePermissionException.php new file mode 100644 index 0000000..519cb57 --- /dev/null +++ b/src/Pho/Kernel/Foundation/Exceptions/WriteForEdgePermissionException.php @@ -0,0 +1,21 @@ +message = sprintf( + "The edge %s (a %s) cannot be edited by the node %s (a %s)", + (string) $edge->id(), + get_class($edge), + (string) $node->id(), + get_class($node) + ); + } +} \ No newline at end of file diff --git a/tests/Pho/Kernel/EdgeTest.php b/tests/Pho/Kernel/EdgeTest.php index 1865b20..eff0dfb 100644 --- a/tests/Pho/Kernel/EdgeTest.php +++ b/tests/Pho/Kernel/EdgeTest.php @@ -88,4 +88,16 @@ public function testEdgeAttributePersistence() { $this->assertEquals($like_content, $like_recreated->attributes()->content); } + /* + * @todo implement this + * // check for permissions + public function testEdgeProperEdit() { + $this->flushDBandRestart(); + $user = new \PhoNetworksAutogenerated\User($this->kernel, $this->graph, "123456"); + $content = $this->kernel->founder()->post("emre sokullu"); + $edge = $content->edges()->in()->current(); + eval(\Psy\sh()); + } + */ + } \ No newline at end of file