Skip to content

Commit

Permalink
In Kohana 2.4, ORM no longer does the find_all() call for us when we
Browse files Browse the repository at this point in the history
retrieve related ORMs.  If we tack a find_all() on the end, it breaks
the User_Definition interface so create User_Model::groups() and
Groups_Model::users() as glue.
  • Loading branch information
bharat committed Dec 18, 2009
1 parent 9d19e27 commit 0736cf2
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 5 deletions.
2 changes: 1 addition & 1 deletion modules/gallery/helpers/access.php
Expand Up @@ -101,7 +101,7 @@ static function user_can($user, $perm_name, $item) {

$resource = $perm_name == "view" ?
$item : model_cache::get("access_cache", $item->id, "item_id");
foreach ($user->groups->find_all() as $group) {
foreach ($user->groups() as $group) {
if ($resource->__get("{$perm_name}_{$group->id}") === self::ALLOW) {
return true;
}
Expand Down
2 changes: 1 addition & 1 deletion modules/gallery/helpers/identity.php
Expand Up @@ -75,7 +75,7 @@ static function load_user() {

if (!$session->get("group_ids")) {
$ids = array();
foreach ($user->groups->find_all() as $group) {
foreach ($user->groups() as $group) {
$ids[] = $group->id;
}
$session->set("group_ids", $ids);
Expand Down
6 changes: 3 additions & 3 deletions modules/gallery/tests/Access_Helper_Test.php
Expand Up @@ -76,7 +76,7 @@ public function user_can_access_test() {
access::deny(identity::registered_users(), "view", $item);

$user = identity::create_user("access_test", "Access Test", "");
foreach ($user->groups as $group) {
foreach ($user->groups() as $group) {
$user->remove($group);
}
$user->add($access_test);
Expand All @@ -93,7 +93,7 @@ public function user_can_no_access_test() {
access::deny(identity::registered_users(), "view", $item);

$user = identity::create_user("access_test", "Access Test", "");
foreach ($user->groups as $group) {
foreach ($user->groups() as $group) {
$user->remove($group);
}
$user->save();
Expand Down Expand Up @@ -288,7 +288,7 @@ public function non_view_permissions_can_be_revoked_lower_down_test() {
public function i_can_edit_test() {
// Create a new user that belongs to no groups
$user = identity::create_user("access_test", "Access Test", "");
foreach ($user->groups as $group) {
foreach ($user->groups() as $group) {
$user->remove($group);
}
$user->save();
Expand Down
4 changes: 4 additions & 0 deletions modules/user/models/group.php
Expand Up @@ -33,6 +33,10 @@ public function delete($id=null) {
module::event("group_deleted", $old);
}

public function users() {
return $this->users->find_all();
}

public function save() {
if (!$this->loaded()) {
$created = 1;
Expand Down
4 changes: 4 additions & 0 deletions modules/user/models/user.php
Expand Up @@ -61,6 +61,10 @@ public function avatar_url($size=80, $default=null) {
md5($this->email), $size, $default ? "&d=" . urlencode($default) : "");
}

public function groups() {
return $this->groups->find_all();
}

public function save() {
if (!$this->loaded()) {
$created = 1;
Expand Down

0 comments on commit 0736cf2

Please sign in to comment.