From 4271f7702a2754d8470949209f2db82990eb2d1a Mon Sep 17 00:00:00 2001
From: Bharat Mediratta
Date: Sat, 29 Nov 2008 22:47:15 +0000
Subject: Add access model (not fully baked yet). Update scaffolding to allow
addition of just albums (helpful for testing permissions)
---
core/controllers/welcome.php | 14 ++++++++------
core/helpers/core_installer.php | 19 ++++++++++++++-----
core/models/access.php | 21 +++++++++++++++++++++
core/views/welcome.html.php | 15 +++++++++++++++
4 files changed, 58 insertions(+), 11 deletions(-)
create mode 100644 core/models/access.php
(limited to 'core')
diff --git a/core/controllers/welcome.php b/core/controllers/welcome.php
index 5cf6d7bf..b6c4f381 100644
--- a/core/controllers/welcome.php
+++ b/core/controllers/welcome.php
@@ -162,7 +162,7 @@ class Welcome_Controller extends Template_Controller {
url::redirect("welcome");
}
- function add_albums_and_photos($count) {
+ function add_albums_and_photos($count, $desired_type=null) {
srand(time());
$parents = ORM::factory("item")->where("type", "album")->find_all()->as_array();
@@ -174,8 +174,14 @@ class Welcome_Controller extends Template_Controller {
}
for ($i = 0; $i < $count; $i++) {
+ set_time_limit(30);
+
$parent = $parents[array_rand($parents)];
- if (!rand(0, 10)) {
+ $type = $desired_type;
+ if (!$type) {
+ $type = rand(0, 10) ? "photo" : "album";
+ }
+ if ($type == "album") {
$parents[] = album::create(
$parent->id, "rnd_" . rand(), "Rnd $i", "random album $i", $owner_id)
->set_thumbnail(DOCROOT . "core/tests/test.jpg", 200, 150)
@@ -184,10 +190,6 @@ class Welcome_Controller extends Template_Controller {
photo::create($parent->id, DOCROOT . "themes/default/images/thumbnail.jpg",
"thumbnail.jpg", "rnd_" . rand(), "sample thumbnail", $owner_id);
}
-
- if (!($i % 100)) {
- set_time_limit(30);
- }
}
url::redirect("welcome");
}
diff --git a/core/helpers/core_installer.php b/core/helpers/core_installer.php
index 1066b08c..792798ea 100644
--- a/core/helpers/core_installer.php
+++ b/core/helpers/core_installer.php
@@ -31,12 +31,12 @@ class core_installer {
}
if ($version == 0) {
- $db->query("CREATE TABLE `modules` (
+ $db->query("CREATE TABLE `access` (
`id` int(9) NOT NULL auto_increment,
- `name` char(255) default NULL,
- `version` int(9) default NULL,
- PRIMARY KEY (`id`),
- UNIQUE KEY(`name`))
+ `item_id` int(9),
+ `group_id` int(9) NOT NULL,
+ `perm` char(255) default NULL,
+ PRIMARY KEY (`id`))
ENGINE=InnoDB DEFAULT CHARSET=utf8;");
$db->query("CREATE TABLE `items` (
@@ -62,6 +62,14 @@ class core_installer {
KEY `type` (`type`))
ENGINE=InnoDB DEFAULT CHARSET=utf8;");
+ $db->query("CREATE TABLE `modules` (
+ `id` int(9) NOT NULL auto_increment,
+ `name` char(255) default NULL,
+ `version` int(9) default NULL,
+ PRIMARY KEY (`id`),
+ UNIQUE KEY(`name`))
+ ENGINE=InnoDB DEFAULT CHARSET=utf8;");
+
foreach (array("albums", "resizes") as $dir) {
@mkdir(VARPATH . $dir);
}
@@ -83,6 +91,7 @@ class core_installer {
public static function uninstall() {
$db = Database::instance();
+ $db->query("DROP TABLE IF EXISTS `access`;");
$db->query("DROP TABLE IF EXISTS `items`;");
$db->query("DROP TABLE IF EXISTS `modules`;");
system("/bin/rm -rf " . VARPATH . "albums");
diff --git a/core/models/access.php b/core/models/access.php
new file mode 100644
index 00000000..f85e152d
--- /dev/null
+++ b/core/models/access.php
@@ -0,0 +1,21 @@
+
] photos and albums
+
+ add: [
+ foreach (array(1, 10, 50, 100, 500, 1000) as $count): ?>
+ = html::anchor("welcome/add_albums_and_photos/$count/album", "$count") ?>
+ endforeach ?>
+ ] albums only
+
add: [
foreach (array(1, 10, 50, 100, 500, 1000) as $count): ?>
@@ -328,6 +335,14 @@
-
= html::anchor("albums/{$current->album->id}", $current->album->title) ?>
+ foreach (ORM::factory("item")->list_fields("items") as $field => $info): ?>
+ if (!strncmp($field, "view_", 5)): ?>
+ [= $field ?>== $current->album->$field ?>]
+ endif ?>
+ endforeach ?>
+ foreach (ORM::factory("access")->where("item_id", $current->album->id)->find() as $access): ?>
+ [ = $access->id ?> ]
+ endforeach ?>
$stack[] = "CLOSE"; ?>
if ($current->children): ?>
$stack = array_merge($stack, $current->children) ?>
--
cgit v1.2.3