Skip to content

Commit

Permalink
Add missing permission checks.
Browse files Browse the repository at this point in the history
Make the tag relationship an associative array.
  • Loading branch information
bharat committed Jan 30, 2010
1 parent a956098 commit a04d0d2
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
6 changes: 3 additions & 3 deletions modules/tag/helpers/tag_item_rest.php
Expand Up @@ -23,8 +23,8 @@ static function get($request) {
return array(
"url" => $request->url,
"members" => array(
rest::url("tag", $tag),
rest::url("item", $item)));
"tag" => rest::url("tag", $tag),
"item" => rest::url("item", $item)));
}

static function delete($request) {
Expand All @@ -37,7 +37,7 @@ static function resolve($tuple) {
list ($tag_id, $item_id) = split(",", $tuple);
$tag = ORM::factory("tag", $tag_id);
$item = ORM::factory("item", $item_id);
if (!$tag->loaded() || !$item->loaded() || !$tag->has($item)) {
if (!$tag->loaded() || !$item->loaded() || !$tag->has($item) || !access::can("view", $item)) {
throw new Kohana_404_Exception();
}

Expand Down
8 changes: 6 additions & 2 deletions modules/tag/helpers/tag_items_rest.php
Expand Up @@ -37,12 +37,16 @@ static function post($request) {
$item = rest::resolve($request->params->item);
access::required("view", $item);

if (!$tag->loaded()) {
throw new Kohana_404_Exception();
}

tag::add($item, $tag->name);
return array(
"url" => rest::url("tag_item", $tag, $item),
"members" => array(
rest::url("tag", $tag),
rest::url("item", $item)));
"tag" => rest::url("tag", $tag),
"item" => rest::url("item", $item)));
}

static function delete($request) {
Expand Down
4 changes: 2 additions & 2 deletions modules/tag/tests/Tag_Item_Rest_Helper_Test.php
Expand Up @@ -32,8 +32,8 @@ public function get_test() {
$this->assert_equal_array(
array("url" => rest::url("tag_item", $tag, item::root()),
"members" => array(
rest::url("tag", $tag),
rest::url("item", item::root()))),
"tag" => rest::url("tag", $tag),
"item" => rest::url("item", item::root()))),
tag_item_rest::get($request));
}

Expand Down

0 comments on commit a04d0d2

Please sign in to comment.