From: <gem...@li...> - 2011-11-24 15:13:50
|
Revision: 281 http://gemstracker.svn.sourceforge.net/gemstracker/?rev=281&view=rev Author: matijsdejong Date: 2011-11-24 15:13:38 +0000 (Thu, 24 Nov 2011) Log Message: ----------- Split User->getOrganizationId into User->getBaseOrganizationId and User->getCurrentOrganizationId. user_organization info no longer part of return of getUserData(), but set buy setCurrentOrganization. Added checks on $this->menu to _layout functions so that error messages remain displayed, even when the menu is not active. ($#&@!) Modified Paths: -------------- trunk/library/classes/Gems/Default/AskAction.php trunk/library/classes/Gems/Default/IndexAction.php trunk/library/classes/Gems/Default/OrganizationAction.php trunk/library/classes/Gems/User/NoLoginDefinition.php trunk/library/classes/Gems/User/OldStaffUserDefinition.php trunk/library/classes/Gems/User/Organization.php trunk/library/classes/Gems/User/ProjectUserDefinition.php trunk/library/classes/Gems/User/StaffUserDefinition.php trunk/library/classes/Gems/User/User.php trunk/library/classes/Gems/User/UserLoader.php trunk/library/classes/GemsEscort.php trunk/library/classes/MUtil/Controller/Action.php Modified: trunk/library/classes/Gems/Default/AskAction.php =================================================================== --- trunk/library/classes/Gems/Default/AskAction.php 2011-11-24 14:25:16 UTC (rev 280) +++ trunk/library/classes/Gems/Default/AskAction.php 2011-11-24 15:13:38 UTC (rev 281) @@ -121,7 +121,7 @@ $this->view->headMeta()->appendHttpEquiv('Refresh', $delay . '; url=' . $url); } - $organizationData = $this->db->fetchRow("SELECT * FROM gems__organizations WHERE gor_id_organization = ?", $token->getOrganizationId()); + $organization = $this->loader->getOrganization($token->getOrganizationId()); Gems_Html::init(); // Turn on Gems specific html like pInfo $this->html->h3($this->_('Token')); @@ -131,8 +131,8 @@ $this->html->pInfo(sprintf($this->_('Thank you for answering the survey for token %s.'), strtoupper($this->_getParam(MUtil_Model::REQUEST_ID)))); $this->html->pInfo($this->_('Please click the button below to answer the next survey.')); } else { - if ($organizationData['gor_welcome']) { - $this->html->pInfo()->raw(MUtil_Markup::render($this->_($organizationData['gor_welcome']), 'Bbcode', 'Html')); + if ($welcome = $organization->getWelcome()) { + $this->html->pInfo()->raw(MUtil_Markup::render($this->_($welcome), 'Bbcode', 'Html')); } $this->html->pInfo(sprintf($this->_('Please click the button below to answer the survey for token %s.'), strtoupper($tokenId))); } @@ -157,8 +157,8 @@ 'After this survey there are another %d surveys we would like you to answer.', $next), $next)); } - if ($organizationData['gor_signature']) { - $this->html->pInfo()->raw(MUtil_Markup::render($this->_($organizationData['gor_signature']), 'Bbcode', 'Html')); + if ($sig = $organization->getSignature()) { + $this->html->pInfo()->raw(MUtil_Markup::render($this->_($sig), 'Bbcode', 'Html')); } return; @@ -216,20 +216,20 @@ if ($this->_request->isPost()) { $throttleSettings = $this->project->getAskThrottleSettings(); - + // Prune the database for (very) old attempts - $this->db->query("DELETE FROM gems__token_attempts WHERE gta_datetime < DATE_SUB(NOW(), INTERVAL ? second)", + $this->db->query("DELETE FROM gems__token_attempts WHERE gta_datetime < DATE_SUB(NOW(), INTERVAL ? second)", $throttleSettings['period'] * 20); - + // Retrieve the number of failed attempts that occurred within the specified window - $attemptData = $this->db->fetchRow("SELECT COUNT(1) AS attempts, UNIX_TIMESTAMP(MAX(gta_datetime)) AS last " . + $attemptData = $this->db->fetchRow("SELECT COUNT(1) AS attempts, UNIX_TIMESTAMP(MAX(gta_datetime)) AS last " . "FROM gems__token_attempts WHERE gta_datetime > DATE_SUB(NOW(), INTERVAL ? second)", $throttleSettings['period']); - + $remainingDelay = ($attemptData['last'] + $throttleSettings['delay']) - time(); - + if ($attemptData['attempts'] > $throttleSettings['threshold'] && $remainingDelay > 0) { $this->escort->logger->log("Possible token brute force attack, throttling for $remainingDelay seconds", Zend_Log::ERR); - + $this->addMessage($this->_('The server is currently busy, please wait a while and try again.')); } else if ($form->isValid($_POST)) { $this->_forward('forward'); Modified: trunk/library/classes/Gems/Default/IndexAction.php =================================================================== --- trunk/library/classes/Gems/Default/IndexAction.php 2011-11-24 14:25:16 UTC (rev 280) +++ trunk/library/classes/Gems/Default/IndexAction.php 2011-11-24 15:13:38 UTC (rev 281) @@ -164,7 +164,7 @@ $element->setRequired(true); if (! $this->_request->isPost()) { - $element->setValue($this->loader->getCurrentUser()->getOrganizationId()); + $element->setValue($this->loader->getCurrentUser()->getCurrentOrganizationId()); } } @@ -293,7 +293,6 @@ * Fix current locale / organization in cookies */ Gems_Cookies::setLocale($user->getLocale(), $this->basepath->getBasePath()); - Gems_Cookies::setOrganization($user->getOrganizationId(), $this->basepath->getBasePath()); /** * Ready Modified: trunk/library/classes/Gems/Default/OrganizationAction.php =================================================================== --- trunk/library/classes/Gems/Default/OrganizationAction.php 2011-11-24 14:25:16 UTC (rev 280) +++ trunk/library/classes/Gems/Default/OrganizationAction.php 2011-11-24 15:13:38 UTC (rev 281) @@ -75,7 +75,6 @@ $request = $this->getRequest(); $orgId = urldecode($request->getParam('org')); $url = base64_decode($request->getParam('current_uri')); - $oldOrgId = $user->getOrganizationId(); $allowedOrganizations = $user->getAllowedOrganizations(); if (isset($allowedOrganizations[$orgId])) { Modified: trunk/library/classes/Gems/User/NoLoginDefinition.php =================================================================== --- trunk/library/classes/Gems/User/NoLoginDefinition.php 2011-11-24 14:25:16 UTC (rev 280) +++ trunk/library/classes/Gems/User/NoLoginDefinition.php 2011-11-24 15:13:38 UTC (rev 281) @@ -69,7 +69,6 @@ return array( 'user_active' => false, 'user_role' => 'nologin', - //'user_organization_id' => 0, //REMOVED AS IT BREAKS STORING LAST ORGANIZATION ); } } Modified: trunk/library/classes/Gems/User/OldStaffUserDefinition.php =================================================================== --- trunk/library/classes/Gems/User/OldStaffUserDefinition.php 2011-11-24 14:25:16 UTC (rev 280) +++ trunk/library/classes/Gems/User/OldStaffUserDefinition.php 2011-11-24 15:13:38 UTC (rev 281) @@ -174,18 +174,15 @@ * compatibility */ $select = new Zend_Db_Select($this->db); - $select->from('gems__staff', array('user_id'=>'gsf_id_user', - 'user_login'=>'gsf_login', - 'user_email'=>'gsf_email', - 'user_group'=>'gsf_id_primary_group', - 'user_locale'=>'gsf_iso_lang', - 'user_logout'=>'gsf_logout_on_survey')) + $select->from('gems__staff', array('user_id' => 'gsf_id_user', + 'user_login' => 'gsf_login', + 'user_email' => 'gsf_email', + 'user_group' => 'gsf_id_primary_group', + 'user_locale' => 'gsf_iso_lang', + 'user_logout' => 'gsf_logout_on_survey', + 'user_base_org_id' => 'gsf_id_organization')) ->columns(array('user_name'=>"(concat(coalesce(concat(`gems__staff`.`gsf_first_name`,_utf8' '),_utf8''),coalesce(concat(`gems__staff`.`gsf_surname_prefix`,_utf8' '),_utf8''),coalesce(`gems__staff`.`gsf_last_name`,_utf8'')))")) ->join('gems__groups', 'gsf_id_primary_group = ggp_id_group', array('user_role'=>'ggp_role')) - ->join('gems__organizations', 'gsf_id_organization = gor_id_organization', - array( - 'user_organization_id'=>'gor_id_organization', - 'user_organization_name'=>'gor_name')) ->where('ggp_group_active = 1') ->where('gor_active = 1') ->where('gsf_active = 1') Modified: trunk/library/classes/Gems/User/Organization.php =================================================================== --- trunk/library/classes/Gems/User/Organization.php 2011-11-24 14:25:16 UTC (rev 280) +++ trunk/library/classes/Gems/User/Organization.php 2011-11-24 15:13:38 UTC (rev 281) @@ -216,6 +216,16 @@ } /** + * Get the signature of the organization. + * + * @return string + */ + public function getSignature() + { + return $this->_organizationData['gor_signature']; + } + + /** * Get the style attribute. * * @return string @@ -225,6 +235,16 @@ return $this->_organizationData['gor_style']; } + /** + * Get the welcome message for the organization. + * + * @return string + */ + public function getWelcome() + { + return $this->_organizationData['gor_welcome']; + } + public function invalidateCache() { if ($this->cache) { $cacheId = $this->_getCacheId(); Modified: trunk/library/classes/Gems/User/ProjectUserDefinition.php =================================================================== --- trunk/library/classes/Gems/User/ProjectUserDefinition.php 2011-11-24 14:25:16 UTC (rev 280) +++ trunk/library/classes/Gems/User/ProjectUserDefinition.php 2011-11-24 15:13:38 UTC (rev 281) @@ -68,14 +68,13 @@ public function getUserData($login_name, $organization) { return array( - 'user_id' => 1, - 'user_login' => $login_name, - 'user_name' => $login_name, - 'user_group' => 800, - 'user_role' => 'master', - 'user_style' => 'gems', - 'user_organization_id' => $organization, - 'user_organization_name' => 'SUPER ADMIN', + 'user_id' => 1, + 'user_login' => $login_name, + 'user_name' => $login_name, + 'user_group' => 800, + 'user_role' => 'master', + 'user_style' => 'gems', + 'user_base_org_id' => $organization, 'user_allowed_ip_ranges' => $this->project->getSuperAdminIPRanges(), ); } Modified: trunk/library/classes/Gems/User/StaffUserDefinition.php =================================================================== --- trunk/library/classes/Gems/User/StaffUserDefinition.php 2011-11-24 14:25:16 UTC (rev 280) +++ trunk/library/classes/Gems/User/StaffUserDefinition.php 2011-11-24 15:13:38 UTC (rev 281) @@ -183,12 +183,13 @@ $select = new Zend_Db_Select($this->db); $select->from('gems__user_logins', array('user_login_id' => 'gul_id_user')) ->join('gems__staff', 'gul_login = gsf_login AND gul_id_organization = gsf_id_organization', array( - 'user_login' => 'gsf_login', - 'user_id' => 'gsf_id_user', - 'user_email'=>'gsf_email', - 'user_group'=>'gsf_id_primary_group', - 'user_locale'=>'gsf_iso_lang', - 'user_logout'=>'gsf_logout_on_survey')) + 'user_id' => 'gsf_id_user', + 'user_login' => 'gsf_login', + 'user_email' => 'gsf_email', + 'user_group' => 'gsf_id_primary_group', + 'user_locale' => 'gsf_iso_lang', + 'user_logout' => 'gsf_logout_on_survey', + 'user_base_org_id' => 'gsf_id_organization')) ->columns(array('user_name'=>"(concat(coalesce(concat(`gems__staff`.`gsf_first_name`,_utf8' '),_utf8''),coalesce(concat(`gems__staff`.`gsf_surname_prefix`,_utf8' '),_utf8''),coalesce(`gems__staff`.`gsf_last_name`,_utf8'')))")) ->join('gems__groups', 'gsf_id_primary_group = ggp_id_group', array('user_role'=>'ggp_role', 'user_allowed_ip_ranges' => 'ggp_allowed_ip_ranges')) ->join('gems__organizations', 'gul_id_organization = gor_id_organization', Modified: trunk/library/classes/Gems/User/User.php =================================================================== --- trunk/library/classes/Gems/User/User.php 2011-11-24 14:25:16 UTC (rev 280) +++ trunk/library/classes/Gems/User/User.php 2011-11-24 15:13:38 UTC (rev 281) @@ -94,6 +94,12 @@ protected $session; /** + * + * @var Zend_Translate + */ + protected $translate; + + /** * Required * * @var Gems_User_UserLoader @@ -328,16 +334,42 @@ } /** - * Returns the name of the user definition. + * Returns the original (not the current) organization id of this user. * - * @return string - * NOT NEEDED FOR THE MOMENT / - public function getDefinitionName() + * @return int + */ + public function getBaseOrganizationId() { - return $this->_getVar('__user_definition'); - } // */ + return $this->_getVar('user_base_org_id'); + } /** + * Returns the organization that is currently used by this user. + * + * @return Gems_User_Organization + */ + public function getCurrentOrganization() + { + return $this->userLoader->getOrganization($this->getCurrentOrganizationId()); + } + + /** + * Returns the organization id that is currently used by this user. + * + * @return int + */ + public function getCurrentOrganizationId() + { + $orgId = $this->_getVar('user_organization_id'); + + //If not set, read it from the cookie + if (is_null($orgId)) { + $orgId = Gems_Cookies::getOrganization(Zend_Controller_Front::getInstance()->getRequest()); + } + return $orgId; + } + + /** * Return true if this user has a password. * * @return boolean @@ -358,7 +390,7 @@ return array( 'userlogin' => $this->getLoginName(), 'password' => $password, - 'organization' => $this->getOrganizationId()); + 'organization' => $this->getCurrentOrganizationId()); } /** @@ -401,42 +433,6 @@ } /** - * - * @return Gems_User_Organization - */ - public function getOrganization() - { - return $this->userLoader->getOrganization($this->getOrganizationId()); - } - - /** - * - * @return int - */ - public function getOrganizationId() - { - $orgId = $this->_getVar('user_organization_id'); - - //If not set, read it from the cookie - if (is_null($orgId)) { - $orgId = Gems_Cookies::getOrganization(Zend_Controller_Front::getInstance()->getRequest()); - } - return $orgId; - } - - /** - * Gets the (optional) organization code. - * - * @return string - * NOT NEEDED FOR THE MOMENT / - public function getOrganizationCode() - { - $organizationId = $this->getOrganizationId(); - - return $this->userLoader->getOrganization($organizationId)->getCode(); - } // */ - - /** * Return a password reset key * * @return string @@ -618,7 +614,7 @@ if ($orgs) { // Not to forget: the users own organization - $orgs[] = $this->getOrganizationId(); + $orgs[] = $this->getBaseOrganizationId(); $sql .= "gor_id_organization IN ("; $sql .= implode(', ', $orgs); @@ -653,7 +649,7 @@ if ($this->canSetPassword()) { $checker = $this->userLoader->getPasswordChecker(); - $codes[] = $this->getOrganization()->getCode(); + $codes[] = $this->getCurrentOrganization()->getCode(); $codes[] = $this->getRoles(); $codes[] = $this->_getVar('__user_definition'); @@ -707,44 +703,47 @@ $organization = $this->userLoader->getOrganization($organizationId); } - $oldOrganizationId = $this->getOrganizationId(); + $oldOrganizationId = $this->getCurrentOrganizationId(); - if ($organizationId != $oldOrganizationId) { - $this->_setVar('user_organization_id', $organizationId); + if ($organizationId) { + if ($organizationId != $oldOrganizationId) { + $this->_setVar('user_organization_id', $organizationId); - // Depreciation warning: the settings will be removed in - // version 1.6 at the latest. - $this->_setVar('user_organization_name', $organization->getName()); - $this->_setVar('user_style', $organization->getStyle()); - // End depreciation warning + // Depreciation warning: the settings will be removed in + // version 1.6 at the latest. + $this->_setVar('user_organization_name', $organization->getName()); + $this->_setVar('user_style', $organization->getStyle()); + // End depreciation warning - if ($this->isCurrentUser()) { - // Now update the requestcache to change the oldOrgId to the new orgId - // Don't do it when the oldOrgId doesn't match - $requestCache = $this->session->requestCache; + if ($this->isCurrentUser()) { + // Now update the requestcache to change the oldOrgId to the new orgId + // Don't do it when the oldOrgId doesn't match + if ($requestCache = $this->session->requestCache) { - //Create the list of request cache keys that match an organization ID (to be extended) - $possibleOrgIds = array( - 'gr2o_id_organization', - 'gto_id_organization'); + //Create the list of request cache keys that match an organization ID (to be extended) + $possibleOrgIds = array( + 'gr2o_id_organization', + 'gto_id_organization'); - foreach ($requestCache as $key => $value) { - if (is_array($value)) { - foreach ($value as $paramKey => $paramValue) { - if (in_array($paramKey, $possibleOrgIds)) { - if ($paramValue == $oldOrganizationId) { - $requestCache[$key][$paramKey] = $organizationId; + foreach ($requestCache as $key => $value) { + if (is_array($value)) { + foreach ($value as $paramKey => $paramValue) { + if (in_array($paramKey, $possibleOrgIds)) { + if ($paramValue == $oldOrganizationId) { + $requestCache[$key][$paramKey] = $organizationId; + } + } } } } + $this->session->requestCache = $requestCache; } } - $this->session->requestCache = $requestCache; } - } - if (! Gems_Cookies::setOrganization($organizationId, $this->basepath->getBasePath())) { - throw new Exception($this->_('Cookies must be enabled for this site.')); + if (! Gems_Cookies::setOrganization($organizationId, $this->basepath->getBasePath())) { + throw new Exception($this->translate->_('Cookies must be enabled for this site.')); + } } return $this; Modified: trunk/library/classes/Gems/User/UserLoader.php =================================================================== --- trunk/library/classes/Gems/User/UserLoader.php 2011-11-24 14:25:16 UTC (rev 280) +++ trunk/library/classes/Gems/User/UserLoader.php 2011-11-24 15:13:38 UTC (rev 281) @@ -167,7 +167,7 @@ static $organizations = array(); if (null === $organizationId) { - $organizationId = intval(self::$currentUser->getOrganizationId()); + $organizationId = intval(self::$currentUser->getCurrentOrganizationId()); } if (! isset($organizations[$organizationId])) { @@ -209,7 +209,11 @@ $values['__user_definition'] = $defName; - return $this->_loadClass('User', true, array($values, $definition)); + $user = $this->_loadClass('User', true, array($values, $definition)); + + $user->setCurrentOrganization($organization); + + return $user; } /** Modified: trunk/library/classes/GemsEscort.php =================================================================== --- trunk/library/classes/GemsEscort.php 2011-11-24 14:25:16 UTC (rev 280) +++ trunk/library/classes/GemsEscort.php 2011-11-24 15:13:38 UTC (rev 281) @@ -376,7 +376,6 @@ * -- user_role * -- user_locale * -- user_organization_id - * -- user_organization_name * * Use $this->session to access afterwards * @@ -538,19 +537,21 @@ */ protected function _layoutContact(array $args = null) { - $menuItem = $this->menu->find(array('controller' => 'contact', 'action' => 'index')); + if ($this->menu instanceof Gems_Menu) { + $menuItem = $this->menu->find(array('controller' => 'contact', 'action' => 'index')); - if ($menuItem) { - $contactDiv = MUtil_Html::create()->div( - $args, - array('id' => 'contact')); // tooltip - $contactDiv->a($menuItem->toHRefAttribute(), $menuItem->get('label')); + if ($menuItem) { + $contactDiv = MUtil_Html::create()->div( + $args, + array('id' => 'contact')); // tooltip + $contactDiv->a($menuItem->toHRefAttribute(), $menuItem->get('label')); - $ul = $menuItem->toUl(); - $ul->class = 'dropdownContent tooltip'; - $contactDiv->append($ul); + $ul = $menuItem->toUl(); + $ul->class = 'dropdownContent tooltip'; + $contactDiv->append($ul); - return $contactDiv; + return $contactDiv; + } } } @@ -798,7 +799,8 @@ $user = $this->getLoader()->getCurrentUser(); if ($orgs = $user->getAllowedOrganizations()) { // Organization switcher - $orgSwitch = MUtil_Html::create('div', array('id' => 'organizations')); + $orgSwitch = MUtil_Html::create('div', array('id' => 'organizations')); + $currentId = $user->getCurrentOrganizationId(); $currentUri = base64_encode($this->view->url()); $url = $this->view->getHelper('url')->url(array('controller' => 'organization', 'action' => 'change-ui'), null, true); @@ -809,7 +811,7 @@ $select = $formDiv->select(array('name' => "org", 'onchange' => "javascript:this.form.submit();")); foreach ($orgs as $id => $org) { $selected = ''; - if ($id == $user->getOrganizationId()) { + if ($id == $currentId) { $selected = array('selected' => "selected"); } $select->option(array('value' => $id), $org, $selected); @@ -902,7 +904,8 @@ { $div = MUtil_Html::create()->div($args, array('id' => 'version')); $version = $this->loader->getVersions()->getVersion(); - if ($item = $this->menu->findFirst(array('controller'=>'project-information', 'action'=>'changelog'))->toHRefAttribute()) { + if (($this->menu instanceof Gems_Menu) && + ($item = $this->menu->findFirst(array('controller'=>'project-information', 'action'=>'changelog'))->toHRefAttribute())) { $link = MUtil_Html::create()->a($version, $item); } else { $link = $version; @@ -1073,7 +1076,7 @@ */ public function getCurrentOrganization() { - return $this->getLoader()->getCurrentUser()->getOrganizationId(); + return $this->getLoader()->getCurrentUser()->getCurrentOrganizationId(); } /** Modified: trunk/library/classes/MUtil/Controller/Action.php =================================================================== --- trunk/library/classes/MUtil/Controller/Action.php 2011-11-24 14:25:16 UTC (rev 280) +++ trunk/library/classes/MUtil/Controller/Action.php 2011-11-24 15:13:38 UTC (rev 281) @@ -4,7 +4,7 @@ /** * Copyright (c) 2011, Erasmus MC * All rights reserved. - * + * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright @@ -15,7 +15,7 @@ * * Neither the name of Erasmus MC nor the * names of its contributors may be used to endorse or promote products * derived from this software without specific prior written permission. - * + * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE @@ -71,7 +71,7 @@ * @var MUtil_Snippets_SnippetLoader */ protected $snippetLoader; - + /** * The current html/head/title for this page. * @@ -131,7 +131,7 @@ * @param array $urlOptions Url parts * @param boolean $reset Use default module, action and controller instead of current when not specified in $urlOptions * @param string $routeName - * @param boolean $encode + * @param boolean $encode */ protected function _reroute(array $urlOptions = array(), $reset = false, $routeName = null, $encode = true) { @@ -172,7 +172,7 @@ { $extraSource = MUtil_Ra::pairs(func_get_args(), 1); $snippet = $this->getSnippet($filename, $extraSource); - + if ($snippet->hasHtmlOutput()) { $this->html[] = $snippet; return $snippet; @@ -202,7 +202,7 @@ if ($snippet->hasHtmlOutput()) { $this->html[] = $snippet; $results[$filename] = $snippet; - + } elseif ($snippet->getRedirectRoute()) { $snippet->redirectRoute(); return false; @@ -263,12 +263,12 @@ } else { $extraSourceParameters = array(); } - + $loader = $this->getSnippetLoader(); - + return $loader->getSnippet($filename, $extraSourceParameters); } - + /** * Returns a source of values for snippets. * @@ -285,7 +285,7 @@ /** * Returns the current html/head/title for this page. - * + * * If the title is an array the seperator concatenates the parts. * * @param string $separator @@ -371,7 +371,7 @@ $this->_helper->viewRenderer->setScriptAction('html-view'); } } - + /** * Stub for overruling default snippet loader initiation. */ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |