Permalink
Browse files

Change the name of identity library from Identity to IdentityProvider…

…. Create a helper class called identity to simplify call the Identity Provider. Move the contents of MY_Session.php to the new helper class and remove the MY_Session class
  • Loading branch information...
1 parent 4cb9ec1 commit 3c936d661a088fb43b47eb5b208958180e8f65eb @talmdal talmdal committed Oct 22, 2009
Showing with 628 additions and 512 deletions.
  1. +1 −1 modules/akismet/tests/Akismet_Helper_Test.php
  2. +4 −4 modules/comment/controllers/comments.php
  3. +1 −1 modules/comment/helpers/comment.php
  4. +1 −1 modules/comment/models/comment.php
  5. +1 −1 modules/comment/tests/Comment_Event_Test.php
  6. +2 −2 modules/comment/tests/Comment_Helper_Test.php
  7. +4 −4 modules/comment/tests/Comment_Model_Test.php
  8. +1 −1 modules/digibug/controllers/digibug.php
  9. +2 −2 modules/digibug/tests/Digibug_Controller_Test.php
  10. +8 −8 modules/g2_import/helpers/g2_import.php
  11. +1 −1 modules/gallery/controllers/admin.php
  12. +5 −5 modules/gallery/controllers/admin_identity.php
  13. +2 −2 modules/gallery/controllers/albums.php
  14. +2 −2 modules/gallery/controllers/l10n_client.php
  15. +4 −4 modules/gallery/controllers/login.php
  16. +1 −1 modules/gallery/controllers/logout.php
  17. +3 −3 modules/gallery/controllers/permissions.php
  18. +2 −2 modules/gallery/controllers/upgrader.php
  19. +2 −2 modules/gallery/controllers/welcome_message.php
  20. +2 −2 modules/gallery/helpers/access.php
  21. +1 −1 modules/gallery/helpers/gallery.php
  22. +3 −7 modules/gallery/helpers/gallery_event.php
  23. +1 −1 modules/gallery/helpers/gallery_installer.php
  24. +1 −1 modules/gallery/helpers/gallery_theme.php
  25. +225 −0 modules/gallery/helpers/identity.php
  26. +2 −2 modules/gallery/helpers/item.php
  27. +1 −1 modules/gallery/helpers/locales.php
  28. +1 −1 modules/gallery/helpers/log.php
  29. +1 −1 modules/gallery/helpers/movie.php
  30. +1 −1 modules/gallery/helpers/photo.php
  31. +1 −1 modules/gallery/helpers/site_status.php
  32. +1 −1 modules/gallery/helpers/task.php
  33. +2 −2 modules/gallery/libraries/Admin_View.php
  34. +0 −222 modules/gallery/libraries/Identity.php
  35. +200 −0 modules/gallery/libraries/IdentityProvider.php
  36. +0 −93 modules/gallery/libraries/MY_Session.php
  37. +3 −3 modules/gallery/libraries/Theme_View.php
  38. +1 −1 modules/gallery/libraries/drivers/{Identity.php → IdentityProvider.php}
  39. +1 −1 modules/gallery/models/item.php
  40. +1 −1 modules/gallery/models/log.php
  41. +1 −1 modules/gallery/models/task.php
  42. +72 −72 modules/gallery/tests/Access_Helper_Test.php
  43. +2 −2 modules/gallery/tests/Albums_Controller_Test.php
  44. +3 −3 modules/gallery/tests/Item_Helper_Test.php
  45. +3 −3 modules/gallery/tests/Photos_Controller_Test.php
  46. +1 −1 modules/gallery/views/kohana_error_page.php
  47. +1 −1 modules/gallery/views/login.html.php
  48. +1 −1 modules/gallery/views/login_ajax.html.php
  49. +5 −5 modules/notification/helpers/notification.php
  50. +1 −1 modules/notification/helpers/notification_event.php
  51. +2 −2 modules/search/helpers/search.php
  52. +2 −2 modules/server_add/controllers/server_add.php
  53. +1 −1 modules/server_add/helpers/server_add_event.php
  54. +1 −1 modules/server_add/helpers/server_add_theme.php
  55. +3 −3 modules/user/controllers/admin_users.php
  56. +1 −1 modules/user/controllers/password.php
  57. +2 −2 modules/user/controllers/users.php
  58. +14 −4 modules/user/helpers/group.php
  59. +15 −15 modules/user/libraries/drivers/{Identity → IdentityProvider}/Gallery.php
  60. +1 −1 modules/user/views/admin_users.html.php
