diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/Psecio/Gatekeeper/GroupModel.php | 15 | ||||
-rw-r--r-- | src/Psecio/Gatekeeper/PermissionModel.php | 15 | ||||
-rw-r--r-- | src/Psecio/Gatekeeper/PolicyCollection.php | 2 | ||||
-rw-r--r-- | src/Psecio/Gatekeeper/UserGroupModel.php | 5 | ||||
-rw-r--r-- | src/Psecio/Gatekeeper/UserModel.php | 21 | ||||
-rw-r--r-- | src/Psecio/Gatekeeper/UserPermissionCollection.php | 3 | ||||
-rw-r--r-- | src/Psecio/Gatekeeper/UserPermissionModel.php | 5 |
7 files changed, 58 insertions, 8 deletions
diff --git a/src/Psecio/Gatekeeper/GroupModel.php b/src/Psecio/Gatekeeper/GroupModel.php index 899336b..3364339 100644 --- a/src/Psecio/Gatekeeper/GroupModel.php +++ b/src/Psecio/Gatekeeper/GroupModel.php @@ -30,6 +30,11 @@ class GroupModel extends \Psecio\Gatekeeper\Model\Mysql 'column' => 'name', 'type' => 'varchar' ), + 'expire' => array( + 'description' => 'Expiration Date', + 'column' => 'expire', + 'type' => 'datetime' + ), 'created' => array( 'description' => 'Date Created', 'column' => 'created', @@ -215,4 +220,14 @@ class GroupModel extends \Psecio\Gatekeeper\Model\Mysql ); return $this->getDb()->delete($childGroup); } + + /** + * Check to see if the group is expired + * + * @return boolean Expired/Not expired result + */ + public function isExpired() + { + return ($this->expire !== null && $this->expire <= time()); + } }
\ No newline at end of file diff --git a/src/Psecio/Gatekeeper/PermissionModel.php b/src/Psecio/Gatekeeper/PermissionModel.php index 89f79a8..3fb1db5 100644 --- a/src/Psecio/Gatekeeper/PermissionModel.php +++ b/src/Psecio/Gatekeeper/PermissionModel.php @@ -49,6 +49,11 @@ class PermissionModel extends \Psecio\Gatekeeper\Model\Mysql 'column' => 'updated', 'type' => 'datetime' ), + 'expire' => array( + 'description' => 'Expiration Date', + 'column' => 'expire', + 'type' => 'datetime' + ), 'children' => array( 'description' => 'Child Permissions', 'type' => 'relation', @@ -103,4 +108,14 @@ class PermissionModel extends \Psecio\Gatekeeper\Model\Mysql ); return $this->getDb()->delete($childPermission); } + + /** + * Test if the permission is expired + * + * @return boolean Expired/not expired + */ + public function isExpired() + { + return ($this->expire !== null && $this->expire <= time()); + } }
\ No newline at end of file diff --git a/src/Psecio/Gatekeeper/PolicyCollection.php b/src/Psecio/Gatekeeper/PolicyCollection.php index 8f390fe..87a22c8 100644 --- a/src/Psecio/Gatekeeper/PolicyCollection.php +++ b/src/Psecio/Gatekeeper/PolicyCollection.php @@ -18,7 +18,7 @@ class PolicyCollection extends \Psecio\Gatekeeper\Collection\Mysql $results = $this->getDb()->fetch($sql); foreach ($results as $result) { - $policy = new PolicyMoel($this->getDb(), $result); + $policy = new PolicyModel($this->getDb(), $result); $this->add($policy); } } diff --git a/src/Psecio/Gatekeeper/UserGroupModel.php b/src/Psecio/Gatekeeper/UserGroupModel.php index a8451b3..4c3269e 100644 --- a/src/Psecio/Gatekeeper/UserGroupModel.php +++ b/src/Psecio/Gatekeeper/UserGroupModel.php @@ -30,6 +30,11 @@ class UserGroupModel extends \Psecio\Gatekeeper\Model\Mysql 'column' => 'id', 'type' => 'integer' ), + 'expire' => array( + 'description' => 'Expiration Date', + 'column' => 'expire', + 'type' => 'datetime' + ), 'created' => array( 'description' => 'Date Created', 'column' => 'created', diff --git a/src/Psecio/Gatekeeper/UserModel.php b/src/Psecio/Gatekeeper/UserModel.php index a5ab7fa..9389fb2 100644 --- a/src/Psecio/Gatekeeper/UserModel.php +++ b/src/Psecio/Gatekeeper/UserModel.php @@ -187,16 +187,21 @@ class UserModel extends \Psecio\Gatekeeper\Model\Mysql * Attach a permission to a user account * * @param integer|PermissionModel $perm Permission ID or model isntance + * @param integer $expire Expiration time of the permission relationship */ - public function addPermission($perm) + public function addPermission($perm, $expire = null) { if ($perm instanceof PermissionModel) { $perm = $perm->id; } - $perm = new UserPermissionModel($this->getDb(), array( + $data = [ 'user_id' => $this->id, 'permission_id' => $perm - )); + ]; + if ($expire !== null && is_int($expire)) { + $data['expire'] = $expire; + } + $perm = new UserPermissionModel($this->getDb(), $data); return $this->getDb()->save($perm); } @@ -224,15 +229,19 @@ class UserModel extends \Psecio\Gatekeeper\Model\Mysql * @param integer|GroupModel $group Add the user to a group * @return boolean Success/fail of add */ - public function addGroup($group) + public function addGroup($group, $expire = null) { if ($group instanceof GroupModel) { $group = $group->id; } - $group = new UserGroupModel($this->getDb(), array( + $data = [ 'group_id' => $group, 'user_id' => $this->id - )); + ]; + if ($expire !== null && is_int($expire)) { + $data['expire'] = $expire; + } + $group = new UserGroupModel($this->getDb(), $data); return $this->getDb()->save($group); } diff --git a/src/Psecio/Gatekeeper/UserPermissionCollection.php b/src/Psecio/Gatekeeper/UserPermissionCollection.php index 0de1d6e..872aafe 100644 --- a/src/Psecio/Gatekeeper/UserPermissionCollection.php +++ b/src/Psecio/Gatekeeper/UserPermissionCollection.php @@ -15,7 +15,8 @@ class UserPermissionCollection extends \Psecio\Gatekeeper\Collection\Mysql $data = array('userId' => $userId); $sql = 'select p.* from '.$prefix.'permissions p, '.$prefix.'user_permission up' .' where p.id = up.permission_id' - .' and up.user_id = :userId'; + .' and up.user_id = :userId' + .' and (up.expire >= UNIX_TIMESTAMP(NOW()) or up.expire is null)'; $results = $this->getDb()->fetch($sql, $data); diff --git a/src/Psecio/Gatekeeper/UserPermissionModel.php b/src/Psecio/Gatekeeper/UserPermissionModel.php index 5bb769f..ca5051a 100644 --- a/src/Psecio/Gatekeeper/UserPermissionModel.php +++ b/src/Psecio/Gatekeeper/UserPermissionModel.php @@ -30,6 +30,11 @@ class UserPermissionModel extends \Psecio\Gatekeeper\Model\Mysql 'column' => 'id', 'type' => 'integer' ), + 'expire' => array( + 'description' => 'Expiration Date', + 'column' => 'expire', + 'type' => 'datetime' + ), 'created' => array( 'description' => 'Date Created', 'column' => 'created', |