From ae568b6182544b84067aa099eec494da477d083f Mon Sep 17 00:00:00 2001 From: Tim Almdal Date: Fri, 22 Jan 2010 12:09:11 -0800 Subject: Refactor the identity provider installation in to a common helper method (change_provider) with an initialization callback. --- modules/gallery/libraries/IdentityProvider.php | 29 ++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'modules/gallery/libraries') diff --git a/modules/gallery/libraries/IdentityProvider.php b/modules/gallery/libraries/IdentityProvider.php index bcb3056a..f7be33e3 100644 --- a/modules/gallery/libraries/IdentityProvider.php +++ b/modules/gallery/libraries/IdentityProvider.php @@ -57,6 +57,35 @@ class IdentityProvider_Core { Kohana_Config::instance()->clear("identity"); } + /** + * 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); + } + + 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(); + } + /** * Loads the configured driver and validates it. * -- cgit v1.2.3 From eabeeeb1267e0c925b5f31b2455a080bc2e9f237 Mon Sep 17 00:00:00 2001 From: Tim Almdal Date: Fri, 22 Jan 2010 13:38:05 -0800 Subject: Trap any errors that may occur when trying to install a new identity provider and then reinstall the current one. --- modules/gallery/controllers/admin_modules.php | 31 +++++++++++--------- modules/gallery/libraries/IdentityProvider.php | 40 ++++++++++++++++++-------- 2 files changed, 45 insertions(+), 26 deletions(-) (limited to 'modules/gallery/libraries') diff --git a/modules/gallery/controllers/admin_modules.php b/modules/gallery/controllers/admin_modules.php index a2168280..84fee25d 100644 --- a/modules/gallery/controllers/admin_modules.php +++ b/modules/gallery/controllers/admin_modules.php @@ -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/libraries/IdentityProvider.php b/modules/gallery/libraries/IdentityProvider.php index f7be33e3..e07838d1 100644 --- a/modules/gallery/libraries/IdentityProvider.php +++ b/modules/gallery/libraries/IdentityProvider.php @@ -71,19 +71,35 @@ class IdentityProvider_Core { module::uninstall($current_provider); } - 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"); + 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; } - - module::event("identity_provider_changed", $current_provider, $new_provider); - - auth::login($provider->admin_user()); - Session::instance()->regenerate(); } /** -- cgit v1.2.3 From abdeb21ccbb25aee564335dbbfca4a8afaf49384 Mon Sep 17 00:00:00 2001 From: Tim Almdal Date: Sat, 23 Jan 2010 13:29:49 -0800 Subject: Add a user_menu method to the Admin_View and then use this method to get the user menu. Since the information displayed is identical in both admin and theme views, it makes sense to combine the generation to it is done in a common location. --- modules/gallery/helpers/gallery_event.php | 3 +-- modules/gallery/libraries/Admin_View.php | 10 ++++++++++ themes/admin_wind/css/screen.css | 5 +++++ themes/admin_wind/views/admin.html.php | 15 +-------------- 4 files changed, 17 insertions(+), 16 deletions(-) (limited to 'modules/gallery/libraries') diff --git a/modules/gallery/helpers/gallery_event.php b/modules/gallery/helpers/gallery_event.php index 982bf094..6175e049 100644 --- a/modules/gallery/helpers/gallery_event.php +++ b/modules/gallery/helpers/gallery_event.php @@ -111,12 +111,11 @@ class gallery_event_Core { ->label(t("Login"))); } else { $csrf = access::csrf_token(); - $item = $theme->item(); $menu->append(Menu::factory("dialog") ->id("user_menu_edit_profile") ->css_id("g-user-profile-link") ->view("login_current_user.html") - ->url(url::site("form/edit/users/{$user->id}")) + ->url(url::site("form/edit/user/{$user->id}")) ->label($user->display_name())); $menu->append(Menu::factory("link") ->id("user_menu_logout") diff --git a/modules/gallery/libraries/Admin_View.php b/modules/gallery/libraries/Admin_View.php index a990e4ca..e3f9dff0 100644 --- a/modules/gallery/libraries/Admin_View.php +++ b/modules/gallery/libraries/Admin_View.php @@ -36,6 +36,8 @@ class Admin_View_Core extends Gallery_View { $this->sidebar = ""; $this->set_global("theme", $this); $this->set_global("user", identity::active_user()); + $this->set_global("page_type", "admin"); + $this->set_global("page_subtype", $name); } public function admin_menu() { @@ -44,6 +46,14 @@ class Admin_View_Core extends Gallery_View { return $menu->render(); } + public function user_menu() { + $menu = Menu::factory("root") + ->css_id("g-login-menu") + ->css_class("g-inline ui-helper-clear-fix"); + module::event("user_menu", $menu, $this); + return $menu->render(); + } + /** * Print out any site wide status information. */ diff --git a/themes/admin_wind/css/screen.css b/themes/admin_wind/css/screen.css index 73ec8ac5..ac47a3db 100644 --- a/themes/admin_wind/css/screen.css +++ b/themes/admin_wind/css/screen.css @@ -229,6 +229,7 @@ th { #g-header #g-login-menu { margin-top: 1em; + float: right; } /* View container ~~~~~~~~~~~~~~~~~~~~~~~~ */ @@ -473,6 +474,10 @@ th { right: 150px; } +.rtl #g-header #g-login-menu { + float: left; +} + .rtl #g-header #g-login-menu li { margin-left: 0; padding-left: 0; diff --git a/themes/admin_wind/views/admin.html.php b/themes/admin_wind/views/admin.html.php index 25ba1c97..fa79119a 100644 --- a/themes/admin_wind/views/admin.html.php +++ b/themes/admin_wind/views/admin.html.php @@ -43,23 +43,10 @@ site_status() ?>
admin_header_top() ?> - + user_menu() ?>
admin_menu() ?>
-- cgit v1.2.3