Skip to content

Commit

Permalink
*5111* update to role listbuilders (consolidate AuthorRole, Managerial
Browse files Browse the repository at this point in the history
  • Loading branch information
jalperin committed Apr 10, 2010
1 parent 6d75bbc commit d966f38
Show file tree
Hide file tree
Showing 43 changed files with 661 additions and 1,033 deletions.
16 changes: 6 additions & 10 deletions classes/admin/form/PressSiteSettingsForm.inc.php
Expand Up @@ -146,21 +146,17 @@ function execute() {
$publicationFormatDao =& DAORegistry::getDAO('PublicationFormatDAO');
$publicationFormatDao->installDefaults($pressId, $installedLocales);

// Install default roles
$flexibleRoleDao =& DAORegistry::getDAO('FlexibleRoleDAO');
$flexibleRoleDao->installDefaults($pressId, $installedLocales);
// Install default user groups
$userGroupDao =& DAORegistry::getDAO('UserGroupDAO');
$userGroupDao->installSettings($pressId, 'registry/userGroups.xml');

// Make the site administrator the press manager of newly created presses
$sessionManager =& SessionManager::getManager();
$userSession =& $sessionManager->getUserSession();
if ($userSession->getUserId() != null && $userSession->getUserId() != 0 && !empty($pressId)) {
$roleDao =& DAORegistry::getDAO('RoleDAO');
$role = new Role();
$role->setPressId($pressId);
$role->setUserId($userSession->getUserId());
$role->setRoleId(ROLE_ID_PRESS_MANAGER);

$roleDao->insertRole($role);
// get the default site admin user group
$managerUserGroup =& $userGroupDao->getDefaultByRoleId($pressId, ROLE_ID_PRESS_MANAGER);
$userGroupDao->assignUserToGroup($userSession->getUserId(), $managerUserGroup->getId());
}

// Install default press settings
Expand Down
2 changes: 1 addition & 1 deletion classes/author/form/submit/AuthorSubmitStep1Form.inc.php
Expand Up @@ -48,7 +48,7 @@ function display() {
// to submit to series flagged as "editor-only" for submissions.
// Otherwise, display only series they are allowed to submit to.
$roleDao =& DAORegistry::getDAO('RoleDAO');
$isEditor = $roleDao->roleExists($press->getId(), $user->getId(), ROLE_ID_EDITOR) || $roleDao->roleExists($press->getId(), $user->getId(), ROLE_ID_SERIES_EDITOR);
$isEditor = $roleDao->userHasRole($press->getId(), $user->getId(), ROLE_ID_EDITOR) || $roleDao->userHasRole($press->getId(), $user->getId(), ROLE_ID_SERIES_EDITOR);

$seriesOptions = array('0' => Locale::translate('author.submit.selectSeries')) + $seriesDao->getTitlesByPressId($press->getId());
$templateMgr->assign('seriesOptions', $seriesOptions);
Expand Down
26 changes: 13 additions & 13 deletions classes/core/PageRouter.inc.php
Expand Up @@ -27,36 +27,36 @@ function getCacheablePages() {
}

/**
* Redirect to user home page (or the role home page if the user has one role).
* Redirect to user home page (or the user group home page if the user has one user group).
* @param $request PKPRequest the request to be routed
*/
function redirectHome(&$request) {
$roleDao =& DAORegistry::getDAO('RoleDAO');
$userGroupDao =& DAORegistry::getDAO('UserGroupDAO');
$user = $request->getUser();
$userId = $user->getId();

if ($press =& $this->getContext($request, 1)) {
// The user is in the press context, see if they have one role only
$roles =& $roleDao->getRolesByUserId($userId, $press->getId());
if(count($roles) == 1) {
$role = array_shift($roles);
if ($role->getRoleId() == ROLE_ID_READER) $request->redirect(null, 'index');
$request->redirect(null, $role->getRolePath());
$userGroups =& $userGroupDao->getByUserId($userId, $press->getId());
if($userGroups->getCount() == 1) {
$userGroup =& $userGroups->next();
if ($userGroup->getRoleId() == ROLE_ID_READER) $request->redirect(null, 'index');
$request->redirect(null, $userGroup->getPath());
} else {
$request->redirect(null, 'user');
}
} else {
// The user is at the site context, check to see if they are
// only registered in one place w/ one role
$roles = $roleDao->getRolesByUserId($userId);
$userGroups =& $userGroupDao->getByUserId($userId);

if(count($roles) == 1) {
if($userGroups->getCount() == 1) {
$pressDao =& DAORegistry::getDAO('PressDAO');
$role = array_shift($roles);
$press = $pressDao->getPress($role->getId());
$userGroup =& $userGroups->next();
$press =& $pressDao->getPress($userGroups->getPressId());
if (!isset($press)) $request->redirect('index', 'user');;
if ($role->getRoleId() == ROLE_ID_READER) $request->redirect(null, 'index');
$request->redirect($press->getPath(), $role->getRolePath());
if ($userGroup->getRoleId() == ROLE_ID_READER) $request->redirect(null, 'index');
$request->redirect($press->getPath(), $userGroup->getPath());
} else $request->redirect('index', 'user');
}
}
Expand Down
10 changes: 5 additions & 5 deletions classes/handler/validation/HandlerValidatorRoles.inc.php
Expand Up @@ -15,15 +15,15 @@

class HandlerValidatorRoles extends HandlerValidator {
var $roles;

var $all;

/**
* Constructor.
* @param $handler Handler the associated form
* @param $roles array of role id's
* @param $roles array of role id's
* @param $all bool flag for whether all roles must exist or just 1
*/
*/
function HandlerValidatorRoles(&$handler, $redirectLogin = true, $message = null, $additionalArgs = array(), $roles, $all = false) {
parent::HandlerValidator($handler, $redirectLogin, $message, $additionalArgs);
$this->roles = $roles;
Expand All @@ -46,9 +46,9 @@ function isValid() {
$returner = true;
foreach ( $this->roles as $roleId ) {
if ( $roleId == ROLE_ID_SITE_ADMIN ) {
$exists = $roleDao->roleExists(0, $user->getId(), $roleId);
$exists = $roleDao->userHasRole(0, $user->getId(), $roleId);
} else {
$exists = $roleDao->roleExists($pressId, $user->getId(), $roleId);
$exists = $roleDao->userHasRole($pressId, $user->getId(), $roleId);
}
if ( !$this->all && $exists) return true;
$returner = $returner && $exists;
Expand Down
10 changes: 5 additions & 5 deletions classes/i18n/Locale.inc.php
Expand Up @@ -67,7 +67,7 @@ function getSupportedFormLocales() {
/**
* Return the key name of the user's currently selected locale (default
* is "en_US" for U.S. English).
* @return string
* @return string
*/
function getLocale() {
static $currentLocale;
Expand Down Expand Up @@ -178,8 +178,8 @@ function installLocale($locale) {
$publicationFormatDao =& DAORegistry::getDAO('PublicationFormatDAO');
$publicationFormatDao->installLocale($locale);

$flexibleRoleDao =& DAORegistry::getDAO('FlexibleRoleDAO');
$flexibleRoleDao->installLocale($locale);
$userGroupDao =& DAORegistry::getDAO('UserGroupDAO');
$userGroupDao->installLocale($locale);
}

/**
Expand All @@ -195,8 +195,8 @@ function uninstallLocale($locale) {
$publicationFormatDao =& DAORegistry::getDAO('PublicationFormatDAO');
$publicationFormatDao->uninstallLocale($locale);

$flexibleRoleDao =& DAORegistry::getDAO('FlexibleRoleDAO');
$flexibleRoleDao->uninstallLocale($locale);
$userGroupDao =& DAORegistry::getDAO('UserGroupDAO');
$userGroupDao->deleteSettingsByLocale($locale);
}

/**
Expand Down
40 changes: 27 additions & 13 deletions classes/install/Install.inc.php
Expand Up @@ -34,7 +34,7 @@ class Install extends PKPInstall {
* @see install.form.InstallForm for the expected parameters
* @param $params array installer parameters
* @param $descriptor string descriptor path
* @param $isPlugin boolean true iff a plugin is being installed
* @param $isPlugin boolean true iff a plugin is being installed
*/
function Install($params, $descriptor = 'install.xml', $isPlugin = false) {
parent::PKPInstall($descriptor, $params, $isPlugin);
Expand Down Expand Up @@ -80,7 +80,7 @@ function createData() {
}
}
} else {
// Add initial site data
// Add initial site data

$locale = $this->getParam('locale');
$siteDao =& DAORegistry::getDAO('SiteDAO', $this->dbconn);
Expand Down Expand Up @@ -119,29 +119,43 @@ function createData() {
$this->setError(INSTALLER_ERROR_DB, $this->dbconn->errorMsg());
return false;
}
$roleDao =& DAORegistry::getDao('RoleDAO', $this->dbconn);
$role = new Role();
$role->setPressId(0);
$role->setUserId($user->getId());
$role->setRoleId(ROLE_ID_SITE_ADMIN);
if (!$roleDao->insertRole($role)) {

// Create an admin user group
$userGroupDao =& DAORegistry::getDao('UserGroupDAO', $this->dbconn);
$adminUserGroup = new UserGroup();
$adminUserGroup->setRoleId(ROLE_ID_SITE_ADMIN);
$adminUserGroup->setPressId(0);
$adminUserGroup->setDefault(true);
foreach ($this->installedLocales as $locale) {
$name = Locale::translate('default.roles.admin', $locale);
$namePlural = Locale::translate('default.roles.admins', $locale);
$adminUserGroup->setSetting('name', $name, $locale);
$adminUserGroup->setSetting('namePlural', $namePlural, $locale);
}
if (!$userGroupDao->insertUserGroup($adminUserGroup)) {
$this->setError(INSTALLER_ERROR_DB, $this->dbconn->errorMsg());
return false;
}

// put the installer into this user group
if (!$userGroupDao->assignUserToGroup($user->getId(), $adminUserGroup->getId())) {
$this->setError(INSTALLER_ERROR_DB, $this->dbconn->errorMsg());
return false;
}

// Add initial plugin data to versions table
$versionDao =& DAORegistry::getDAO('VersionDAO');
$versionDao =& DAORegistry::getDAO('VersionDAO');
import('site.VersionCheck');
$categories = PluginRegistry::getCategories();
foreach ($categories as $category) {
PluginRegistry::loadCategory($category, true);
$plugins = PluginRegistry::getPlugins($category);
foreach ($plugins as $plugin) {
$versionFile = $plugin->getPluginPath() . '/version.xml';

if (FileManager::fileExists($versionFile)) {
$versionInfo =& VersionCheck::parseVersionXML($versionFile);
$pluginVersion = $versionInfo['version'];
$pluginVersion = $versionInfo['version'];
$pluginVersion->setCurrent(1);
$versionDao->insertVersion($pluginVersion);
} else {
Expand All @@ -158,7 +172,7 @@ function createData() {
}
}
}

}

return true;
Expand Down
4 changes: 2 additions & 2 deletions classes/manager/form/AnnouncementForm.inc.php
Expand Up @@ -67,9 +67,9 @@ function execute() {

// Send a notification to associated users
import('notification.NotificationManager');
$roleDao =& DAORegistry::getDAO('RoleDAO');
$userGroupDao =& DAORegistry::getDAO('RoleAssignmentDAO');
$notificationUsers = array();
$allUsers = $roleDao->getUsersByPressId($pressId);
$allUsers = $userGroupDao->getUsersByPressId($pressId);
while (!$allUsers->eof()) {
$user =& $allUsers->next();
$notificationUsers[] = array('id' => $user->getId());
Expand Down
60 changes: 26 additions & 34 deletions classes/manager/form/UserManagementForm.inc.php
Expand Up @@ -38,7 +38,7 @@ function UserManagementForm($userId = null) {
$this->addCheck(new FormValidator($this, 'username', 'required', 'user.profile.form.usernameRequired'));
$this->addCheck(new FormValidatorCustom($this, 'username', 'required', 'user.register.form.usernameExists', array(DAORegistry::getDAO('UserDAO'), 'userExistsByUsername'), array($this->userId, true), true));
$this->addCheck(new FormValidatorAlphaNum($this, 'username', 'required', 'user.register.form.usernameAlphaNumeric'));

if (!Config::getVar('security', 'implicit_auth')) {
$this->addCheck(new FormValidator($this, 'password', 'required', 'user.profile.form.passwordRequired'));
$this->addCheck(new FormValidatorLength($this, 'password', 'required', 'user.register.form.passwordLengthTooShort', '>=', $site->getMinPasswordLength()));
Expand All @@ -59,17 +59,16 @@ function UserManagementForm($userId = null) {
/**
* Display the form.
*/
function display() {
function display(&$args, &$request) {
$userDao =& DAORegistry::getDAO('UserDAO');
$templateMgr =& TemplateManager::getManager();
$site =& Request::getSite();
$press =& Request::getPress();
$site =& $request->getSite();

$templateMgr->assign('genderOptions', $userDao->getGenderOptions());
$templateMgr->assign('minPasswordLength', $site->getMinPasswordLength());
$templateMgr->assign('source', Request::getUserVar('source'));
$templateMgr->assign('userId', $this->userId);

if (isset($this->userId)) {
$user =& $userDao->getUser($this->userId);
$templateMgr->assign('username', $user->getUsername());
Expand All @@ -78,28 +77,28 @@ function display() {
$helpTopicId = 'press.users.createNewUser';
}

$flexibleRoleDao =& DAORegistry::getDAO('FlexibleRoleDAO');
$press =& $request->getPress();
$userGroupDao =& DAORegistry::getDAO('UserGroupDAO');

$options = array();
$options[''] = Locale::translate('manager.people.doNotEnroll');

if (Validation::isPressManager()) {
$roles =& $flexibleRoleDao->getEnabledByPressId($press->getId());
$userGroups =& $userGroupDao->getByPressId($press->getId());

foreach ($roles as $role) {
$options[$role->getId()] = $role->getLocalizedName();
foreach ($userGroups->toArray() as $userGroup) {
$options[$userGroup->getId()] = $userGroup->getLocalizedName();
}
} else {
$flexibleRole =& $flexibleRoleDao->getByRoleId(ROLE_ID_READER, $press->getId());
$options[$flexibleRole->getId()] = $flexibleRole->getLocalizedName();
$userGroup =& $userGroupDao->getDefaultByRoleId($press->getId(), ROLE_ID_READER);
$options[$userGroup->getId()] = $userGroup->getLocalizedName();
}

$templateMgr->assign('roleOptions', $options);
$templateMgr->assign('userGroupOptions', $options);

// Send implicitAuth setting down to template
$templateMgr->assign('implicitAuth', Config::getVar('security', 'implicit_auth'));

$site =& Request::getSite();

$templateMgr->assign('availableLocales', $site->getSupportedLocaleNames());

$templateMgr->assign('helpTopicId', $helpTopicId);
Expand All @@ -123,7 +122,7 @@ function display() {
/**
* Initialize form data from current user profile.
*/
function initData() {
function initData(&$args, &$request) {
if (isset($this->userId)) {
$userDao =& DAORegistry::getDAO('UserDAO');
$user =& $userDao->getUser($this->userId);
Expand Down Expand Up @@ -158,10 +157,10 @@ function initData() {
}
if (!isset($this->userId)) {
$roleDao =& DAORegistry::getDAO('RoleDAO');
$flexibleRoleId = Request::getUserVar('flexibleRoleId');
$userGroupId = $request->getUserVar('userGroupId');

$this->_data = array(
'enrollAs' => array($flexibleRoleId)
'enrollAs' => array($userGroupId)
);
}
}
Expand Down Expand Up @@ -219,9 +218,9 @@ function getLocaleFieldNames() {
/**
* Register a new user.
*/
function execute() {
function execute(&$args, &$request) {
$userDao =& DAORegistry::getDAO('UserDAO');
$press =& Request::getPress();
$press =& $request->getPress();

if (isset($this->userId)) {
$user =& $userDao->getUser($this->userId);
Expand Down Expand Up @@ -251,7 +250,7 @@ function execute() {
$user->setMustChangePassword($this->getData('mustChangePassword') ? 1 : 0);
$user->setAuthId((int) $this->getData('authId'));

$site =& Request::getSite();
$site =& $request->getSite();
$availableLocales = $site->getSupportedLocales();

$locales = array();
Expand Down Expand Up @@ -310,22 +309,15 @@ function execute() {
$isManager = Validation::isPressManager();

if (!empty($this->_data['enrollAs'])) {
$roleDao =& DAORegistry::getDAO('RoleDAO');
$flexibleRoleDao =& DAORegistry::getDAO('FlexibleRoleDAO');
foreach ($this->getData('enrollAs') as $flexibleRoleId) {
$userGroupDao =& DAORegistry::getDAO('UserGroupDAO');

foreach ($this->getData('enrollAs') as $userGroupId) {
// Enroll new user into an initial role
$flexibleRole =& $flexibleRoleDao->getById($flexibleRoleId);
$roleId = $flexibleRole ? $flexibleRole->getRoleId() : 0;
if (!$isManager && $roleId != ROLE_ID_READER) continue;
if ($roleId != null) {
$role = new Role();
$role->setPressId($press->getId());
$role->setUserId($userId);
$role->setRoleId($roleId);
$role->setFlexibleRoleId($flexibleRoleId);
$roleDao->insertRole($role);
$userGroup =& $userGroupDao->getById($userGroupId);
if (!$isManager && $userGroup->getRoleId() != ROLE_ID_READER) continue;
if ($userGroupId != null) {
$userGroupDao->assignUserToGroup($userId, $userGroupId);
}
unset($flexibleRole);
}
}

Expand Down

0 comments on commit d966f38

Please sign in to comment.