summaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
Diffstat (limited to 'modules')
-rw-r--r--modules/comment/helpers/comment_event.php18
-rw-r--r--modules/gallery/controllers/admin_identity.php76
-rw-r--r--modules/gallery/controllers/admin_modules.php33
-rw-r--r--modules/gallery/helpers/gallery_event.php38
-rw-r--r--modules/gallery/helpers/module.php8
-rw-r--r--modules/gallery/libraries/IdentityProvider.php45
-rw-r--r--modules/gallery/views/admin_identity.html.php59
-rw-r--r--modules/gallery/views/admin_identity_confirm.html.php10
-rw-r--r--modules/gallery/views/admin_modules.html.php3
-rw-r--r--modules/slideshow/helpers/slideshow_installer.php2
-rw-r--r--modules/user/helpers/user_installer.php72
-rw-r--r--modules/user/module.info2
12 files changed, 132 insertions, 234 deletions
diff --git a/modules/comment/helpers/comment_event.php b/modules/comment/helpers/comment_event.php
index 43a30d70..bd336cda 100644
--- a/modules/comment/helpers/comment_event.php
+++ b/modules/comment/helpers/comment_event.php
@@ -27,14 +27,16 @@ class comment_event_Core {
static function user_deleted($user) {
$guest = identity::guest();
- db::build()
- ->update("comments")
- ->set("author_id", $guest->id)
- ->set("guest_email", null)
- ->set("guest_name", "guest")
- ->set("guest_url", null)
- ->where("author_id", "=", $user->id)
- ->execute();
+ if (!empty($guest)) { // could be empty if there is not identity provider
+ db::build()
+ ->update("comments")
+ ->set("author_id", $guest->id)
+ ->set("guest_email", null)
+ ->set("guest_name", "guest")
+ ->set("guest_url", null)
+ ->where("author_id", "=", $user->id)
+ ->execute();
+ }
}
static function identity_provider_changed($old_provider, $new_provider) {
diff --git a/modules/gallery/controllers/admin_identity.php b/modules/gallery/controllers/admin_identity.php
deleted file mode 100644
index 354e6c0c..00000000
--- a/modules/gallery/controllers/admin_identity.php
+++ /dev/null
@@ -1,76 +0,0 @@
-<?php defined("SYSPATH") or die("No direct script access.");
-/**
- * Gallery - a web based photo album viewer and editor
- * Copyright (C) 2000-2009 Bharat Mediratta
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or (at
- * your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
- */
-class Admin_Identity_Controller extends Admin_Controller {
- public function index() {
- $view = new Admin_View("admin.html");
- $view->content = new View("admin_identity.html");
- $view->content->available = identity::providers();
- $view->content->active = module::get_var("gallery", "identity_provider", "user");
- print $view;
- }
-
- public function confirm() {
- access::verify_csrf();
-
- $v = new View("admin_identity_confirm.html");
- $v->new_provider = Input::instance()->post("provider");
-
- print $v;
- }
-
- public function change() {
- access::verify_csrf();
-
- $active_provider = module::get_var("gallery", "identity_provider", "user");
- $providers = identity::providers();
- $new_provider = Input::instance()->post("provider");
-
- if ($new_provider != $active_provider) {
-
- module::deactivate($active_provider);
-
- // Switch authentication
- identity::reset();
- module::set_var("gallery", "identity_provider", $new_provider);
-
- module::install($new_provider);
- module::activate($new_provider);
-
- module::event("identity_provider_changed", $active_provider, $new_provider);
-
- module::uninstall($active_provider);
-
- message::success(t("Changed to %description",
- array("description" => $providers->$new_provider)));
-
- try {
- Session::instance()->destroy();
- } catch (Exception $e) {
- // We don't care if there was a problem destroying the session.
- }
- url::redirect(item::root()->abs_url());
- }
-
- message::info(t("The selected provider \"%description\" is already active.",
- array("description" => $providers->$new_provider)));
- url::redirect("admin/identity");
- }
-}
-
diff --git a/modules/gallery/controllers/admin_modules.php b/modules/gallery/controllers/admin_modules.php
index 46defbef..84fee25d 100644
--- a/modules/gallery/controllers/admin_modules.php
+++ b/modules/gallery/controllers/admin_modules.php
@@ -42,7 +42,7 @@ class Admin_Modules_Controller extends Admin_Controller {
if ($info->active && !$desired && module::is_active($module_name)) {
$messages = array_merge($messages, module::can_deactivate($module_name));
} else if (!$info->active && $desired && !module::is_active($module_name)) {
- $messages = array_merge($messages, module::check_environment($module_name));
+ $messages = array_merge($messages, module::can_activate($module_name));
}
}
@@ -76,21 +76,24 @@ class Admin_Modules_Controller extends Admin_Controller {
continue;
}
- $desired = Input::instance()->post($module_name) == 1;
- if ($info->active && !$desired && module::is_active($module_name)) {
- $changes->deactivate[] = $module_name;
- $deactivated_names[] = t($info->name);
- module::deactivate($module_name);
- } else if (!$info->active && $desired && !module::is_active($module_name)) {
- $changes->activate[] = $module_name;
- $activated_names[] = t($info->name);
-
- if (module::is_installed($module_name)) {
- module::upgrade($module_name);
- } else {
- module::install($module_name);
+ try {
+ $desired = Input::instance()->post($module_name) == 1;
+ if ($info->active && !$desired && module::is_active($module_name)) {
+ module::deactivate($module_name);
+ $changes->deactivate[] = $module_name;
+ $deactivated_names[] = t($info->name);
+ } else if (!$info->active && $desired && !module::is_active($module_name)) {
+ if (module::is_installed($module_name)) {
+ module::upgrade($module_name);
+ } else {
+ module::install($module_name);
+ }
+ module::activate($module_name);
+ $changes->activate[] = $module_name;
+ $activated_names[] = t($info->name);
}
- module::activate($module_name);
+ } catch (Exception $e) {
+ Kohana_Log::add("error", (string)$e);
}
}
diff --git a/modules/gallery/helpers/gallery_event.php b/modules/gallery/helpers/gallery_event.php
index b39be169..982bf094 100644
--- a/modules/gallery/helpers/gallery_event.php
+++ b/modules/gallery/helpers/gallery_event.php
@@ -30,21 +30,23 @@ class gallery_event_Core {
static function user_deleted($user) {
$admin = identity::admin_user();
- db::build()
- ->update("tasks")
- ->set("owner_id", $admin->id)
- ->where("owner_id", "=", $user->id)
- ->execute();
- db::build()
- ->update("items")
- ->set("owner_id", $admin->id)
- ->where("owner_id", "=", $user->id)
- ->execute();
- db::build()
- ->update("logs")
- ->set("user_id", $admin->id)
- ->where("user_id", "=", $user->id)
- ->execute();
+ if (!empty($admin)) { // could be empty if there is not identity provider
+ db::build()
+ ->update("tasks")
+ ->set("owner_id", $admin->id)
+ ->where("owner_id", "=", $user->id)
+ ->execute();
+ db::build()
+ ->update("items")
+ ->set("owner_id", $admin->id)
+ ->where("owner_id", "=", $user->id)
+ ->execute();
+ db::build()
+ ->update("logs")
+ ->set("user_id", $admin->id)
+ ->where("user_id", "=", $user->id)
+ ->execute();
+ }
}
static function identity_provider_changed($old_provider, $new_provider) {
@@ -228,11 +230,7 @@ class gallery_event_Core {
->append(Menu::factory("link")
->id("advanced")
->label(t("Advanced"))
- ->url(url::site("admin/advanced_settings")))
- ->append(Menu::factory("link")
- ->id("authentication")
- ->label(t("Authentication"))
- ->url(url::site("admin/identity"))))
+ ->url(url::site("admin/advanced_settings"))))
->append(Menu::factory("link")
->id("modules")
->label(t("Modules"))
diff --git a/modules/gallery/helpers/module.php b/modules/gallery/helpers/module.php
index 595f600b..f680ff6a 100644
--- a/modules/gallery/helpers/module.php
+++ b/modules/gallery/helpers/module.php
@@ -120,17 +120,17 @@ class module_Core {
}
/**
- * Check that the module can be installed. (i.e. all the prerequistes exist)
+ * Check that the module can be activated. (i.e. all the prerequistes exist)
* @param string $module_name
* @return array an array of warning or error messages to be displayed
*/
- static function check_environment($module_name) {
+ static function can_activate($module_name) {
module::_add_to_path($module_name);
$messages = array();
$installer_class = "{$module_name}_installer";
- if (method_exists($installer_class, "check_environment")) {
- $messages = call_user_func(array($installer_class, "check_environment"));
+ if (method_exists($installer_class, "can_activate")) {
+ $messages = call_user_func(array($installer_class, "can_activate"));
}
// Remove it from the active path
diff --git a/modules/gallery/libraries/IdentityProvider.php b/modules/gallery/libraries/IdentityProvider.php
index bcb3056a..e07838d1 100644
--- a/modules/gallery/libraries/IdentityProvider.php
+++ b/modules/gallery/libraries/IdentityProvider.php
@@ -58,6 +58,51 @@ class IdentityProvider_Core {
}
/**
+ * Return a commen confirmation message
+ */
+ static function confirmation_message() {
+ return t("Are you sure you want to change your Identity Provider? " .
+ "Continuing will delete all existing users.");
+ }
+
+ static function change_provider($new_provider) {
+ $current_provider = module::get_var("gallery", "identity_provider");
+ if (!empty($current_provider)) {
+ module::uninstall($current_provider);
+ }
+
+ try {
+ IdentityProvider::reset();
+ $provider = new IdentityProvider($new_provider);
+
+ module::set_var("gallery", "identity_provider", $new_provider);
+
+ if (method_exists("{$new_provider}_installer", "initialize")) {
+ call_user_func("{$new_provider}_installer::initialize");
+ }
+
+ module::event("identity_provider_changed", $current_provider, $new_provider);
+
+ auth::login($provider->admin_user());
+ Session::instance()->regenerate();
+ } catch (Exception $e) {
+ // Make sure new provider is not in the database
+ module::uninstall($new_provider);
+
+ // Lets reset to the current provider so that the gallery installation is still
+ // working.
+ module::set_var("gallery", "identity_provider", null);
+ IdentityProvider::change_provider($current_provider);
+ module::activate($current_provider);
+ message::error(
+ t("Error attempting to enable \"%new_provider\" identity provider, " .
+ "reverted to \"%old_provider\" identity provider",
+ array("new_provider" => $new_provider, "old_provider" => $current_provider)));
+ throw $e;
+ }
+ }
+
+ /**
* Loads the configured driver and validates it.
*
* @return void
diff --git a/modules/gallery/views/admin_identity.html.php b/modules/gallery/views/admin_identity.html.php
deleted file mode 100644
index 51eaa58a..00000000
--- a/modules/gallery/views/admin_identity.html.php
+++ /dev/null
@@ -1,59 +0,0 @@
-<?php defined("SYSPATH") or die("No direct script access.") ?>
-<script type="text/javascript">
- $(document).ready(function() {
- $("#g-modules form").submit(function() {
- var eDialog = '<div id="g-dialog"></div>';
- var params = $(this).serialize();
- var url = $(this).attr("action");
- $("body").append(eDialog);
- $.post($(this).attr("action"), $(this).serialize(), function(data, textStatus) {
- $("#g-dialog").html(data);
- $("#g-dialog").dialog({
- bgiframe: true,
- title: <?= t("Confirm identity provider change")->for_js() ?>,
- resizable: false,
- height:180,
- modal: true,
- overlay: {
- backgroundColor: '#000',
- opacity: 0.5
- },
- buttons: {
- "Continue": function() {
- $("#g-dialog form").submit();
- },
- Cancel: function() {
- $(this).dialog('destroy').remove();
- }
- }
- });
- });
- return false;
- });
- });
-
-</script>
-<div id="g-modules">
- <h1> <?= t("Manage identity providers") ?> </h1>
- <p>
- <?= t("Choose a different user/group management provider.") ?>
- </p>
-
- <form method="post" action="<?= url::site("admin/identity/confirm") ?>">
- <?= access::csrf_form_field() ?>
- <table>
- <tr>
- <th> <?= t("Active") ?> </th>
- <th> <?= t("Description") ?> </th>
- </tr>
- <? foreach ($available as $module_name => $description): ?>
- <tr class="<?= text::alternate("g-odd", "g-even") ?>">
- <? $data = array("name" => "provider"); ?>
- <td> <?= form::radio($data, $module_name, $module_name == $active) ?> </td>
- <td> <?= t($description) ?> </td>
- </tr>
- <? endforeach ?>
- </table>
- <input type="submit" value="<?= t("Change")->for_html_attr() ?>" />
- </form>
-</div>
diff --git a/modules/gallery/views/admin_identity_confirm.html.php b/modules/gallery/views/admin_identity_confirm.html.php
deleted file mode 100644
index 54aae9c8..00000000
--- a/modules/gallery/views/admin_identity_confirm.html.php
+++ /dev/null
@@ -1,10 +0,0 @@
-<?php defined("SYSPATH") or die("No direct script access.") ?>
-<form method="post" action="<?= url::site("admin/identity/change") ?>">
- <?= access::csrf_form_field() ?>
- <?= form::hidden("provider", $new_provider) ?>
-
- <p><span class="ui-icon ui-icon-alert" style="float: left; margin:0 7px 20px 0;"></span>
- <?= t("Are you sure you want to change your Identity Provider? Continuing will delete all existing users.") ?>
- </p>
-</form>
-
diff --git a/modules/gallery/views/admin_modules.html.php b/modules/gallery/views/admin_modules.html.php
index 704e7beb..a021d969 100644
--- a/modules/gallery/views/admin_modules.html.php
+++ b/modules/gallery/views/admin_modules.html.php
@@ -22,6 +22,9 @@
buttons: {
<?= t("Continue")->for_js() ?>: function() {
$("form", this).submit();
+ $(".ui-dialog-buttonpane button:contains(Continue)")
+ .attr("disabled", "disabled")
+ .addClass("ui-state-disabled");
},
<?= t("Cancel")->for_js() ?>: function() {
$(this).dialog("destroy").remove();
diff --git a/modules/slideshow/helpers/slideshow_installer.php b/modules/slideshow/helpers/slideshow_installer.php
index 319e2e79..8d612f3e 100644
--- a/modules/slideshow/helpers/slideshow_installer.php
+++ b/modules/slideshow/helpers/slideshow_installer.php
@@ -34,7 +34,7 @@ class slideshow_installer {
site_status::clear("slideshow_needs_rss");
}
- static function check_environment() {
+ static function can_activate() {
$messages = array();
if (!module::is_active("rss")) {
$messages["warn"][] = t("The Slideshow module requires the RSS module.");
diff --git a/modules/user/helpers/user_installer.php b/modules/user/helpers/user_installer.php
index 0cba502f..38f8020b 100644
--- a/modules/user/helpers/user_installer.php
+++ b/modules/user/helpers/user_installer.php
@@ -18,7 +18,39 @@
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
*/
class user_installer {
+ static function can_activate() {
+ return array("warn" => array(IdentityProvider::confirmation_message()));
+ }
+
static function install() {
+ IdentityProvider::change_provider("user");
+ }
+
+ static function upgrade($version) {
+ if ($version == 1) {
+ module::set_var("user", "mininum_password_length", 5);
+
+ module::set_version("user", $version = 2);
+ }
+ }
+
+ static function uninstall() {
+ // Delete all users and groups so that we give other modules an opportunity to clean up
+ foreach (ORM::factory("user")->find_all() as $user) {
+ $user->delete();
+ }
+
+ foreach (ORM::factory("group")->find_all() as $group) {
+ $group->delete();
+ }
+
+ $db = Database::instance();
+ $db->query("DROP TABLE IF EXISTS {users};");
+ $db->query("DROP TABLE IF EXISTS {groups};");
+ $db->query("DROP TABLE IF EXISTS {groups_users};");
+ }
+
+ static function initialize() {
$db = Database::instance();
$db->query("CREATE TABLE IF NOT EXISTS {users} (
`id` int(9) NOT NULL auto_increment,
@@ -70,19 +102,6 @@ class user_installer {
$admin->admin = true;
$admin->save();
- $current_provider = module::get_var("gallery", "identity_provider");
- if (empty($current_provider)) {
- // If there is no provider defined then we are doing an initial install
- // so we need to set the provider and make the administrator own everything
- // If the installer is called and there is an identity provider, then we
- // are switching identity providers and and the event handlers will do the
- // right things
- module::set_var("gallery", "identity_provider", "user");
-
- // Let the admin own everything
- $db->query("update {items} set owner_id = {$admin->id}");
- }
-
$root = ORM::factory("item", 1);
access::allow($everybody, "view", $root);
access::allow($everybody, "view_full", $root);
@@ -90,32 +109,7 @@ class user_installer {
access::allow($registered, "view", $root);
access::allow($registered, "view_full", $root);
- module::set_var("user", "mininum_password_length", 5);
-
module::set_version("user", 2);
- }
-
- static function upgrade($version) {
- if ($version == 1) {
- module::set_var("user", "mininum_password_length", 5);
-
- module::set_version("user", $version = 2);
- }
- }
-
- static function uninstall() {
- // Delete all users and groups so that we give other modules an opportunity to clean up
- foreach (ORM::factory("user")->find_all() as $user) {
- $user->delete();
- }
-
- foreach (ORM::factory("group")->find_all() as $group) {
- $group->delete();
- }
-
- $db = Database::instance();
- $db->query("DROP TABLE IF EXISTS {users};");
- $db->query("DROP TABLE IF EXISTS {groups};");
- $db->query("DROP TABLE IF EXISTS {groups_users};");
+ module::set_var("user", "mininum_password_length", 5);
}
} \ No newline at end of file
diff --git a/modules/user/module.info b/modules/user/module.info
index 7178f108..d1e02382 100644
--- a/modules/user/module.info
+++ b/modules/user/module.info
@@ -2,5 +2,3 @@ name = "Users and Groups"
description = "Gallery 3 user and group management"
version = 2
-; Don't show this module on the module administration screen
-no_module_admin = 1