summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChris Cornutt <enygma@phpdeveloper.org>2015-07-02 20:43:47 -0500
committerChris Cornutt <enygma@phpdeveloper.org>2015-07-02 20:43:47 -0500
commitc01b19f506c2819199f55ec710a5e3748d27fd6c (patch)
tree125b5f6effb0e2e9689a3163c880631af98e48f0
parent7727fbab2c7d73a92a665c013ce76fb43487449b (diff)
downloadgatekeeper-c01b19f506c2819199f55ec710a5e3748d27fd6c.zip
gatekeeper-c01b19f506c2819199f55ec710a5e3748d27fd6c.tar.gz
gatekeeper-c01b19f506c2819199f55ec710a5e3748d27fd6c.tar.bz2
adding expiration to permissions, updating docs
-rw-r--r--docs/permissions.md25
-rw-r--r--src/Psecio/Gatekeeper/PermissionModel.php15
2 files changed, 39 insertions, 1 deletions
diff --git a/docs/permissions.md b/docs/permissions.md
index 682c222..b7820cb 100644
--- a/docs/permissions.md
+++ b/docs/permissions.md
@@ -25,6 +25,29 @@ if (Gatekeeper::createPermission($perm) === true) {
?>
```
+You can also set an expiration date on your permissions using the `expire` property:
+
+```php
+<?php
+$perm = [
+ 'name' => 'perm1',
+ 'description' => 'Permission #1',
+ 'expire' => strtotime('+1 day')
+];
+?>
+```
+
+These values are stored as Unix timestamps on the permission records themselves. This will cause the permission to exire, **not** the permission to no longer be allowed for a user (that's in the user-to-permission relationship). You can also check to see if a permission is expired with the `isExpired` method:
+
+```php
+<?php
+$permission = Gatekeeper::findPermissionById(1);
+if ($permission->isExpired() === true) {
+ echo 'Oh noes, the permission expired!';
+}
+?>
+```
+
## Adding Child Permissions
Much like groups, permissions also support the concept of children. Adding a permission as a child to a parent is easy and can be done in one of two ways:
@@ -41,7 +64,7 @@ $permission->addChild($permission);
?>
```
-### Removing Child Permissions
+## Removing Child Permissions
You can also remove child permissions in a similar way:
diff --git a/src/Psecio/Gatekeeper/PermissionModel.php b/src/Psecio/Gatekeeper/PermissionModel.php
index 89f79a8..da9a04f 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