Skip to content
Browse files

added Owned behavior & global rules fix with tests

  • Loading branch information...
1 parent 2be7729 commit 9dc54b4ee9aeefcc1c59c6015674d07ade0d571e @everzet committed Mar 18, 2010
View
1 config/doctrine/sfObjectGuardUser.yml
@@ -51,4 +51,3 @@ sfObjectGuardUser:
class: sfObjectGuardActivationKey
local: id
foreign: user_id
-
View
0 lib/doctrine/Guardable.php → lib/doctrine/Guardable/Guardable.php
File renamed without changes.
View
0 lib/doctrine/template/Guardable.php → ...doctrine/Guardable/template/Guardable.php
File renamed without changes.
View
36 lib/doctrine/Owned/template/Owned.php
@@ -0,0 +1,36 @@
+<?php
+
+/*
+ * This file is part of the sfDoctrineObjectGuardPlugin.
+ * (c) 2009 Konstantin Kudryashov <ever.zet@gmail.com>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+/**
+ * Doctrine_Template_Owned extends doctrine with Owned behavior.
+ *
+ * @package sfDoctrineObjectGuardPlugin
+ * @subpackage behavior
+ * @author Konstantin Kudryashov <ever.zet@gmail.com>
+ * @version 1.0.0
+ */
+class Doctrine_Template_Owned extends Doctrine_Template
+{
+ protected $_options = array('ownerColumn' => 'owner_id');
+
+ public function setTableDefinition()
+ {
+ $this->hasColumn($this->_options['ownerColumn'], 'integer', 4);
+ }
+
+ public function setUp()
+ {
+ $this->hasOne('sfObjectGuardUser as Owner', array(
+ 'local' => $this->_options['ownerColumn'],
+ 'foreign' => 'id',
+ 'onDelete' => 'CASCADE'
+ ));
+ }
+}
View
8 lib/model/doctrine/PluginsfObjectGuardUserGroupTable.class.php
@@ -9,21 +9,21 @@ public function getCredentialsForUserQuery($user)
return Doctrine_Query::create()->
select('p.name as perm_name')->
from('sfObjectGuardUserGroup ug')->
- leftJoin('ug.sfObjectGuardGroup g')->
- leftJoin('g.permissions p')->
+ leftJoin('ug.Group g')->
+ leftJoin('g.Permissions p')->
where('ug.user_id = ?', $user->getId());
}
public function getCredentialsForUser($user)
{
$permissions = $this->
getCredentialsForUserQuery($user)->
- fetchArray();
+ execute(array(), Doctrine::HYDRATE_NONE);
$credentials = array();
foreach ($permissions as $permission)
{
- $credentials[] = 'global/' . $permission['perm_name'];
+ $credentials[] = 'global/' . $permission[0];
}
return $credentials;
View
39 lib/routing/sfObjectGuardRouting.class.php
@@ -89,4 +89,43 @@ static public function addPasswordRemindRoutes(sfEvent $event)
new sfRoute('/user/remind', array('module' => 'sfObjectGuardPasswordRemind', 'action' => 'index'))
);
}
+
+ /**
+ * Listens to the routing.load_configuration event & adds password remind page routes if needed
+ *
+ * @param sfEvent An sfEvent instance
+ */
+ static public function addCredentialsTestRoutes(sfEvent $event)
+ {
+ $routes = $event->getSubject();
+
+ //$routes->prependRoute(
+ // 'sf_object_guard_test_add_publication',
+ // new sfRoute('/sf_object_guard_test/add_publication', array(
+ // 'module' => 'sfObjectGuardCredentialsTest', 'action' => 'addPublication'
+ // ))
+ //);
+
+ $routes->prependRoute(
+ 'sf_object_guard_test_add_publication',
+ new sfDoctrineRoute('/sf_object_guard_test/:id/add_publication', array(
+ 'module' => 'sfObjectGuardCredentialsTest',
+ 'action' => 'addPublication'
+ ), array(), array(
+ 'model' => 'sfObjectGuardTest',
+ 'type' => 'object',
+ ))
+ );
+
+ $routes->prependRoute(
+ 'sf_object_guard_test_edit_publication',
+ new sfDoctrineRoute('/sf_object_guard_test/:id/edit', array(
+ 'module' => 'sfObjectGuardCredentialsTest',
+ 'action' => 'editPublication'
+ ), array(), array(
+ 'model' => 'sfObjectGuardTest',
+ 'type' => 'object',
+ ))
+ );
+ }
}
View
21 test/fixtures/TestGroupsAndPermissions.yml
@@ -29,18 +29,18 @@ sfObjectGuardUser:
email: everzet@gmail.com
is_active: false
password: tesPasas123sa
- UserAdmin:
- email: admin@test.com
+ User3:
+ email: cred_test1@tester.com
is_active: true
- password: test_pass
- UserModerator:
- email: moderator@test.com
+ password: test_PaSS
+ User4:
+ email: cred_test2@tester.com
is_active: true
- password: test_pass
- UserParticipant:
- email: part@test.com
+ password: test_PaSS
+ User5:
+ email: cred_test3@tester.com
is_active: true
- password: test_pass
+ password: test_PaSS
sfObjectGuardGroup:
Participants:
@@ -66,9 +66,6 @@ sfObjectGuardPermission:
ComFryPublication:
name: fry_publication
description: Can set highest priority to publication in sfObjectGuardTest
- ComSettings:
- name: settings
- description: Can view and change sfObjectGuardTest settings
ComPromoteModerator:
name: promote_moderator
description: Can promote users for moderator of sfObjectGuardTest
View
18 test/unit/sfObjectGuardGuardableTest.php
@@ -2,10 +2,11 @@
include dirname(__FILE__) . '/../bootstrap/doctrine.php';
-$t = new lime_test(26, new lime_output_color);
+$t = new lime_test(29, new lime_output_color);
$user1 = Doctrine::getTable('sfObjectGuardUser')->findOneByEmail('ever.zet@gmail.com');
$user2 = Doctrine::getTable('sfObjectGuardUser')->findOneByEmail('everzet@gmail.com');
+$user3 = Doctrine::getTable('sfObjectGuardUser')->findOneByEmail('cred_test2@tester.com');
$sfObjectGuardTest = Doctrine::getTable('sfObjectGuardTest')->findOneByName('test');
$sfObjectGuardTest2 = Doctrine::getTable('sfObjectGuardTest')->findOneByName('test2');
$participantGroup = Doctrine::getTable('sfObjectGuardGroup')->findOneByName('participant');
@@ -119,6 +120,21 @@
$t->is($sfObjectGuardTest->isUserInGroup($user1, $participantGroup), false, 'User "is not participant"');
$t->is($sfObjectGuardTest->isUserInGroup($user1, $participantGroup), false, 'User "is not moderator"');
+$user3->Groups[] = $moderatorGroup;
+$user3->save();
+
+$t->comment('Global rights');
+$usr = sfContext::getInstance()->getUser();
+$usr->signIn($user3);
+$t->ok(!$usr->hasCredential('global/add_publication'), 'Has not global rule to add publication');
+$t->ok($usr->hasCredential('global/dismiss_user'), 'Global rule to edit publication');
+
+$user3->Groups[] = $participantGroup;
+$user3->save();
+$usr->clearCredentials();
+
+$t->ok($usr->hasCredential('global/add_publication'), 'Now has global rule to add publication');
+
function getUsersCountInGroup(sfObjectGuardUser $user1, sfObjectGuardGroup $group, sfObjectGuardTest $com)
{
return Doctrine_Query::create()->

0 comments on commit 9dc54b4

Please sign in to comment.
Something went wrong with that request. Please try again.