From 08c01fec6cc590eb578522164de81114b889c4b5 Mon Sep 17 00:00:00 2001 From: Tim Almdal Date: Mon, 5 Oct 2009 11:51:08 -0700 Subject: The initial commit of refactoring the user/group adminsitration into a driver. Create an Identity library that defines the interface the Gallery3 expects Move the user and group helpers into the gallery module to provide the familiar interface into the Identity library. Create a Gallery Identity back-end that is supplied by the user module. The vision here is that all user and group code that is gallery or ui specific is contained within the core product. Anything that relates to manipulating a user or group is contained in the back end code that can be replaced. --- modules/gallery/config/identity.php | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 modules/gallery/config/identity.php (limited to 'modules/gallery/config') diff --git a/modules/gallery/config/identity.php b/modules/gallery/config/identity.php new file mode 100644 index 00000000..f2064127 --- /dev/null +++ b/modules/gallery/config/identity.php @@ -0,0 +1,36 @@ + "gallery", + "params" => array(), +); -- cgit v1.2.3 From 03d0311618267cf0b16445161c4d275749d64a5e Mon Sep 17 00:00:00 2001 From: Tim Almdal Date: Wed, 7 Oct 2009 21:40:05 -0700 Subject: Implement a user::is_writable() API method and disable the user add, updates and display if the Identity driver does not support writes. This is set in the config.identity.php --- modules/gallery/config/identity.php | 3 +- modules/gallery/helpers/gallery_theme.php | 1 + modules/gallery/helpers/user.php | 39 ++++++++++++++++++++---- modules/gallery/libraries/Identity.php | 11 +++++++ modules/gallery/libraries/drivers/Identity.php | 1 - modules/gallery/views/admin_users.html.php | 36 ++++++++++++++-------- modules/gallery/views/admin_users_group.html.php | 4 +-- modules/gallery/views/login.html.php | 2 +- themes/admin_wind/css/screen.css | 3 +- 9 files changed, 75 insertions(+), 25 deletions(-) (limited to 'modules/gallery/config') diff --git a/modules/gallery/config/identity.php b/modules/gallery/config/identity.php index f2064127..72d1b589 100644 --- a/modules/gallery/config/identity.php +++ b/modules/gallery/config/identity.php @@ -18,7 +18,7 @@ * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ /* - * @package User + * @package Identity * * User settings, defined as arrays, or "groups". If no group name is * used when loading the cache library, the group named "default" will be used. @@ -32,5 +32,6 @@ */ $config["default"] = array ( "driver" => "gallery", + "allow_updates" => false, "params" => array(), ); diff --git a/modules/gallery/helpers/gallery_theme.php b/modules/gallery/helpers/gallery_theme.php index a342b4bd..54b35fb7 100644 --- a/modules/gallery/helpers/gallery_theme.php +++ b/modules/gallery/helpers/gallery_theme.php @@ -55,6 +55,7 @@ class gallery_theme_Core { if ($theme->page_type != "login") { $view = new View("login.html"); $view->user = user::active(); + $view->writable = user::is_writable(); return $view->render(); } } diff --git a/modules/gallery/helpers/user.php b/modules/gallery/helpers/user.php index abbf8ab0..e3494fdf 100644 --- a/modules/gallery/helpers/user.php +++ b/modules/gallery/helpers/user.php @@ -25,24 +25,34 @@ */ class user_Core { static function get_edit_form($user) { + $writable = self::is_writable(); $form = new Forge("users/update/$user->id", "", "post", array("id" => "g-edit-user-form")); $form->set_attr("class", "g-narrow"); $group = $form->group("edit_user")->label(t("Edit User: %name", array("name" => $user->name))); $group->input("full_name")->label(t("Full Name"))->id("g-fullname")->value($user->full_name); self::_add_locale_dropdown($group, $user); - $group->password("password")->label(t("Password"))->id("g-password"); - $group->password("password2")->label(t("Confirm Password"))->id("g-password2") - ->matches($group->password); + if ($writable) { + $group->password("password")->label(t("Password"))->id("g-password"); + $group->password("password2")->label(t("Confirm Password"))->id("g-password2") + ->matches($group->password); + } $group->input("email")->label(t("Email"))->id("g-email")->value($user->email); $group->input("url")->label(t("URL"))->id("g-url")->value($user->url); $form->add_rules_from(self::get_edit_rules()); module::event("user_edit_form", $user, $form); $group->submit("")->value(t("Save")); + + if (!$writable) { + foreach ($group->inputs as $input) { + $input->disabled("disabled"); + } + } return $form; } static function get_edit_form_admin($user) { + $writable = self::is_writable(); $form = new Forge( "admin/users/edit_user/$user->id", "", "post", array("id" => "g-edit-user-form")); $group = $form->group("edit_user")->label(t("Edit User")); @@ -51,9 +61,11 @@ class user_Core { "in_use", t("There is already a user with that username")); $group->input("full_name")->label(t("Full Name"))->id("g-fullname")->value($user->full_name); self::_add_locale_dropdown($group, $user); - $group->password("password")->label(t("Password"))->id("g-password"); - $group->password("password2")->label(t("Confirm Password"))->id("g-password2") - ->matches($group->password); + if ($writable) { + $group->password("password")->label(t("Password"))->id("g-password"); + $group->password("password2")->label(t("Confirm Password"))->id("g-password2") + ->matches($group->password); + } $group->input("email")->label(t("Email"))->id("g-email")->value($user->email); $group->input("url")->label(t("URL"))->id("g-url")->value($user->url); $group->checkbox("admin")->label(t("Admin"))->id("g-admin")->checked($user->admin); @@ -61,6 +73,11 @@ class user_Core { module::event("user_edit_form_admin", $user, $form); $group->submit("")->value(t("Modify User")); + if (!$writable) { + foreach ($group->inputs as $input) { + $input->disabled("disabled"); + } + } return $form; } @@ -234,6 +251,16 @@ class user_Core { } } + /** + * Determine if a feature is supported by the driver. + * + * @param string $feature the name of the feature to check + * @return boolean true if supported + */ + static function is_writable() { + return Identity::instance()->is_writable(); + } + /** * Return the guest user. * diff --git a/modules/gallery/libraries/Identity.php b/modules/gallery/libraries/Identity.php index a24e6226..fec822db 100644 --- a/modules/gallery/libraries/Identity.php +++ b/modules/gallery/libraries/Identity.php @@ -92,6 +92,17 @@ class Identity_Core { } } + /** + * Determine if a feature is supported by the driver. + * + * @param string $feature the name of the feature to check + * @return boolean true if supported + */ + public function is_writable() { + return !empty($this->config["allow_updates"]); + } + + /** * Return the guest user. * diff --git a/modules/gallery/libraries/drivers/Identity.php b/modules/gallery/libraries/drivers/Identity.php index e67547be..a92958c7 100644 --- a/modules/gallery/libraries/drivers/Identity.php +++ b/modules/gallery/libraries/drivers/Identity.php @@ -176,7 +176,6 @@ abstract class User_Definition { case "hash": case "url": case "locale": - Kohana::log("error", "__set($column, $value)"); $this->user->$column = $value; break; default: diff --git a/modules/gallery/views/admin_users.html.php b/modules/gallery/views/admin_users.html.php index a127bc15..82d0926c 100644 --- a/modules/gallery/views/admin_users.html.php +++ b/modules/gallery/views/admin_users.html.php @@ -2,7 +2,7 @@
+ " class="g-dialog-link g-button g-right ui-icon-left ui-state-default ui-corner-all" title="for_html_attr() ?>"> +

@@ -65,7 +68,7 @@ $user): ?> user admin ? "admin" : "" ?>"> - + "> " title="for_html_attr() ?>" alt="name) ?>" @@ -86,15 +89,19 @@ id") ?>" open_text="" class="g-panel-link g-button ui-state-default ui-corner-all ui-icon-left"> - - id != $user->id && !$user->guest): ?> - id") ?>" - class="g-dialog-link g-button ui-state-default ui-corner-all ui-icon-left"> - - - for_html_attr() ?>" - class="g-button ui-state-disabled ui-corner-all ui-icon-left"> - + + + + + id != $user->id && !$user->guest): ?> + id") ?>" + class="g-dialog-link g-button ui-state-default ui-corner-all ui-icon-left"> + + + for_html_attr() ?>" + class="g-button ui-state-disabled ui-corner-all ui-icon-left"> + + @@ -104,12 +111,14 @@

+ " class="g-dialog-link g-button g-right ui-icon-left ui-state-default ui-corner-all" title="for_html_attr() ?>"> +

@@ -118,8 +127,9 @@
-- cgit v1.2.3 From 1c1b726d077dc4db27b8af526384e74b9ae50e4f Mon Sep 17 00:00:00 2001 From: Tim Almdal Date: Tue, 13 Oct 2009 19:56:02 -0700 Subject: Change the user config setting "allow_updates" to true in the identity config file and correct a missing variable in the view. --- modules/gallery/config/identity.php | 2 +- modules/gallery/helpers/gallery_theme.php | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) (limited to 'modules/gallery/config') diff --git a/modules/gallery/config/identity.php b/modules/gallery/config/identity.php index 72d1b589..0479d08b 100644 --- a/modules/gallery/config/identity.php +++ b/modules/gallery/config/identity.php @@ -32,6 +32,6 @@ */ $config["default"] = array ( "driver" => "gallery", - "allow_updates" => false, + "allow_updates" => true, "params" => array(), ); diff --git a/modules/gallery/helpers/gallery_theme.php b/modules/gallery/helpers/gallery_theme.php index a342b4bd..54b35fb7 100644 --- a/modules/gallery/helpers/gallery_theme.php +++ b/modules/gallery/helpers/gallery_theme.php @@ -55,6 +55,7 @@ class gallery_theme_Core { if ($theme->page_type != "login") { $view = new View("login.html"); $view->user = user::active(); + $view->writable = user::is_writable(); return $view->render(); } } -- cgit v1.2.3 From 6d5c12e13e6f1199a96180e69cac69d77ecbbcc2 Mon Sep 17 00:00:00 2001 From: Tim Almdal Date: Sat, 17 Oct 2009 10:36:50 -0700 Subject: Move the default identity config into the users module and change the Identity constructor to look in module::get_var(gallery, identity_provider) for the current identity driver. In addition, don't just arbitrarily lock the use module. Only lock gallery and the module that is referenced by "user_driver_module" variable. --- modules/gallery/config/identity.php | 37 ------------------- modules/gallery/helpers/module.php | 3 +- modules/gallery/libraries/Identity.php | 66 ++++++++++++++-------------------- modules/user/config/identity.php | 37 +++++++++++++++++++ 4 files changed, 65 insertions(+), 78 deletions(-) delete mode 100644 modules/gallery/config/identity.php create mode 100644 modules/user/config/identity.php (limited to 'modules/gallery/config') diff --git a/modules/gallery/config/identity.php b/modules/gallery/config/identity.php deleted file mode 100644 index 0479d08b..00000000 --- a/modules/gallery/config/identity.php +++ /dev/null @@ -1,37 +0,0 @@ - "gallery", - "allow_updates" => true, - "params" => array(), -); diff --git a/modules/gallery/helpers/module.php b/modules/gallery/helpers/module.php index fe37f4f9..eab94500 100644 --- a/modules/gallery/helpers/module.php +++ b/modules/gallery/helpers/module.php @@ -90,7 +90,8 @@ class module_Core { // Lock certain modules $modules->gallery->locked = true; - $modules->user->locked = true; + $identity_module = self::get_var("gallery", "identity_provider", "user"); + $modules->$identity_module->locked = true; $modules->ksort(); self::$available = $modules; } diff --git a/modules/gallery/libraries/Identity.php b/modules/gallery/libraries/Identity.php index f844cf8f..9eb4b83b 100644 --- a/modules/gallery/libraries/Identity.php +++ b/modules/gallery/libraries/Identity.php @@ -49,49 +49,35 @@ class Identity_Core { /** * Loads the configured driver and validates it. * - * @param array|string custom configuration or config group name * @return void */ - public function __construct($config="default") { - if (is_string($config)) { - $name = $config; - - // Test the config group name - if (($config = Kohana::config("identity.".$config)) === NULL) { - throw new Exception("@todo NO USER LIBRARY CONFIGURATION FOR: $name"); - } - - if (is_array($config)) { - // Append the default configuration options - $config += Kohana::config("identity.default"); - } else { - // Load the default group - $config = Kohana::config("identity.default"); - } - - // Cache the config in the object - $this->config = $config; - - // Set driver name - $driver = "Identity_".ucfirst($this->config["driver"])."_Driver"; - - // Load the driver - if ( ! Kohana::auto_load($driver)) { - throw new Kohana_Exception("core.driver_not_found", $this->config["driver"], - get_class($this)); - } - - // Initialize the driver - $this->driver = new $driver($this->config["params"]); - - // Validate the driver - if ( !($this->driver instanceof Identity_Driver)) { - throw new Kohana_Exception("core.driver_implements", $this->config["driver"], - get_class($this), "Identity_Driver"); - } - - Kohana::log("debug", "Identity Library initialized"); + public function __construct() { + $name = $config = module::get_var("gallery", "identity_provider", "user"); + + // Test the config group name + if (($this->config = Kohana::config("identity.".$config)) === NULL) { + throw new Exception("@todo NO USER LIBRARY CONFIGURATION FOR: $name"); + } + + // Set driver name + $driver = "Identity_".ucfirst($this->config["driver"])."_Driver"; + + // Load the driver + if ( ! Kohana::auto_load($driver)) { + throw new Kohana_Exception("core.driver_not_found", $this->config["driver"], + get_class($this)); } + + // Initialize the driver + $this->driver = new $driver($this->config["params"]); + + // Validate the driver + if ( !($this->driver instanceof Identity_Driver)) { + throw new Kohana_Exception("core.driver_implements", $this->config["driver"], + get_class($this), "Identity_Driver"); + } + + Kohana::log("debug", "Identity Library initialized"); } /** diff --git a/modules/user/config/identity.php b/modules/user/config/identity.php new file mode 100644 index 00000000..f9f013aa --- /dev/null +++ b/modules/user/config/identity.php @@ -0,0 +1,37 @@ + "gallery", + "allow_updates" => true, + "params" => array(), +); -- cgit v1.2.3 From baca223e1d5a5d495b41b0232d2528a776bbc49c Mon Sep 17 00:00:00 2001 From: Tim Almdal Date: Wed, 4 Nov 2009 08:24:15 -0800 Subject: Address the inconsistency between Add Photos and Server Add so that neither replace spaces in the filename Fixes ticket #853 --- modules/gallery/config/upload.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'modules/gallery/config') diff --git a/modules/gallery/config/upload.php b/modules/gallery/config/upload.php index 897ecacf..69ea7768 100644 --- a/modules/gallery/config/upload.php +++ b/modules/gallery/config/upload.php @@ -33,4 +33,4 @@ $config['create_directories'] = FALSE; /** * Remove spaces from uploaded filenames. */ -$config['remove_spaces'] = TRUE; \ No newline at end of file +$config['remove_spaces'] = FALSE; \ No newline at end of file -- cgit v1.2.3