Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Use BOOLEAN instead of integer to describe the permissions :

 - DENY = false
 - ALLOW = true
 - UNKNOW = null  (for intent only)
 - INHERIT = null (for cache)

Upgrade is not included for now.
  • Loading branch information...
commit 719c59e0402464a0e2b14915f6d10218ff5d4729 1 parent c78744d
@rledisez authored
View
32 installer/install.sql
@@ -4,12 +4,12 @@ DROP TABLE IF EXISTS {access_caches};
CREATE TABLE {access_caches} (
`id` int(9) NOT NULL auto_increment,
`item_id` int(9) default NULL,
- `view_full_1` smallint(6) NOT NULL default '0',
- `edit_1` smallint(6) NOT NULL default '0',
- `add_1` smallint(6) NOT NULL default '0',
- `view_full_2` smallint(6) NOT NULL default '0',
- `edit_2` smallint(6) NOT NULL default '0',
- `add_2` smallint(6) NOT NULL default '0',
+ `view_full_1` binary(1) NOT NULL default false,
+ `edit_1` binary(1) NOT NULL default false,
+ `add_1` binary(1) NOT NULL default false,
+ `view_full_2` binary(1) NOT NULL default false,
+ `edit_2` binary(1) NOT NULL default false,
+ `add_2` binary(1) NOT NULL default false,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8;
/*!40101 SET character_set_client = @saved_cs_client */;
@@ -20,14 +20,14 @@ DROP TABLE IF EXISTS {access_intents};
CREATE TABLE {access_intents} (
`id` int(9) NOT NULL auto_increment,
`item_id` int(9) default NULL,
- `view_1` tinyint(1) default NULL,
- `view_full_1` tinyint(1) default NULL,
- `edit_1` tinyint(1) default NULL,
- `add_1` tinyint(1) default NULL,
- `view_2` tinyint(1) default NULL,
- `view_full_2` tinyint(1) default NULL,
- `edit_2` tinyint(1) default NULL,
- `add_2` tinyint(1) default NULL,
+ `view_1` binary(1) default NULL,
+ `view_full_1` binary(1) default NULL,
+ `edit_1` binary(1) default NULL,
+ `add_1` binary(1) default NULL,
+ `view_2` binary(1) default NULL,
+ `view_full_2` binary(1) default NULL,
+ `edit_2` binary(1) default NULL,
+ `add_2` binary(1) default NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8;
/*!40101 SET character_set_client = @saved_cs_client */;
@@ -164,8 +164,8 @@ CREATE TABLE {items} (
`view_count` int(9) default '0',
`weight` int(9) NOT NULL default '0',
`width` int(9) default NULL,
- `view_1` smallint(6) NOT NULL default '0',
- `view_2` smallint(6) NOT NULL default '0',
+ `view_1` binary(1) default false,
+ `view_2` binary(1) default false,
PRIMARY KEY (`id`),
KEY `parent_id` (`parent_id`),
KEY `type` (`type`),
View
31 modules/gallery/helpers/access.php
@@ -66,9 +66,10 @@
* the Access_Intent_Model
*/
class access_Core {
- const DENY = 0;
- const ALLOW = 1;
- const UNKNOWN = 2;
+ const DENY = false;
+ const ALLOW = true;
+ const INHERIT = null; // access_intent
+ const UNKNOWN = null; // cache (access_cache, items)
/**
* Does the active user have this permission on this item?
@@ -129,7 +130,7 @@ static function group_can($group, $perm_name, $item) {
* @param Group_Model $group
* @param string $perm_name
* @param Item_Model $item
- * @return integer access::ALLOW, access::DENY or null for no intent
+ * @return boolean access::ALLOW, access::DENY or access::INHERIT (null) for no intent
*/
static function group_intent($group, $perm_name, $item) {
$intent = model_cache::get("access_intent", $item->id, "item_id");
@@ -157,7 +158,7 @@ static function locked_by($group, $perm_name, $item) {
->where("`right` >= $item->right")
->where("items.id <> $item->id")
->join("access_intents", "items.id", "access_intents.item_id")
- ->where("access_intents.view_$group->id", 0)
+ ->where("access_intents.view_$group->id", access::DENY)
->orderby("level", "DESC")
->limit(1)
->find();
@@ -241,7 +242,7 @@ static function reset($group, $perm_name, $item) {
if ($item->id == 1) {
throw new Exception("@todo CANT_RESET_ROOT_PERMISSION");
}
- self::_set($group, $perm_name, $item, null);
+ self::_set($group, $perm_name, $item, access::INHERIT);
}
/**
@@ -443,9 +444,10 @@ private static function _add_columns($perm_name, $group) {
$db = Database::instance();
$field = "{$perm_name}_{$group->id}";
$cache_table = $perm_name == "view" ? "items" : "access_caches";
- $db->query("ALTER TABLE {{$cache_table}} ADD `$field` SMALLINT NOT NULL DEFAULT 0");
- $db->query("ALTER TABLE {access_intents} ADD `$field` BOOLEAN DEFAULT NULL");
- $db->update("access_intents", array($field => 0), array("item_id" => 1));
+ $not_null = $cache_table == "items" ? "" : "NOT NULL";
+ $db->query("ALTER TABLE {{$cache_table}} ADD `$field` BINARY $not_null DEFAULT FALSE");
+ $db->query("ALTER TABLE {access_intents} ADD `$field` BINARY DEFAULT NULL");
+ $db->update("access_intents", array($field => access::DENY), array("item_id" => 1));
model_cache::clear();
ORM::factory("access_intent")->clear_cache();
}
@@ -501,7 +503,7 @@ private static function _update_access_view_cache($group, $item) {
->where("left >=", $item->left)
->where("right <=", $item->right)
->where("type", "album")
- ->where("access_intents.$field IS NOT", null)
+ ->where("access_intents.$field IS NOT", self::INHERIT)
->orderby("level", "DESC")
->find_all();
foreach ($query as $row) {
@@ -545,12 +547,12 @@ private static function _update_access_non_view_cache($group, $perm_name, $item)
//
// @todo To optimize this, we wouldn't need to propagate from the parent, we could just
// propagate from here with the parent's intent.
- if ($access->$field === null) {
+ if ($access->$field === self::INHERIT) {
$tmp_item = ORM::factory("item")
->join("access_intents", "items.id", "access_intents.item_id")
->where("left <", $item->left)
->where("right >", $item->right)
- ->where("$field IS NOT", null)
+ ->where("$field IS NOT", self::UNKNOWN)
->orderby("left", "DESC")
->limit(1)
->find();
@@ -566,12 +568,13 @@ private static function _update_access_non_view_cache($group, $perm_name, $item)
->join("items", "items.id", "access_intents.item_id")
->where("left >=", $item->left)
->where("right <=", $item->right)
- ->where("$field IS NOT", null)
+ ->where("$field IS NOT", self::INHERIT)
->orderby("level", "ASC")
->find_all();
foreach ($query as $row) {
+ $value = ($row->$field === access::ALLOW) ? "TRUE" : "FALSE";
$db->query(
- "UPDATE {access_caches} SET `$field` = {$row->$field} " .
+ "UPDATE {access_caches} SET `$field` = $value " .
"WHERE `item_id` IN " .
" (SELECT `id` FROM {items} " .
" WHERE `left` >= $row->left " .
View
2  modules/gallery/views/permissions_form.html.php
@@ -26,7 +26,7 @@
</a>
</td>
<? else: ?>
- <? if ($intent === null): ?>
+ <? if ($intent === access::INHERIT): ?>
<? if ($allowed): ?>
<td class="gAllowed">
<a href="javascript:set('allow',<?= $group->id ?>,<?= $permission->id ?>,<?= $item->id ?>)"
View
2  modules/search/helpers/search.php
@@ -24,7 +24,7 @@ static function search($q, $limit, $offset) {
if (!user::active()->admin) {
foreach (user::group_ids() as $id) {
- $fields[] = "`view_$id` = " . access::ALLOW;
+ $fields[] = "`view_$id` = TRUE"; // access::ALLOW
}
$access_sql = "AND (" . join(" AND ", $fields) . ")";
} else {
View
4 system/libraries/drivers/Database.php
@@ -120,7 +120,7 @@ public function where($key, $value, $type, $num_wheres, $quote)
$key .= ' =';
}
- $value = ($value == TRUE) ? ' 1' : ' 0';
+ $value = ($value == TRUE) ? ' TRUE' : ' FALSE';
}
else
{
@@ -310,7 +310,7 @@ public function escape($value)
$value = '\''.$this->escape_str($value).'\'';
break;
case 'boolean':
- $value = (int) $value;
+ $value = ($value == TRUE) ? 'TRUE' : 'FALSE';
break;
case 'double':
// Convert to non-locale aware float to prevent possible commas
Please sign in to comment.
Something went wrong with that request. Please try again.