Skip to content

Commit

Permalink
Merge pull request #21 from phonetworks/edge-edit-permissions
Browse files Browse the repository at this point in the history
Edge edit permissions
  • Loading branch information
esokullu authored Aug 29, 2018
2 parents 3d5819d + 47dd568 commit 7a79d80
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 2 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
11 changes: 10 additions & 1 deletion src/Pho/Kernel/Foundation/AbstractActor.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

namespace Pho\Kernel\Foundation\Exceptions;

use Pho\Framework\ParticleInterface;
use Pho\Lib\Graph\EntityInterface;

class WriteForEdgePermissionException extends \Exception
{
public function __construct(EntityInterface $edge, ParticleInterface $node)
{
parent::__construct();
$this->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)
);
}
}
12 changes: 12 additions & 0 deletions tests/Pho/Kernel/EdgeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
*/

}

0 comments on commit 7a79d80

Please sign in to comment.