diff options
author | Tim Almdal <tnalmdal@shaw.ca> | 2009-10-13 11:48:42 -0700 |
---|---|---|
committer | Tim Almdal <tnalmdal@shaw.ca> | 2009-10-13 11:48:42 -0700 |
commit | d9720b77e9c4455df3e3237c285ad5a33afdd591 (patch) | |
tree | 2d2d7f918b9e7af7d312d7bc08f05fce0e4c528f | |
parent | 4dd6e4cc4c3353b36a5c69a845ad879ddf085d2f (diff) | |
parent | 53393a144609c0d8402b14606f52422bf3f28daf (diff) |
Merge branch 'master' into talmdal_dev
Conflicts:
modules/gallery/controllers/admin_users.php
modules/gallery/controllers/password.php
modules/gallery/helpers/group.php
modules/gallery/helpers/user.php
modules/notification/helpers/notification.php
-rw-r--r-- | modules/gallery/controllers/admin_users.php | 4 | ||||
-rw-r--r-- | modules/gallery/controllers/movies.php | 13 | ||||
-rw-r--r-- | modules/gallery/controllers/password.php | 4 | ||||
-rw-r--r-- | modules/gallery/controllers/photos.php | 12 | ||||
-rw-r--r-- | modules/gallery/helpers/group.php | 10 | ||||
-rw-r--r-- | modules/gallery/helpers/movie.php | 3 | ||||
-rw-r--r-- | modules/gallery/helpers/photo.php | 3 | ||||
-rw-r--r-- | modules/gallery/helpers/user.php | 9 | ||||
-rw-r--r-- | modules/gallery/libraries/Identity.php | 30 | ||||
-rw-r--r-- | modules/gallery/libraries/drivers/Identity.php | 28 | ||||
-rw-r--r-- | modules/gallery/tests/Access_Helper_Test.php | 4 | ||||
-rw-r--r-- | modules/notification/helpers/notification.php | 4 | ||||
-rw-r--r-- | modules/user/libraries/drivers/Identity/Gallery.php | 46 |
13 files changed, 66 insertions, 104 deletions
diff --git a/modules/gallery/controllers/admin_users.php b/modules/gallery/controllers/admin_users.php index 9b7c81f1..34b3a426 100644 --- a/modules/gallery/controllers/admin_users.php +++ b/modules/gallery/controllers/admin_users.php @@ -22,8 +22,8 @@ class Admin_Users_Controller extends Admin_Controller { $view = new Admin_View("admin.html"); $view->content = new View("admin_users.html"); $view->content->writable = user::is_writable(); - $view->content->users = user::users(array("orderby" => array("name" => "ASC"))); - $view->content->groups = group::groups(array("orderby" => array("name" => "ASC"))); + $view->content->users = user::get_user_list(array("orderby" => array("name" => "ASC"))); + $view->content->groups = group::get_group_list(array("orderby" => array("name" => "ASC"))); print $view; } diff --git a/modules/gallery/controllers/movies.php b/modules/gallery/controllers/movies.php index 2a917c58..01a9fc8b 100644 --- a/modules/gallery/controllers/movies.php +++ b/modules/gallery/controllers/movies.php @@ -61,7 +61,18 @@ class Movies_Controller extends Items_Controller { access::required("edit", $movie); $form = movie::get_edit_form($movie); - if ($valid = $form->validate()) { + $valid = $form->validate(); + + if ($valid) { + $new_ext = pathinfo($form->edit_item->filename->value, PATHINFO_EXTENSION); + $old_ext = pathinfo($photo->name, PATHINFO_EXTENSION); + if (strcasecmp($new_ext, $old_ext)) { + $form->edit_item->filename->add_error("illegal_extension", 1); + $valid = false; + } + } + + if ($valid) { if ($form->edit_item->filename->value != $movie->name || $form->edit_item->slug->value != $movie->slug) { // Make sure that there's not a name or slug conflict diff --git a/modules/gallery/controllers/password.php b/modules/gallery/controllers/password.php index 817ff01c..e8b08960 100644 --- a/modules/gallery/controllers/password.php +++ b/modules/gallery/controllers/password.php @@ -32,7 +32,7 @@ class Password_Controller extends Controller { if (request::method() == "post") { $this->_change_password(); } else { - $user = user::lookyp_by_hash(Input::instance()->get("key")); + $user = user::lookup_by_hash(Input::instance()->get("key")); if (!empty($user)) { print $this->_new_password_form($user->hash); } else { @@ -116,7 +116,7 @@ class Password_Controller extends Controller { private function _change_password() { $view = $this->_new_password_form(); if ($view->content->validate()) { - $user = user::lookyp_by_hash(Input::instance()->get("key")); + $user = user::lookup_by_hash(Input::instance()->get("key")); if (empty($user)) { throw new Exception("@todo FORBIDDEN", 503); } diff --git a/modules/gallery/controllers/photos.php b/modules/gallery/controllers/photos.php index 81e7519e..fbff53ce 100644 --- a/modules/gallery/controllers/photos.php +++ b/modules/gallery/controllers/photos.php @@ -63,7 +63,17 @@ class Photos_Controller extends Items_Controller { $form = photo::get_edit_form($photo); $valid = $form->validate(); - if ($valid = $form->validate()) { + + if ($valid) { + $new_ext = pathinfo($form->edit_item->filename->value, PATHINFO_EXTENSION); + $old_ext = pathinfo($photo->name, PATHINFO_EXTENSION); + if (strcasecmp($new_ext, $old_ext)) { + $form->edit_item->filename->add_error("illegal_extension", 1); + $valid = false; + } + } + + if ($valid) { if ($form->edit_item->filename->value != $photo->name || $form->edit_item->slug->value != $photo->slug) { // Make sure that there's not a name or slug conflict diff --git a/modules/gallery/helpers/group.php b/modules/gallery/helpers/group.php index 074a7b83..17dd7f70 100644 --- a/modules/gallery/helpers/group.php +++ b/modules/gallery/helpers/group.php @@ -91,7 +91,7 @@ class group_Core { * @return Group_Model the group object, or null if the id was invalid. */ static function lookup($id) { - return Identity::instance()->lookup_group($id); + return Identity::instance()->lookup_group_by_field("id", $id); } /** @@ -100,16 +100,16 @@ class group_Core { * @return Group_Core the group object, or null if the name was invalid. */ static function lookup_by_name($name) { - return Identity::instance()->lookup_group_by_name($name); + return Identity::instance()->lookup_group_by_field("name", $name); } /** * List the groups - * @param mixed options to apply to the selection of the user + * @param mixed options to apply to the selection of the user (@see Database.php) * @return array the group list. */ - static function groups($filter=array()) { - return Identity::instance()->list_groups($filter); + static function get_group_list($filter=array()) { + return Identity::instance()->get_group_list($filter); } /** diff --git a/modules/gallery/helpers/movie.php b/modules/gallery/helpers/movie.php index 98419387..9ca28fe6 100644 --- a/modules/gallery/helpers/movie.php +++ b/modules/gallery/helpers/movie.php @@ -141,7 +141,8 @@ class movie_Core { ->callback("item::validate_no_slashes") ->error_messages("no_slashes", t("The movie name can't contain a \"/\"")) ->callback("item::validate_no_trailing_period") - ->error_messages("no_trailing_period", t("The movie name can't end in \".\"")); + ->error_messages("no_trailing_period", t("The movie name can't end in \".\"")) + ->error_messages("illegal_extension", t("You cannot change the filename extension")); $group->input("slug")->label(t("Internet Address"))->value($movie->slug) ->callback("item::validate_url_safe") ->error_messages( diff --git a/modules/gallery/helpers/photo.php b/modules/gallery/helpers/photo.php index 99f28753..6677ddc9 100644 --- a/modules/gallery/helpers/photo.php +++ b/modules/gallery/helpers/photo.php @@ -169,7 +169,8 @@ class photo_Core { ->callback("item::validate_no_slashes") ->error_messages("no_slashes", t("The photo name can't contain a \"/\"")) ->callback("item::validate_no_trailing_period") - ->error_messages("no_trailing_period", t("The photo name can't end in \".\"")); + ->error_messages("no_trailing_period", t("The photo name can't end in \".\"")) + ->error_messages("illegal_extension", t("You cannot change the filename extension")); $group->input("slug")->label(t("Internet Address"))->value($photo->slug) ->callback("item::validate_url_safe") ->error_messages( diff --git a/modules/gallery/helpers/user.php b/modules/gallery/helpers/user.php index e3494fdf..f0509030 100644 --- a/modules/gallery/helpers/user.php +++ b/modules/gallery/helpers/user.php @@ -310,18 +310,19 @@ class user_Core { * @return User_Model the user object, or null if the id was invalid. */ static function lookup($id) { - return Identity::instance()->lookup_user($id); + return Identity::instance()->lookup_user_by_field("id", $id); } /** * Look up a user by name. - * @param integer $id the user name + * @param integer $name the user name * @return User_Model the user object, or null if the name was invalid. */ static function lookup_by_name($name) { return Identity::instance()->lookup_user_by_field("name", $name); } + /** * Look up a user by hash. * @param string $name the user name @@ -336,8 +337,8 @@ class user_Core { * @param mixed options to apply to the selection of the user(optional) * @return array the group list. */ - static function users($filter=array()) { - return Identity::instance()->list_users($filter); + static function get_user_list($filter=array()) { + return Identity::instance()->get_user_list($filter); } /** diff --git a/modules/gallery/libraries/Identity.php b/modules/gallery/libraries/Identity.php index fec822db..488cc535 100644 --- a/modules/gallery/libraries/Identity.php +++ b/modules/gallery/libraries/Identity.php @@ -147,15 +147,6 @@ class Identity_Core { } /** - * Look up a user by id. - * @param integer $id the user id - * @return Identity_Model the user object, or null if the id was invalid. - */ - public function lookup_user($id) { - return $this->driver->lookup_user($id); - } - - /** * Look up a user by field value. * @param string search field * @param string search value @@ -194,21 +185,12 @@ class Identity_Core { } /** - * Look up a group by id. - * @param integer $id the user id - * @return Group_Model the group object, or null if the id was invalid. - */ - public function lookup_group($id) { - return $this->driver->lookup_group($id); - } - - /** * Look up a group by name. * @param integer $id the group name * @return Group_Model the group object, or null if the name was invalid. */ - public function lookup_group_by_name($name) { - return $this->driver->lookup_group_by_name($name); + public function lookup_group_by_field($field_name, $value) { + return $this->driver->lookup_group_by_field($field_name, $value); } /** @@ -216,8 +198,8 @@ class Identity_Core { * @param mixed options to apply to the selection of the user * @return array the group list. */ - public function list_users($filter=array()) { - return $this->driver->list_users($filter); + public function get_user_list($filter=array()) { + return $this->driver->get_user_list($filter); } /** @@ -225,8 +207,8 @@ class Identity_Core { * @param mixed options to apply to the selection of the user * @return array the group list. */ - public function list_groups($filter=array()) { - return $this->driver->list_groups($filter); + public function get_group_list($filter=array()) { + return $this->driver->get_group_list($filter); } /** diff --git a/modules/gallery/libraries/drivers/Identity.php b/modules/gallery/libraries/drivers/Identity.php index a92958c7..ca80aad5 100644 --- a/modules/gallery/libraries/drivers/Identity.php +++ b/modules/gallery/libraries/drivers/Identity.php @@ -52,15 +52,9 @@ interface Identity_Driver { * @return string hashed password */ public function hash_password($password); - /** - * Look up a user by id. - * @param integer $id the user id - * @return User_Core the user object, or null if the id was invalid. - */ - public function lookup_user($id); /** - * Look up a user by name. + * Look up a user by by search the specified field. * @param string search field * @param string search value * @return User_Core the user object, or null if the name was invalid. @@ -90,34 +84,20 @@ interface Identity_Driver { public function registered_users(); /** - * Look up a group by id. - * @param integer $id the user id - * @return Group_Model the group object, or null if the id was invalid. - */ - public function lookup_group($id); - - /** - * Look up a group by name. - * @param integer $id the group name - * @return Group_Model the group object, or null if the name was invalid. - */ - public function lookup_group_by_name($name); - - /** * List the users * @param mixed options to apply to the selection of the user * @todo Do a longer write up on format of filters (@see Database.php) * @return array the group list. */ - public function list_users($filter=array()); + public function get_user_list($filter=array()); /** * List the groups - * @param mixed options to apply to the selection of the user + * @param mixed options to apply to the selection of the group * @todo Do a longer write up on format of filters (@see Database.php) * @return array the group list. */ - public function list_groups($filter=array()); + public function get_group_list($filter=array()); /** * Return the edit rules associated with an group. diff --git a/modules/gallery/tests/Access_Helper_Test.php b/modules/gallery/tests/Access_Helper_Test.php index 59cec453..72d7e04c 100644 --- a/modules/gallery/tests/Access_Helper_Test.php +++ b/modules/gallery/tests/Access_Helper_Test.php @@ -33,7 +33,7 @@ class Access_Helper_Test extends Unit_Test_Case { } catch (Exception $e) { } try { - $user = ORM::factory("user")->where("name", "access_test")->find(); + $user = user::lookup_by_name("access_test"); if ($user->loaded) { $user->delete(); } @@ -307,7 +307,7 @@ class Access_Helper_Test extends Unit_Test_Case { $group->save(); access::allow($group, "edit", $root); - $user = ORM::factory("user", $user->id); // reload() does not flush related columns + $user = user::lookup($user->id); // reload() does not flush related columns user::set_active($user); // And verify that the user can edit. diff --git a/modules/notification/helpers/notification.php b/modules/notification/helpers/notification.php index 8cf9f428..150616ab 100644 --- a/modules/notification/helpers/notification.php +++ b/modules/notification/helpers/notification.php @@ -79,8 +79,8 @@ class notification { $subscriber_ids[] = $subscriber->user_id; } - $users = user::users(array("in" => array("id", $subscriber_ids), - "where" => array("email IS NOT" => null))); + $users = user::get_user_list(array("in" => array("id", $subscriber_ids), + "where" => array("email IS NOT" => null))); $subscribers = array(); foreach ($users as $user) { diff --git a/modules/user/libraries/drivers/Identity/Gallery.php b/modules/user/libraries/drivers/Identity/Gallery.php index f8816644..b287ed4c 100644 --- a/modules/user/libraries/drivers/Identity/Gallery.php +++ b/modules/user/libraries/drivers/Identity/Gallery.php @@ -105,19 +105,6 @@ class Identity_Gallery_Driver implements Identity_Driver { } /** - * Look up a user by id. - * @param integer $id the user id - * @return User_Model the user object, or null if the id was invalid. - */ - public function lookup_user($id) { - $user = model_cache::get("user", $id); - if ($user->loaded) { - return new Gallery_User($user); - } - return null; - } - - /** * Look up a user by field value. * @param string search field * @param string search value @@ -174,27 +161,15 @@ class Identity_Gallery_Driver implements Identity_Driver { } /** - * Look up a user by id. - * @param integer $id the user id - * @return User_Model the user object, or null if the id was invalid. - */ - public function lookup_group($id) { - $group = model_cache::get("group", $id); - if ($group->loaded) { - return new Gallery_Group($group); - } - return null; - } - - /** - * Look up a group by name. - * @param integer $id the group name - * @return Group_Model the group object, or null if the name was invalid. + * Look up a group by field value. + * @param string search field + * @param string search value + * @return Group_Core the group object, or null if the name was invalid. */ - public function lookup_group_by_name($name) { + public function lookup_user_by_field($field_name, $value) { try { - $group = model_cache::get("group", $name, "name"); - if ($group->loaded) { + $user = model_cache::get("group", $value, $field_name); + if ($user->loaded) { return new Gallery_Group($group); } } catch (Exception $e) { @@ -205,12 +180,13 @@ class Identity_Gallery_Driver implements Identity_Driver { return null; } + /** * List the users * @param mixed options to apply to the selection of the user * @return array the group list. */ - public function list_users($filter=array()) { + public function get_user_list($filter=array()) { $results = $this->_do_search("user", $filter); $users = array(); foreach ($results->as_array() as $user) { @@ -222,10 +198,10 @@ class Identity_Gallery_Driver implements Identity_Driver { /** * List the groups - * @param mixed options to apply to the selection of the user + * @param mixed options to apply to the selection of the group * @return array the group list. */ - public function list_groups($filter=array()) { + public function get_group_list($filter=array()) { $results = $this->_do_search("group", $filter); $groups = array(); foreach ($results->as_array() as $group) { |