@@ -26,7 +26,7 @@ public function setup() {
$root = ORM::factory("item", 1);
$this->_comment = comment::create(
- $root, Identity::guest(), "This is a comment",
+ $root, identity::guest(), "This is a comment",
"John Doe", "john@gallery2.org", "http://gallery2.org");
foreach ($this->_comment->list_fields("comments") as $name => $field) {
if (strpos($name, "server_") === 0) {
@@ -65,7 +65,7 @@ public function _create($comment) {
$form = comment::get_add_form($item);
$valid = $form->validate();
if ($valid) {
- if (Session::active_user()->guest && !$form->add_comment->inputs["name"]->value) {
+ if (identity::active_user()->guest && !$form->add_comment->inputs["name"]->value) {
$form->add_comment->inputs["name"]->add_error("missing", 1);
$valid = false;
}
@@ -78,13 +78,13 @@ public function _create($comment) {
if ($valid) {
$comment = comment::create(
- $item, Session::active_user(),
+ $item, identity::active_user(),
$form->add_comment->text->value,
$form->add_comment->inputs["name"]->value,
$form->add_comment->email->value,
$form->add_comment->url->value);
- $active = Session::active_user();
+ $active = identity::active_user();
if ($active->guest) {
$form->add_comment->inputs["name"]->value("");
$form->add_comment->email->value("");
@@ -192,7 +192,7 @@ public function _form_add($item_id) {
* @see REST_Controller::form_edit($resource)
*/
public function _form_edit($comment) {
- if (!Session::active_user()->admin) {
+ if (!identity::active_user()->admin) {
access::forbidden();
}
print comment::get_edit_form($comment);
@@ -75,7 +75,7 @@ static function get_add_form($item) {
module::event("comment_add_form", $form);
$group->submit("")->value(t("Add"));
- $active = Session::active_user();
+ $active = identity::active_user();
if (!$active->guest) {
$group->inputs["name"]->value($active->full_name)->disabled("disabled");
$group->email->value($active->email)->disabled("disabled");
@@ -23,7 +23,7 @@ function item() {
}
function author() {
- return Identity::lookup_user($this->author_id);
+ return identity::lookup_user($this->author_id);
}
function author_name() {
@@ -22,7 +22,7 @@ public function deleting_an_item_deletes_its_comments_too_test() {
$rand = rand();
$album = album::create(ORM::factory("item", 1), "test_$rand", "test_$rand");
$comment = comment::create(
- $album, Identity::guest(), "text_$rand", "name_$rand", "email_$rand", "url_$rand");
+ $album, identity::guest(), "text_$rand", "name_$rand", "email_$rand", "url_$rand");
$album->delete();
@@ -48,7 +48,7 @@ public function create_comment_for_guest_test() {
$rand = rand();
$root = ORM::factory("item", 1);
$comment = comment::create(
- $root, Identity::guest(), "text_$rand", "name_$rand", "email_$rand", "url_$rand");
+ $root, identity::guest(), "text_$rand", "name_$rand", "email_$rand", "url_$rand");
$this->assert_equal("name_$rand", $comment->author_name());
$this->assert_equal("email_$rand", $comment->author_email());
@@ -77,7 +77,7 @@ public function create_comment_for_guest_test() {
public function create_comment_for_user_test() {
$rand = rand();
$root = ORM::factory("item", 1);
- $admin = Identity::lookup_user(2);
+ $admin = identity::lookup_user(2);
$comment = comment::create(
$root, $admin, "text_$rand", "name_$rand", "email_$rand", "url_$rand");
@@ -22,17 +22,17 @@ class Comment_Model_Test extends Unit_Test_Case {
public function cant_view_comments_for_unviewable_items_test() {
$root = ORM::factory("item", 1);
$album = album::create($root, rand(), rand(), rand());
- $comment = comment::create($album, Identity::guest(), "text", "name", "email", "url");
- Session::set_active_user(Identity::guest());
+ $comment = comment::create($album, identity::guest(), "text", "name", "email", "url");
+ identity::set_active_user(identity::guest());
// We can see the comment when permissions are granted on the album
- access::allow(Identity::everybody(), "view", $album);
+ access::allow(identity::everybody(), "view", $album);
$this->assert_equal(
1,
ORM::factory("comment")->viewable()->where("comments.id", $comment->id)->count_all());
// We can't see the comment when permissions are denied on the album
- access::deny(Identity::everybody(), "view", $album);
+ access::deny(identity::everybody(), "view", $album);
$this->assert_equal(
0,
ORM::factory("comment")->viewable()->where("comments.id", $comment->id)->count_all());
@@ -23,7 +23,7 @@ public function print_photo($id) {
$item = ORM::factory("item", $id);
access::required("view", $item);
- if (access::group_can(Identity::everybody(), "view_full", $item)) {
+ if (access::group_can(identity::everybody(), "view_full", $item)) {
$full_url = $item->file_url(true);
$thumb_url = $item->thumb_url(true);
} else {
@@ -35,8 +35,8 @@ public function setup() {
$root = ORM::factory("item", 1);
$this->_album = album::create($root, rand(), "test album");
- access::deny(Identity::everybody(), "view_full", $this->_album);
- access::deny(Identity::registered_users(), "view_full", $this->_album);
+ access::deny(identity::everybody(), "view_full", $this->_album);
+ access::deny(identity::registered_users(), "view_full", $this->_album);
$rand = rand();
$this->_item = photo::create($this->_album, MODPATH . "gallery/tests/test.jpg", "$rand.jpg",
@@ -230,16 +230,16 @@ static function import_group(&$queue) {
switch ($g2_group->getGroupType()) {
case GROUP_NORMAL:
try {
- $group = Identity::create_group($g2_group->getGroupName());
+ $group = identity::create_group($g2_group->getGroupName());
} catch (Exception $e) {
// @todo For now we assume this is a "duplicate group" exception
- $group = Identity::lookup_user_by_name($g2_group->getGroupname());
+ $group = identity::lookup_user_by_name($g2_group->getGroupname());
}
$message = t("Group '%name' was imported", array("name" => $g2_group->getGroupname()));
break;
case GROUP_ALL_USERS:
- $group = Identity::registered_users();
+ $group = identity::registered_users();
$message = t("Group 'Registered' was converted to '%name'", array("name" => $group->name));
break;
@@ -248,7 +248,7 @@ static function import_group(&$queue) {
break; // This is not a group in G3
case GROUP_EVERYBODY:
- $group = Identity::everybody();
+ $group = identity::everybody();
$message = t("Group 'Everybody' was converted to '%name'", array("name" => $group->name));
break;
}
@@ -270,7 +270,7 @@ static function import_user(&$queue) {
}
if (g2(GalleryCoreApi::isAnonymousUser($g2_user_id))) {
- self::set_map($g2_user_id, Identity::guest()->id);
+ self::set_map($g2_user_id, identity::guest()->id);
return t("Skipping Anonymous User");
}
@@ -285,11 +285,11 @@ static function import_user(&$queue) {
$g2_groups = g2(GalleryCoreApi::fetchGroupsForUser($g2_user->getId()));
try {
- $user = Identity::create_user($g2_user->getUsername(), $g2_user->getfullname(), "");
+ $user = identity::create_user($g2_user->getUsername(), $g2_user->getfullname(), "");
$message = t("Created user: '%name'.", array("name" => $user->name));
} catch (Exception $e) {
// @todo For now we assume this is a "duplicate user" exception
- $user = Identity::lookup_user_by_name($g2_user->getUsername());
+ $user = identity::lookup_user_by_name($g2_user->getUsername());
$message = t("Loaded existing user: '%name'.", array("name" => $user->name));
}
@@ -301,7 +301,7 @@ static function import_user(&$queue) {
$user->admin = true;
$message .= t("\n\tAdded 'admin' flag to user");
} else {
- $group = Identity::lookup_group(self::map($g2_group_id));
+ $group = identity::lookup_group(self::map($g2_group_id));
$user->add($group);
$message .= t("\n\tAdded user to group '%group'.", array("group" => $group->name));
}
@@ -21,7 +21,7 @@ class Admin_Controller extends Controller {
private $theme;
public function __construct($theme=null) {
- if (!(Session::active_user()->admin)) {
+ if (!(identity::active_user()->admin)) {
access::forbidden();
}
@@ -21,7 +21,7 @@ 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->available = identity::providers();
$view->content->active = module::get_var("gallery", "identity_provider", "user");
print $view;
}
@@ -39,21 +39,21 @@ public function change() {
access::verify_csrf();
$active_provider = module::get_var("gallery", "identity_provider", "user");
- $providers = Identity::providers();
+ $providers = identity::providers();
$new_provider = $this->input->post("provider");
if ($new_provider != $active_provider) {
module::event("pre_identity_change", $active_provider, $new_provider);
- Identity::deactivate();
+ identity::deactivate();
// Switch authentication
module::set_var("gallery", "identity_provider", $new_provider);
- Identity::reset();
+ identity::reset();
- Identity::activate();
+ identity::activate();
// @todo this type of collation is questionable from an i18n perspective
message::success(t("Changed to %description",
@@ -111,7 +111,7 @@ private function _create_album($album) {
$this->input->post("name"),
$this->input->post("title", $this->input->post("name")),
$this->input->post("description"),
- Session::active_user()->id,
+ identity::active_user()->id,
$this->input->post("slug"));
log::success("content", "Created an album",
@@ -146,7 +146,7 @@ private function _create_photo($album) {
$_FILES["file"]["name"],
$this->input->post("title", $this->input->post("name")),
$this->input->post("description"),
- Session::active_user()->id);
+ identity::active_user()->id);
log::success("content", "Added a photo", html::anchor("photos/$photo->id", "view photo"));
message::success(t("Added photo %photo_title",
@@ -20,7 +20,7 @@
class L10n_Client_Controller extends Controller {
public function save() {
access::verify_csrf();
- if (!Session::active_user()->admin) {
+ if (!identity::active_user()->admin) {
access::forbidden();
}
@@ -85,7 +85,7 @@ public function save() {
public function toggle_l10n_mode() {
access::verify_csrf();
- if (!Session::active_user()->admin) {
+ if (!identity::active_user()->admin) {
access::forbidden();
}
@@ -58,8 +58,8 @@ private function _auth($url) {
$form = login::get_login_form($url);
$valid = $form->validate();
if ($valid) {
- $user = Identity::lookup_user_by_name($form->login->inputs["name"]->value);
- if (empty($user) || !Identity::is_correct_password($user, $form->login->password->value)) {
+ $user = identity::lookup_user_by_name($form->login->inputs["name"]->value);
+ if (empty($user) || !identity::is_correct_password($user, $form->login->password->value)) {
log::warning(
"user",
t("Failed login for %name",
@@ -70,12 +70,12 @@ private function _auth($url) {
}
if ($valid) {
- if (Identity::is_writable()) {
+ if (identity::is_writable()) {
$user->login_count += 1;
$user->last_login = time();
$user->save();
}
- Session::set_active_user($user);
+ identity::set_active_user($user);
log::info("user", t("User %name logged in", array("name" => $user->name)));
}
@@ -19,7 +19,7 @@
*/
class Logout_Controller extends Controller {
public function index() {
- $user = Session::active_user();
+ $user = identity::active_user();
if (!$user->guest) {
try {
Session::instance()->destroy();
@@ -51,7 +51,7 @@ function form($id) {
function change($command, $group_id, $perm_id, $item_id) {
access::verify_csrf();
- $group = Identity::lookup_group($group_id);
+ $group = identity::lookup_group($group_id);
$perm = ORM::factory("permission", $perm_id);
$item = ORM::factory("item", $item_id);
access::required("view", $item);
@@ -74,7 +74,7 @@ function change($command, $group_id, $perm_id, $item_id) {
// If the active user just took away their own edit permissions, give it back.
if ($perm->name == "edit") {
- if (!access::user_can(Session::active_user(), "edit", $item)) {
+ if (!access::user_can(identity::active_user(), "edit", $item)) {
access::allow($group, $perm->name, $item);
}
}
@@ -84,7 +84,7 @@ function change($command, $group_id, $perm_id, $item_id) {
private function _get_form($item) {
$view = new View("permissions_form.html");
$view->item = $item;
- $view->groups = Identity::groups();
+ $view->groups = identity::groups();
$view->permissions = ORM::factory("permission")->find_all();
return $view;
}
@@ -40,7 +40,7 @@ public function index() {
}
$view = new View("upgrader.html");
- $view->can_upgrade = Session::active_user()->admin || $session->get("can_upgrade");
+ $view->can_upgrade = identity::active_user()->admin || $session->get("can_upgrade");
$view->upgrade_token = $upgrade_token;
$view->available = module::available();
$view->done = ($available_upgrades == 0);
@@ -52,7 +52,7 @@ public function upgrade() {
// @todo this may screw up some module installers, but we don't have a better answer at
// this time.
$_SERVER["HTTP_HOST"] = "example.com";
- } else if (!Session::active_user()->admin && !Session::instance()->get("can_upgrade", false)) {
+ } else if (!identity::active_user()->admin && !Session::instance()->get("can_upgrade", false)) {
access::forbidden();
}
@@ -19,12 +19,12 @@
*/
class Welcome_Message_Controller extends Controller {
public function index() {
- if (!Session::active_user()->admin) {
+ if (!identity::active_user()->admin) {
url::redirect(item::root()->abs_url());
}
$v = new View("welcome_message.html");
- $v->user = Session::active_user();
+ $v->user = identity::active_user();
print $v;
}
}
@@ -79,7 +79,7 @@ class access_Core {
* @return boolean
*/
static function can($perm_name, $item) {
- return self::user_can(Session::active_user(), $perm_name, $item);
+ return self::user_can(identity::active_user(), $perm_name, $item);
}
/**
@@ -423,7 +423,7 @@ private static function _get_all_groups() {
// This is ok at packaging time, so work around it.
$config = module::get_var("gallery", "identity_provider");
if (!empty($config)) {
- return Identity::groups();
+ return identity::groups();
} else {
return array();
}
@@ -27,7 +27,7 @@ class gallery_Core {
static function maintenance_mode() {
$maintenance_mode = Kohana::config("core.maintenance_mode", false, false);
- if (Router::$controller != "login" && !empty($maintenance_mode) && !Session::active_user()->admin) {
+ if (Router::$controller != "login" && !empty($maintenance_mode) && !identity::active_user()->admin) {
Router::$controller = "maintenance";
Router::$controller_path = MODPATH . "gallery/controllers/maintenance.php";
Router::$method = "index";
Oops, something went wrong.

0 comments on commit 3c936d6

Please sign in to comment.