public function init() { $this->setName("Edit concept"); $this->setMethod('Post'); $this->_isProposalOnly = !(OpenSKOS_Db_Table_Users::fromIdentity()->isAllowed('editor.concepts', 'full-create') || OpenSKOS_Db_Table_Users::fromIdentity()->isAllowed('editor.concepts', 'edit')); $this->buildHeader()->buildTabsControl()->buildLanguageTabs()->buildSchemeTabs(); }
public function clearHistoryAction() { $user = OpenSKOS_Db_Table_Users::fromIdentity(); if (null !== $user) { $user->clearUserHistory(); } $this->getHelper('json')->sendJson(array('status' => 'ok')); }
/** * Sets the api key parameter for the api requests. * * @return OpenSKOS_Http_Client_Api */ protected function assignApiKey() { $user = OpenSKOS_Db_Table_Users::fromIdentity(); if (null === $user) { throw new OpenSKOS_Http_Client_Api_Exception('User not found. Needed for request to the api.'); } $this->setParameterGet('key', $user->apikey); return $this; }
public function removeAction() { $user = OpenSKOS_Db_Table_Users::fromIdentity(); if (null === $user) { throw new Zend_Controller_Action_Exception('User not found', 404); } $user->removeConceptFromSelection($this->getRequest()->getPost('uuid')); $selection = $user->getConceptsSelection(); $this->getHelper('json')->sendJson(array('status' => 'ok', 'result' => $this->_prepareSelectionData($selection))); }
public function editAction() { $this->_requireAccess('editor.collections', 'manage'); $collection = $this->_getCollection(); if (!OpenSKOS_Db_Table_Users::fromIdentity()->isAllowed('editor.delete-all-concepts-in-collection', null)) { $collection->getUploadForm()->removeElement('delete-before-import'); } $this->view->assign('collection', $collection); $this->view->assign('jobs', $collection->getJobs()); $this->view->assign('harvestjobs', $collection->getJobs(OpenSKOS_Db_Table_Row_Job::JOB_TASK_HARVEST)); $this->view->assign('max_upload_size', Zend_Controller_Front::getInstance()->getParam('bootstrap')->getOption('max_upload_size')); }
public function indexAction() { $user = OpenSKOS_Db_Table_Users::requireFromIdentity(); $apiClient = new Editor_Models_ApiClient(); $this->view->assign('conceptSchemes', $apiClient->getAllConceptSchemeUriTitlesMap()); $this->view->assign('conceptSchemesId', $apiClient->getConceptSchemeMap('uri', 'uuid')); $this->view->assign('disableSearchProfileChanging', $user->disableSearchProfileChanging); $this->view->assign('exportForm', Editor_Forms_Export::getInstance()); $this->view->assign('deleteForm', Editor_Forms_Delete::getInstance()); $this->view->assign('changeStatusForm', Editor_Forms_ChangeStatus::getInstance()); $this->view->assign('historyData', $user->getUserHistory()); $this->view->assign('searchForm', Editor_Forms_Search::getInstance()); }
public function preDispatch(Zend_Controller_Request_Abstract $request) { if (!in_array($request->getModuleName(), $this->modules)) { return; } $authInstance = Zend_Auth::getInstance(); //SAML login: if (isset($_SERVER['eppn'])) { //lookup user with this eduPersonPrincipalName: $model = new OpenSKOS_Db_Table_Users(); $user = $model->fetchRow($model->select()->where('eppn=?', $_SERVER['eppn'])); if (null !== $user) { if ($user->active != 'Y') { Zend_Auth::getInstance()->clearIdentity(); Zend_Session::forgetMe(); Zend_Controller_Action_HelperBroker::getStaticHelper('FlashMessenger')->setNamespace('error')->addMessage(_('Your account is blocked.')); Zend_Controller_Action_HelperBroker::getStaticHelper('redirector')->direct('index', 'index', 'website'); } $login = new Editor_Models_Login(); $login->getStorage()->write($user); return; } } $resource = $request->getControllerName(); $actionName = $request->getActionName(); if ($authInstance->hasIdentity()) { if ($authInstance->getIdentity()->active != 'Y') { Zend_Auth::getInstance()->clearIdentity(); Zend_Session::forgetMe(); Zend_Controller_Action_HelperBroker::getStaticHelper('FlashMessenger')->setNamespace('error')->addMessage(_('Your account is blocked.')); Zend_Controller_Action_HelperBroker::getStaticHelper('redirector')->direct('index', 'index', 'website'); } } else { if ($request->getControllerName() != 'login') { Zend_Controller_Action_HelperBroker::getStaticHelper('redirector')->direct('index', 'login', 'editor'); } } }
/** * Check does the user have access to the specified resource with the specified privilege. * * @param string $resource * @param string $privilege, optional, Default: null * @param string $responseType, optional, Default: RESPONSE_TYPE_HTML. One of RESPONSE_TYPE_HTML, RESPONSE_TYPE_PARTIAL_HTML or RESPONSE_TYPE_JSON. */ protected function _requireAccess($resource, $privilege = null, $responseType = self::RESPONSE_TYPE_HTML) { if (false === OpenSKOS_Db_Table_Users::fromIdentity()->isAllowed($resource, $privilege)) { $message = _('Your access level does not allow you access to') . ' "' . $resource . '" - "' . $privilege . '".'; switch ($responseType) { case self::RESPONSE_TYPE_JSON: $this->getHelper('json')->sendJson(array('status' => 'accessDenied', 'message' => $message)); break; case self::RESPONSE_TYPE_PARTIAL_HTML: $this->getHelper('FlashMessenger')->setNamespace('error')->addMessage($message); $redirectToUrl = $this->getHelper('url')->url(array('module' => 'editor'), null, true); $redirectorJs = '<script type="text/javascript">window.location.href="' . $redirectToUrl . '";</script>'; $this->getResponse()->setBody($redirectorJs)->sendResponse(); exit; break; case self::RESPONSE_TYPE_HTML: default: $this->getHelper('FlashMessenger')->setNamespace('error')->addMessage($message); $this->_helper->redirector('index', 'index', 'editor'); break; } } }
/** * @return Editor_Forms_SearchOptions */ protected function buildUserInteraction() { $modelUsers = new OpenSKOS_Db_Table_Users(); $users = $modelUsers->fetchAll($modelUsers->select()->where('tenant=?', $this->_getCurrentTenant()->code)); $roles = OpenSKOS_Db_Table_Users::getUserRoles(); $rolesOptions = array_combine($roles, $roles); $userData = array(); foreach ($users as $user) { $userData[$user->id] = $user->name; } $userInteractionTypes = array(); if (isset($this->_searchOptions['interactiontypes'])) { $userInteractionTypes = $this->_searchOptions['interactiontypes']; } $this->addElement('hidden', 'userInteractionTypeLabel', array('label' => _('Created, modified or approved'), 'disabled' => true)); $this->addElement('multiCheckbox', 'userInteractionType', array('label' => '', 'multiOptions' => $userInteractionTypes)); $this->addElement('multiselect', 'interactionByRoles', array('label' => _('Roles'), 'multiOptions' => $rolesOptions)); $this->addElement('multiselect', 'interactionByUsers', array('label' => _('Users'), 'multiOptions' => $userData)); $this->buildDateInput('interaction'); $this->addDisplayGroup(array('userInteractionType', 'interactionByRoles', 'interactionByUsers', 'interactionDateFrom', 'interactionDateTo'), 'interaction', array('legend' => _('Created, modified or approved'), 'disableDefaultDecorators' => true, 'decorators' => array('FormElements', array('HtmlTag', array('tag' => 'div', 'id' => 'interaction'))))); return $this; }
/** * @return Editor_Forms_Search */ public static function factory() { // Gets the user which should be used for getting search options. $request = Zend_Controller_Front::getInstance()->getRequest(); if (null !== $request->getPost('user')) { $model = new OpenSKOS_Db_Table_Users(); $userForSearch = $model->find($request->getPost('user'))->current(); if (null === $userForSearch) { throw new Zend_Controller_Action_Exception('User not found', 404); } } else { $userForSearch = OpenSKOS_Db_Table_Users::requireFromIdentity(); } return new Editor_Forms_Search(array('UserForSearch' => $userForSearch)); }
} return $statuses; }; // Profiles $profilesCounter = 0; $profilesModel = new OpenSKOS_Db_Table_SearchProfiles(); foreach ($profilesModel->fetchAll() as $profile) { $searchOptions = unserialize($profile->searchOptions); if (in_array('expired', $searchOptions['status'])) { $searchOptions['status'] = $replaceExpired($searchOptions['status']); $profile->setSearchOptions($searchOptions); $profile->save(); $profilesCounter++; } } echo $profilesCounter . ' profiles were updated.' . "\n"; // Users $usersCounter = 0; $usersModel = new OpenSKOS_Db_Table_Users(); foreach ($usersModel->fetchAll() as $user) { if ($user->searchOptions !== null) { $searchOptions = unserialize($user->searchOptions); if (isset($searchOptions['status']) && in_array('expired', $searchOptions['status'])) { $searchOptions['status'] = $replaceExpired($searchOptions['status']); $user->searchOptions = serialize($searchOptions); $user->save(); $usersCounter++; } } } echo $usersCounter . ' users were updated.' . "\n";
/** * Gets an instance of the api client. Sets the api client tenant. * * return Editor_Models_ApiClient */ protected function _getApiClientInstance() { if (null === $this->_apiClient) { $user = OpenSKOS_Db_Table_Users::requireById($this->get('userId')); $tenant = OpenSKOS_Db_Table_Tenants::fromCode($user->tenant); $this->_apiClient = Editor_Models_ApiClient::factory(); $this->_apiClient->setTenant($tenant); } return $this->_apiClient; }
public function didIBlockMyselfFromTheEditor() { $id = Zend_Auth::getInstance()->getIdentity()->id; if ($id != $this->id) { return false; } return !OpenSKOS_Db_Table_Users::isEditorAllowed($this->type, $this->role); }
/** * Builds query for search by users and by users from specific role. * All the users from the specified role will be added with OR to the query of users. * If the final query of users includes all users - an empty string is returned - the query should not be applied. * * @param string $field The field to search by. * @param string $usersOption The option in $this->_searchOptions to use as users to search by * @param string $usersRoleOption The option in $this->_searchOptions to use as role to search by * @return string */ protected function _buildUsersAndUserRolesQuery($field, $usersOption, $usersRoleOption, $allUsers) { $searchUsers = array(); if (isset($this->_searchOptions[$usersRoleOption]) && !empty($this->_searchOptions[$usersRoleOption])) { $modelUsers = new OpenSKOS_Db_Table_Users(); $usersByRole = $modelUsers->fetchAll($modelUsers->select()->where('tenant=?', $this->_tenant->code)->where('role IN (?)', $this->_searchOptions[$usersRoleOption])->group('id')); foreach ($usersByRole as $user) { $searchUsers[] = $user->id; } } if (isset($this->_searchOptions[$usersOption]) && !empty($this->_searchOptions[$usersOption])) { $searchUsers = array_merge($searchUsers, $this->_searchOptions[$usersOption]); $searchUsers = array_unique($searchUsers); } $query = ''; // If not all users are selected - adds each of them to the query. if (count($allUsers) != count($searchUsers)) { foreach ($searchUsers as $user) { $query .= !empty($query) ? ' OR ' : ''; $query .= $field . ':' . $user; if ($field == 'created_by') { $query .= ' OR '; $query .= 'dcterms_creator:"' . $allUsers[$user] . '"'; } } } return $query; }
if (null === $OPTS->email) { fwrite(STDERR, "missing required `email` argument\n"); exit(1); } if (null === $OPTS->password) { $password = OpenSKOS_Db_Table_Users::pwgen(8); } else { $password = $OPTS->password; } try { $model->createRow(array('code' => $OPTS->code, 'name' => $OPTS->name))->save(); } catch (Zend_Db_Exception $e) { fwrite(STDERR, $e->getMessage() . "\n"); exit(2); } $model = new OpenSKOS_Db_Table_Users(); $model->createRow(array('email' => $OPTS->email, 'name' => $OPTS->name, 'password' => new Zend_Db_Expr('MD5(' . $model->getAdapter()->quote($password) . ')'), 'tenant' => $OPTS->code, 'eppn' => $OPTS->code, 'type' => OpenSKOS_Db_Table_Users::USER_TYPE_BOTH, 'role' => OpenSKOS_Db_Table_Users::USER_ROLE_ADMINISTRATOR))->save(); fwrite(STDOUT, 'A tenant has been created with this user account:' . "\n"); fwrite(STDOUT, " - code: {$OPTS->code}\n"); fwrite(STDOUT, " - login: {$OPTS->email}\n"); fwrite(STDOUT, " - password: {$password}\n"); break; case 'delete': $tenant = $model->find($OPTS->code)->current(); if (null === $tenant) { fwrite(STDERR, "Tenant `{$OPTS->code} does not exists\n"); exit(2); } $tenant->delete(); break; default:
/** * @return OpenSKOS_Db_Table_Row_User */ protected function _getUser() { $model = new OpenSKOS_Db_Table_Users(); if (null === ($id = $this->getRequest()->getParam('user'))) { //create a new user: $user = $model->createRow(array('tenant' => $this->_tenant->code)); } else { $user = $model->find((int) $id)->current(); if (null === $user) { $this->getHelper('FlashMessenger')->setNamespace('error')->addMessage(_('User not found')); $this->_helper->redirector('index'); } } if ($user->tenant != $this->_tenant->code) { $this->getHelper('FlashMessenger')->setNamespace('error')->addMessage(_('You are not allowed to edit this user.')); $this->_helper->redirector('index'); } return $user; }
public function setOptionsAction() { $form = Editor_Forms_SearchOptions::getInstance(); $request = $this->getRequest(); if (!$this->getRequest()->isPost()) { return; } if (!$form->isValid($this->getRequest()->getPost())) { return $this->_forward('show-form'); } $user = OpenSKOS_Db_Table_Users::requireFromIdentity(); // Reset defaults if ((bool) $this->getRequest()->getParam('resetDefaults', false)) { $defaultProfile = $user->getFirstDefaultSearchProfile(); if ($defaultProfile !== null) { return $this->_forward('show-form', 'search', 'editor', array('searchProfileId' => $defaultProfile->id)); } else { return $this->_forward('show-form', 'search', 'editor', array('searchProfileId' => '')); } } // Switch profile. if ((bool) $this->getRequest()->getParam('switchProfile', false)) { return $this->_forward('show-form', 'search', 'editor'); } // Save options or profile $options = Editor_Forms_SearchOptions::formValues2Options($this->getRequest()->getPost()); $profilesModel = new OpenSKOS_Db_Table_SearchProfiles(); // Save profile as new one. if ((bool) $this->getRequest()->getParam('saveAs', false)) { $profileName = $this->getRequest()->getParam('searchProfileNameSaveAs', ''); if (empty($profileName)) { $form->getElement('searchProfileNameSaveAs')->addError(_('Please fill a profile name.')); return $this->_forward('show-form'); } $newProfileId = $profilesModel->addNew($profileName, $options, $user->id, $user->tenant); // Switch the form to the new profile return $this->_forward('show-form', 'search', 'editor', array('searchProfileId' => $newProfileId, 'switchProfile' => true, 'reInitForm' => true)); } // Save or delete existing profile. $profileId = intval($this->getRequest()->getParam('searchProfileId', '')); $profile = $profilesModel->find($profileId)->current(); if (((bool) $this->getRequest()->getParam('save', false) || (bool) $this->getRequest()->getParam('delete', false)) && !empty($profileId)) { if (!($user->isAllowed('editor.manage-search-profiles', null) || $user->id == $profile->creatorUserId)) { $form->addError(_('You are not allowed to edit that search profile.')); return $this->_forward('show-form'); } if ((bool) $this->getRequest()->getParam('save', false)) { $profileName = $this->getRequest()->getParam('searchProfileName', ''); if (empty($profileName)) { $form->getElement('searchProfileName')->addError(_('Please fill a profile name.')); return $this->_forward('show-form'); } $profile->name = $profileName; $profile->setSearchOptions($options); $profile->save(); return $this->_forward('show-form', 'search', 'editor', array('switchProfile' => true, 'reInitForm' => true)); } if ((bool) $this->getRequest()->getParam('delete', false)) { $profile->delete(); return $this->_forward('show-form', 'search', 'editor', array('reInitForm' => true)); } } // Save options for the user if ((bool) $this->getRequest()->getParam('ok', false)) { if (null !== $profile) { $originalOptions = $profile->getSearchOptions(); $originalOptions = Editor_Forms_SearchOptions::formValues2Options($originalOptions); // Make sure that there are no any old or unneeded options in the profile. $originalOptions['searchProfileId'] = $profile->id; } else { $originalOptions = Editor_Forms_SearchOptions::getDefaultSearchOptions(); } $checkOptions = array_merge(Editor_Forms_SearchOptions::getDefaultSearchOptions(), $options); if ($checkOptions != $originalOptions) { $options['searchProfileId'] = 'custom'; } $user->setSearchOptions($options); return $this->_forward('set-options-success'); } }
/** * Saves new or existing concept scheme. * */ public function saveAction() { $this->_helper->_layout->setLayout('editor_central_content'); $this->_requireAccess('editor.concept-schemes', 'create', self::RESPONSE_TYPE_PARTIAL_HTML); $form = Editor_Forms_ConceptScheme::getInstance(); $formData = $this->getRequest()->getParams(); if (!$this->getRequest()->isPost()) { $this->getHelper('FlashMessenger')->setNamespace('error')->addMessage(_('No POST data recieved')); $this->_helper->redirector('edit'); } if (!$form->isValid($formData)) { return $this->_forward('create'); } else { $form->populate($formData); $conceptScheme = $this->_getConceptScheme(); if (null === $conceptScheme) { $this->_requireAccess('editor.concept-schemes', 'create', self::RESPONSE_TYPE_PARTIAL_HTML); $conceptScheme = new Editor_Models_ConceptScheme(new Api_Models_Concept()); } else { $this->_requireAccess('editor.concept-schemes', 'edit', self::RESPONSE_TYPE_PARTIAL_HTML); } $oldData = $conceptScheme->getData(); $extraData = $conceptScheme->transformFormData($formData); $conceptScheme->setConceptData($formData, $extraData); try { $user = OpenSKOS_Db_Table_Users::fromIdentity(); $extraData = array_merge($extraData, array('tenant' => $user->tenant, 'modified_by' => (int) $user->id, 'modified_timestamp' => date("Y-m-d\\TH:i:s\\Z"))); if (!isset($extraData['uuid']) || empty($extraData['uuid'])) { $extraData['uuid'] = $conceptScheme['uuid']; $extraData['created_by'] = $extraData['modified_by']; $extraData['created_timestamp'] = $extraData['modified_timestamp']; } else { $extraData['created_by'] = $oldData['created_by']; $extraData['created_timestamp'] = $oldData['created_timestamp']; } $conceptScheme->save($extraData); // Clears the schemes cache after a new scheme is added. OpenSKOS_Cache::getCache()->remove(Editor_Models_ApiClient::CONCEPT_SCHEMES_CACHE_KEY); } catch (Zend_Exception $e) { $this->getHelper('FlashMessenger')->setNamespace('error')->addMessage($e->getMessage()); return $this->_forward('edit'); } } }
/** * Delete a concept scheme from everywhere. * * @param bool $commit, optional, Default: true * @param bool $deletedBy, optional */ public function delete($commit = true, $deletedBy = null) { if (null === $deletedBy) { $actionUser = OpenSKOS_Db_Table_Users::fromIdentity(); if (null !== $actionUser) { $deletedBy = $actionUser->id; } } $affectedConceptsQuery = '(inScheme:"' . $this['uri'] . '" OR topConceptOf:"' . $this['uri'] . '") AND tenant:' . $this['tenant']; // Update affected concepts by steps. $rows = 1000; do { // Get concepts which has the scheme in topConceptOf or inScheme. $concepts = Editor_Models_ApiClient::factory()->getConceptsByQuery($affectedConceptsQuery, array('rows' => $rows)); if (count($concepts['data']) > 0) { // Remove the concept from topConceptOf or inScheme of each concept. Delete concept if it does not have other schemes in inScheme. foreach ($concepts['data'] as $key => $concept) { $concept = new Editor_Models_Concept($concept); $data = $concept->getData(); $updateData = array(); $updateExtraData = array(); if (isset($data['inScheme'])) { $updateData['inScheme'] = array_diff($data['inScheme'], array($this['uri'])); } if (isset($data['topConceptOf'])) { $updateData['topConceptOf'] = array_diff($data['topConceptOf'], array($this['uri'])); } if (empty($updateData['inScheme'])) { $updateExtraData['deleted'] = true; $updateExtraData['deleted_by'] = $deletedBy; } $concept->update($updateData, $updateExtraData, false, true); if ($key == count($concepts['data']) - 1 && $commit) { $this->solr()->commit(); } } } } while (count($concepts['data']) == $rows); // Update the concept scheme $updateExtraData['deleted'] = true; $updateExtraData['deleted_by'] = $deletedBy; $this->update(array(), $updateExtraData); // Commit if ($commit) { $this->solr()->commit(); } }
/** * @return OpenSKOS_Db_Table_Row_User */ protected function _getUser() { $apikey = $this->getRequest()->getParam('key'); if (!$apikey) { throw new Zend_Controller_Action_Exception('No key specified', 412); } $user = OpenSKOS_Db_Table_Users::fetchByApiKey($apikey); if (null === $user) { throw new Zend_Controller_Action_Exception('No such API-key: `' . $apikey . '`', 401); } if (!$user->isApiAllowed()) { throw new Zend_Controller_Action_Exception('Your user account is not allowed to use the API', 401); } if ($user->active != 'Y') { throw new Zend_Controller_Action_Exception('Your user account is blocked', 401); } return $user; }
/** * @return OpenSKOS_Db_Table_Row_User */ protected function _getUser($id) { $model = new OpenSKOS_Db_Table_Users(); $user = $model->find((int) $id)->current(); return $user; }
/** * Sets all dcterms fields. * * @param unknown_type $extraData */ protected function setSpecialExtraData($extraData) { if (isset($extraData['created_timestamp'])) { $this->data['dcterms_dateSubmitted'] = array($extraData['created_timestamp']); } if (isset($extraData['approved_timestamp'])) { $this->data['dcterms_dateAccepted'] = array($extraData['approved_timestamp']); } if (isset($extraData['modified_timestamp'])) { $this->data['dcterms_modified'] = array($extraData['modified_timestamp']); } if (isset($extraData['created_by'])) { $usersModel = new OpenSKOS_Db_Table_Users(); $creator = $usersModel->find($extraData['created_by'])->current(); if (null !== $creator) { $this->data['dcterms_creator'] = array($creator->name); } } if (isset($extraData['status'])) { $this->data['status'] = $extraData['status']; } }