summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--core/helpers/access.php5
-rw-r--r--core/tests/Access_Helper_Test.php17
2 files changed, 22 insertions, 0 deletions
diff --git a/core/helpers/access.php b/core/helpers/access.php
index 3fb7548d..badd9b0a 100644
--- a/core/helpers/access.php
+++ b/core/helpers/access.php
@@ -250,6 +250,10 @@ class access_Core {
* @return void
*/
public static function add_item($item) {
+ $access_intent = ORM::factory("access_intent", $item->id);
+ if ($access_intent->loaded) {
+ throw new Exception("@todo ITEM_ALREADY_ADDED $item->id");
+ }
$access_intent = ORM::factory("access_intent");
$access_intent->item_id = $item->id;
$access_intent->save();
@@ -269,6 +273,7 @@ class access_Core {
}
}
}
+ $item->save();
$access_cache->save();
}
diff --git a/core/tests/Access_Helper_Test.php b/core/tests/Access_Helper_Test.php
index 7f5aa656..9b08b2cd 100644
--- a/core/tests/Access_Helper_Test.php
+++ b/core/tests/Access_Helper_Test.php
@@ -81,6 +81,23 @@ class Access_Helper_Test extends Unit_Test_Case {
$item->delete();
}
+ public function new_photos_inherit_parent_permissions_test() {
+ $root = ORM::factory("item", 1);
+
+ $album = ORM::factory("item");
+ $album->type = "album";
+ $album->add_to_parent($root);
+ access::add_item($album);
+ access::allow(group::everybody(), "view", $album);
+
+ $photo = ORM::factory("item");
+ $photo->type = "photo";
+ $photo->add_to_parent($album);
+ access::add_item($photo);
+
+ $this->assert_true($photo->__get("view_" . group::everybody()->id));
+ }
+
public function can_allow_deny_and_reset_intent_test() {
$root = ORM::factory("item", 1);
$item = ORM::factory("item")->add_to_parent($root);