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 +- 8 files changed, 73 insertions(+), 24 deletions(-) (limited to 'modules') 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 @@