From 3cb29d4bcf7bd93f87435b994878c2604c871612 Mon Sep 17 00:00:00 2001 From: Emre Sokullu Date: Wed, 29 Aug 2018 16:11:31 -0700 Subject: [PATCH 1/3] Update AbstractActor.php --- src/Pho/Kernel/Foundation/AbstractActor.php | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/Pho/Kernel/Foundation/AbstractActor.php b/src/Pho/Kernel/Foundation/AbstractActor.php index 7a7eb58..1b1ae3e 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); From fe16a1a2dd9408164b3743204579a65e0e4ee761 Mon Sep 17 00:00:00 2001 From: Groups Date: Wed, 29 Aug 2018 16:21:16 -0700 Subject: [PATCH 2/3] reorganized exceptions --- src/Pho/Kernel/Foundation/AbstractActor.php | 2 +- .../WriteForEdgePermissionException.php | 21 +++++++++++++++++++ tests/assets/Twitter | 2 +- 3 files changed, 23 insertions(+), 2 deletions(-) create mode 100644 src/Pho/Kernel/Foundation/Exceptions/WriteForEdgePermissionException.php diff --git a/src/Pho/Kernel/Foundation/AbstractActor.php b/src/Pho/Kernel/Foundation/AbstractActor.php index 1b1ae3e..a416a35 100644 --- a/src/Pho/Kernel/Foundation/AbstractActor.php +++ b/src/Pho/Kernel/Foundation/AbstractActor.php @@ -56,7 +56,7 @@ public function edit(EntityInterface $obj): EntityInterface { if($obj instanceof EdgeInterface) { - if($this->equals($obj->tail()->node()) + if($this->equals($obj->tail()->node())) return $obj; else throw new Exceptions\WriteForEdgePermissionException($obj, $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/assets/Twitter b/tests/assets/Twitter index ae7290f..99aed46 160000 --- a/tests/assets/Twitter +++ b/tests/assets/Twitter @@ -1 +1 @@ -Subproject commit ae7290fa5b05370712082d3f17cc1d9560964ae4 +Subproject commit 99aed46f1c9974fd70dc928fe850c4ad073577b1 From 47dd568342c20c06d48dddbf3517e408da9b0208 Mon Sep 17 00:00:00 2001 From: Groups Date: Wed, 29 Aug 2018 16:35:29 -0700 Subject: [PATCH 3/3] added a test skeleton --- composer.json | 2 +- tests/Pho/Kernel/EdgeTest.php | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) 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/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