private function checkUserIsSiteadmin(PFUser $user, Response $response)
 {
     if (!$user->isSuperUser()) {
         $response->addFeedback(Feedback::ERROR, $GLOBALS['Language']->getText('global', 'perm_denied'));
         $response->redirect('/');
     }
 }
 /**
  * @return Rest_Token
  */
 public function generateTokenForUser(PFUser $user)
 {
     $number_generator = new RandomNumberGenerator();
     $token = $number_generator->getNumber();
     $this->token_dao->addTokenForUserId($user->getId(), $token, $_SERVER['REQUEST_TIME']);
     return new Rest_Token($user->getId(), $token);
 }
Example #3
0
 public function __construct(PFUser $user)
 {
     $hp = Codendi_HTMLPurifier::instance();
     $user_name = $hp->purify($user->getRealName());
     $steps = array(new Tuleap_Tour_Step($GLOBALS['Language']->getText('my_tour', 'welcome_title'), $GLOBALS['Language']->getText('my_tour', 'welcome', $user_name)), new Tuleap_Tour_Step($GLOBALS['Language']->getText('my_tour', 'my_personal_page_title'), $GLOBALS['Language']->getText('my_tour', 'my_personal_page'), 'bottom', 'ul.nav > li:first-child'), new Tuleap_Tour_Step($GLOBALS['Language']->getText('my_tour', 'projects_title'), $GLOBALS['Language']->getText('my_tour', 'projects'), 'bottom', 'ul.nav > li.projects-nav'), new Tuleap_Tour_Step($GLOBALS['Language']->getText('my_tour', 'help_title'), $GLOBALS['Language']->getText('my_tour', 'help'), 'bottom', 'ul.nav > li.help-nav'), new Tuleap_Tour_Step($GLOBALS['Language']->getText('my_tour', 'search_title'), $GLOBALS['Language']->getText('my_tour', 'search'), 'bottom', 'ul.nav.pull-right > form'), new Tuleap_Tour_Step($GLOBALS['Language']->getText('my_tour', 'user_menu_title'), $GLOBALS['Language']->getText('my_tour', 'user_menu'), 'bottom', 'ul.nav.pull-right > li.user-menu'), new Tuleap_Tour_Step($GLOBALS['Language']->getText('my_tour', 'end_tour_title'), $GLOBALS['Language']->getText('my_tour', 'end_tour')));
     parent::__construct(self::TOUR_NAME, $steps);
 }
 public function addUserAsProjectAdmin(Project $project, PFUser $user)
 {
     $project_id = $this->da->escapeInt($project->getId());
     $user_id = $this->da->escapeInt($user->getId());
     $sql = "UPDATE user_group\n                SET admin_flags = 'A'\n                WHERE group_id = {$project_id}\n                  AND user_id = {$user_id}";
     return $this->update($sql);
 }
 public function __construct(PFUser $current_user, Project $project, $milestone_id)
 {
     $this->user_id = $current_user->getId();
     $this->lang = $this->getLanguageAbbreviation($current_user);
     $this->project_id = $project->getId();
     $this->milestone_id = $milestone_id;
     $this->view_mode = $current_user->getPreference('agiledashboard_planning_item_view_mode_' . $this->project_id);
 }
 private function userPasswordHasExpired(PFUser $user)
 {
     $expiration_date = $this->getPasswordExpirationDate();
     if ($expiration_date && $user->getLastPwdUpdate() < $expiration_date) {
         return true;
     }
     return false;
 }
Example #7
0
 public function __construct(Project $project, PFUser $pfuser, $suffix)
 {
     parent::__construct($pfuser->toRow());
     $this->setStatus(PFUser::STATUS_RESTRICTED);
     $this->setRealName(self::REAL_NAME);
     $this->setUserName(self::NAME_PREFIX . $project->getUnixName() . $suffix);
     $this->project = $project;
 }
 /**
  * Remove all pair done with user account
  */
 public function removePair(PFUser $user)
 {
     $user_id = $user->getId();
     $dar = $this->dao->searchOpenidUrlsForUserId($user_id);
     if ($dar->count()) {
         $row = $dar->getRow();
         $this->dao->removeConnexionStringForUserId($row['connexion_string'], $user_id);
     }
 }
Example #9
0
 /**
  * Return the Tracker object that correspond to the given request
  *
  * @param Codendi_Request $request The request
  * @param PFUser            $user    Who access the request
  * 
  * @return Tracker_Dispatchable_Interface
  */
 function getDispatchableFromRequest(Codendi_Request $request, PFUser $user)
 {
     if ((int) $request->get('aid')) {
         if ($artifact = $this->getArtifactFactory()->getArtifactByid($request->get('aid'))) {
             return $artifact;
         } else {
             throw new Tracker_ResourceDoesntExistException($GLOBALS['Language']->getText('plugin_tracker_common_type', 'artifact_not_exist'));
         }
     } else {
         if ((int) $request->get('report')) {
             $store_in_session = true;
             if ($request->exist('store_in_session')) {
                 $store_in_session = (bool) $request->get('store_in_session');
             }
             if ($report = $this->getArtifactReportFactory()->getReportById($request->get('report'), $user->getId(), $store_in_session)) {
                 return $report;
             } else {
                 throw new Tracker_ResourceDoesntExistException($GLOBALS['Language']->getText('plugin_tracker_common_type', 'report_not_exist'));
             }
         } else {
             if ((int) $request->get('tracker') || (int) $request->get('atid')) {
                 $tracker_id = (int) $request->get('tracker');
                 if (!$tracker_id) {
                     $tracker_id = (int) $request->get('atid');
                 }
                 if ($tracker = $this->getTrackerFactory()->getTrackerByid($tracker_id)) {
                     return $tracker;
                 } else {
                     throw new Tracker_ResourceDoesntExistException($GLOBALS['Language']->getText('plugin_tracker_common_type', 'tracker_not_exist'));
                 }
             } else {
                 if ((int) $request->get('formElement')) {
                     if ($formElement = $this->getTracker_FormElementFactory()->getFormElementByid($request->get('formElement'))) {
                         return $formElement;
                     }
                 } else {
                     if ($request->get('func') == 'new-artifact-link') {
                         if ($artifact = Tracker_ArtifactFactory::instance()->getArtifactByid($request->get('id'))) {
                             return $artifact;
                         } else {
                             throw new Tracker_ResourceDoesntExistException($GLOBALS['Language']->getText('plugin_tracker_common_type', 'artifact_not_exist'));
                         }
                     } else {
                         if ((int) $request->get('link-artifact-id')) {
                             if ($artifact = Tracker_ArtifactFactory::instance()->getArtifactByid($request->get('link-artifact-id'))) {
                                 return $artifact;
                             } else {
                                 throw new Tracker_ResourceDoesntExistException($GLOBALS['Language']->getText('plugin_tracker_common_type', 'artifact_not_exist'));
                             }
                         }
                     }
                 }
             }
         }
     }
     throw new Tracker_NoMachingResourceException();
 }
 private function createArtifact(PFUser $current_user)
 {
     $email = null;
     if ($current_user->isAnonymous()) {
         $email = $this->request->get('email');
     }
     $fields_data = $this->request->get('artifact');
     $this->tracker->augmentDataFromRequest($fields_data);
     return $this->tracker_artifact_factory->createArtifact($this->tracker, $fields_data, $current_user, $email);
 }
 /**
  * Send a mail when PDF Watermarking is disabled.
  * 
  * @param Docman_Item $item
  * @param PFUser        $currentUser
  * 
  * @return void
  */
 public function notifyOnDisable($item, $currentUser, $defaultUrl)
 {
     $admins = $this->getPeopleToNotifyWhenWatermarkingIsDisabled($item);
     $link = get_server_url() . $defaultUrl . '&action=details&id=' . $item->getId();
     $mail = new Mail();
     $mail->setTo(implode(',', $admins));
     $mail->setSubject($GLOBALS['Language']->getText('plugin_docmanwatermark', 'email_disable_watermark_subject', array($item->getTitle())));
     $mail->setBody($GLOBALS['Language']->getText('plugin_docmanwatermark', 'email_disable_watermark_body', array($item->getTitle(), $currentUser->getRealname(), $link)));
     $mail->send();
 }
Example #12
0
 public function exportUser(PFUser $user, SimpleXMLElement $members_node, $child_name)
 {
     if ($user->getLdapId()) {
         $member_node = $members_node->addChild($child_name, $user->getLdapId());
         $member_node->addAttribute('format', 'ldap');
     } else {
         $member_node = $members_node->addChild($child_name, $user->getUserName());
         $member_node->addAttribute('format', 'username');
     }
 }
 /**
  * Add an artefact in the tracker
  *
  * @param Tracker_IDisplayTrackerLayout  $layout
  * @param Codendi_Request                $request
  * @param PFUser                         $user
  *
  * @return Tracker_Artifact the new artifact
  */
 private function createArtifact(Tracker_IDisplayTrackerLayout $layout, $request, $user)
 {
     $email = null;
     if ($user->isAnonymous()) {
         $email = $request->get('email');
     }
     $fields_data = $request->get('artifact');
     $this->tracker->augmentDataFromRequest($fields_data);
     return $this->artifact_factory->createArtifact($this->tracker, $fields_data, $user, $email);
 }
Example #14
0
 public function getVariantForUser(PFUser $user)
 {
     $variant = $user->getPreference(self::PREFERENCE_NAME);
     if (!$variant) {
         return $this->default;
     }
     if (!$this->isAllowed($variant)) {
         return $this->default;
     }
     return $variant;
 }
 public function __construct(PFUser $current_user, Project $project, $milestone_id, $milestone_representation, $paginated_backlog_items_representations, $paginated_milestones_representations)
 {
     $this->user_id = $current_user->getId();
     $this->lang = $this->getLanguageAbbreviation($current_user);
     $this->project_id = $project->getId();
     $this->milestone_id = $milestone_id;
     $this->view_mode = $current_user->getPreference('agiledashboard_planning_item_view_mode_' . $this->project_id);
     $this->milestone_representation = json_encode($milestone_representation);
     $this->paginated_backlog_items_representations = json_encode($paginated_backlog_items_representations);
     $this->paginated_milestones_representations = json_encode($paginated_milestones_representations);
 }
 private function doesRequestAppearToBeValid(Tracker_Artifact $artifact, array $fields_data, PFUser $submitter)
 {
     if ($submitter->isAnonymous() && !trim($submitter->getEmail())) {
         $GLOBALS['Response']->addFeedback('error', $GLOBALS['Language']->getText('plugin_tracker_artifact', 'email_required'));
         return false;
     }
     if (!$this->fields_validator->validate($artifact, $fields_data)) {
         return false;
     }
     return true;
 }
Example #17
0
 public function __construct(PFUser $owner, $id, $url, $hostname, $name)
 {
     $this->id = $id;
     $this->url = $url;
     $this->hostname = $hostname;
     $this->owner = $owner;
     $this->name = $name;
     $this->ssh_key = $owner->getAuthorizedKeysRaw() ? $owner->getAuthorizedKeysRaw() : '';
     $this->owner_name = $owner->getName();
     $this->owner_id = $owner->getId();
 }
 /**
  * @param PFUser $user
  * @return ProjectUGroup[]
  */
 private function getDynamicUgroupsForUser(PFUser $user)
 {
     $project_ids = $user->getProjects();
     $ugroups = array();
     foreach ($project_ids as $group_id) {
         $ugroups[] = new ProjectUGroup(array('ugroup_id' => ProjectUGroup::PROJECT_MEMBERS, 'group_id' => $group_id));
         if ($user->isAdmin($group_id)) {
             $ugroups[] = new ProjectUGroup(array('ugroup_id' => ProjectUGroup::PROJECT_ADMIN, 'group_id' => $group_id));
         }
     }
     return $ugroups;
 }
 public function userIsGitAdmin(PFUser $user, Project $project)
 {
     $database_result = $this->getCurrentGitAdminPermissionsForProject($project);
     if (db_numrows($database_result) < 1) {
         $database_result = $this->getDefaultGitAdminPermissions();
     }
     $has_permission = false;
     while (!$has_permission && ($row = db_fetch_array($database_result))) {
         $has_permission = ugroup_user_is_member($user->getId(), $row['ugroup_id'], $project->getID());
     }
     return $has_permission;
 }
Example #20
0
 /**
  *
  * @param Tracker_Artifact $artifact
  *
  * @return Tracker_FormElement_Field[]
  */
 public function getFields(Tracker_Artifact $artifact)
 {
     $diplayed_fields = array();
     $tracker_id = $artifact->getTrackerId();
     foreach ($this->displayed_fields as $diplayed_field_name) {
         $field = $this->form_element_factory->getUsedFieldByNameForUser($tracker_id, $diplayed_field_name, $this->user_manager->getCurrentUser());
         if ($field) {
             $diplayed_fields[] = $field;
         }
     }
     return $diplayed_fields;
 }
 public function calculate(PFUser $user, $current_type, $service_name, $project_id)
 {
     if (!$user->useLabFeatures()) {
         return $current_type;
     }
     if ($service_name === Search_SearchWiki::NAME) {
         return $this->calculateForWikiService($project_id);
     }
     if ($this->isRequestFromDocmanOrTracker($service_name)) {
         return $this->getFullTextTypeName();
     }
     return $current_type;
 }
 public function update(Tracker $tracker, SimpleXMLElement $artifact_xml, array $submitted_values, PFUser $user, $submitted_on)
 {
     $artifact_xml->changeset->submitted_on = date('c', $submitted_on);
     $artifact_xml->changeset->submitted_by = $user->getId();
     foreach ($artifact_xml->changeset->field_change as $field_change) {
         $field_name = (string) $field_change['field_name'];
         $field = $this->formelement_factory->getUsedFieldByNameForUser($tracker->getId(), $field_name, $user);
         if ($field && isset($submitted_values[$field->getId()])) {
             $submitted_value = $submitted_values[$field->getId()];
             $this->visitor->update($field_change, $field, $submitted_value);
         }
     }
 }
 private function getSaveOrRevert(PFUser $current_user, Tracker_Report $report, array $options_params, $report_can_be_modified)
 {
     if ($current_user->isAnonymous() || !$report_can_be_modified) {
         return false;
     }
     if ($report->userCanUpdate($current_user)) {
         $default_save = new Templating_Presenter_ButtonDropdownsOption('tracker_report_updater_save', $GLOBALS['Language']->getText('plugin_tracker_report', 'save'), false, '?' . http_build_query(array_merge($options_params, array('func' => Tracker_Report::ACTION_SAVE))));
         $extra_save = array(new Templating_Presenter_ButtonDropdownsOptionWithModal('tracker_report_updater_saveas', $GLOBALS['Language']->getText('plugin_tracker_report', 'save_as'), false, '?' . http_build_query(array_merge($options_params, array('func' => Tracker_Report::ACTION_SAVEAS))) . '#tracker_report_updater_saveas-modal'));
     } elseif (!$current_user->isAnonymous()) {
         $default_save = new Templating_Presenter_ButtonDropdownsOptionWithModal('tracker_report_updater_saveas', $GLOBALS['Language']->getText('plugin_tracker_report', 'save_as'), false, '?' . http_build_query(array_merge($options_params, array('func' => Tracker_Report::ACTION_SAVEAS))) . '#tracker_report_updater_saveas-modal');
         $extra_save = array();
     }
     return new Templating_Presenter_SplitButtonDropdowns('tracker_report_save_dropdown', 'btn-primary', $default_save, $extra_save);
 }
Example #24
0
 public function sendMail(PFUser $user, Project $project, $tv3_id, $tracker_name)
 {
     $mail = new Codendi_Mail();
     $breadcrumbs = array();
     $breadcrumbs[] = '<a href="' . get_server_url() . '/projects/' . $project->getUnixName(true) . '" />' . $project->getPublicName() . '</a>';
     $mail->getLookAndFeelTemplate()->set('breadcrumbs', $breadcrumbs);
     $mail->addAdditionalHeader("X-Codendi-Project", $project->getUnixName());
     $mail->setFrom($GLOBALS['sys_noreply']);
     $mail->setTo($user->getEmail());
     $mail->setSubject('Output of your migration TV3 -> TV5');
     $mail->setBody($this->getMailBody($tv3_id, $tracker_name));
     $mail->send();
     $this->purgeLogStack();
 }
 public function __construct($id, $is_active, PFUser $user, array $projects)
 {
     parent::__construct($id, $is_active);
     $this->projects = $projects;
     $this->has_projects = count($projects) > 0;
     $this->label = $GLOBALS['Language']->getText('include_menu', 'projects');
     $this->filter_project = $GLOBALS['Language']->getText('include_menu', 'filter_project');
     $this->menu_projects_text = $GLOBALS['Language']->getText('include_menu', 'projects');
     $this->browse_projects_text = $GLOBALS['Language']->getText('include_menu', 'browse_projects');
     $this->register_new_proj = $GLOBALS['Language']->getText('include_menu', 'register_new_proj');
     $this->is_trove_cat_enabled = ForgeConfig::get('sys_use_trove');
     $this->is_project_registration_enabled = ForgeConfig::get('sys_use_project_registration', true);
     $this->display_only_trovemap = $this->is_trove_cat_enabled && !$this->is_project_registration_enabled && !$this->projects;
     $this->display_dropdown = !$this->display_only_trovemap && $user->isLoggedIn();
 }
Example #26
0
 public function __construct(PFUser $user, Git_HTTP_Command $command)
 {
     parent::__construct();
     $gitolite_user_info = posix_getpwnam('gitolite');
     $this->gitolite_home = $gitolite_user_info['dir'];
     $this->env['SHELL'] = '/bin/sh';
     $this->env['REMOTE_USER'] = $user->getUnixName();
     $this->env['GIT_HTTP_BACKEND'] = $command->getCommand();
     $this->env['HOME'] = $this->gitolite_home;
     $this->env['REMOTE_ADDR'] = HTTPRequest::getIPAddress();
     $this->appendToEnv('REQUEST_URI');
     $this->appendToEnv('REMOTE_PORT');
     $this->appendToEnv('SERVER_ADDR');
     $this->appendToEnv('SERVER_PORT');
 }
 /**
  * Do all the synchronization between an ldap result and a Tuleap user.
  *
  * This method returns if it modified the user or not. This is usefull during
  * batch process in order to limit computing.
  *
  * @param PFUser       $user User
  * @param LDAPResult $lr   Ldap result
  *
  * @return Boolean True if the method modified the user object
  */
 public function sync(PFUser $user, LDAPResult $lr)
 {
     $modified = false;
     $ldapEmail = $lr->getEmail();
     $realname = ucwords(preg_replace('/^(\\w+).(\\w+)@.*/', '\\1 \\2', $ldapEmail));
     if ($realname !== null && $user->getRealName() != substr($realname, 0, 32)) {
         $user->setRealName($realname);
         $modified = true;
     }
     if ($ldapEmail !== null && $user->getEmail() != $ldapEmail) {
         $user->setEmail($ldapEmail);
         $modified = true;
     }
     return $modified;
 }
 /**
  * Check user status validity
  *
  * @param PFUser $user
  * @param Boolean $allowpending
  * @return Boolean
  * @throws User_StatusDeletedException
  * @throws User_StatusSuspendedException
  */
 private function isFinalStatus(PFUser $user)
 {
     $status = $user->getStatus();
     switch ($status) {
         case PFUser::STATUS_ACTIVE:
         case PFUser::STATUS_RESTRICTED:
             return true;
             break;
         case PFUser::STATUS_DELETED:
             throw new User_StatusDeletedException();
         case PFUser::STATUS_SUSPENDED:
             throw new User_StatusSuspendedException();
         default:
             return false;
     }
 }
 /** @return PaginatedWikiPages */
 public function getPaginatedUserPages(PFUser $user, $project_id, $limit, $offset, $pagename)
 {
     $pages = array();
     if ($pagename !== '') {
         $row_pages = $this->dao->searchPaginatedUserWikiPagesByPagename($project_id, $limit, $offset, $pagename);
     } else {
         $row_pages = $this->dao->searchPaginatedUserWikiPages($project_id, $limit, $offset);
     }
     foreach ($row_pages as $page) {
         $wiki_page = new PHPWikiPage($project_id, $page['pagename']);
         if ($wiki_page->isAutorized($user->getId())) {
             $pages[] = $wiki_page;
         }
     }
     return new PaginatedPHPWikiPages($pages);
 }
 /**
  * Send mail to project administrators after daliy user sync.
  *
  * @param String  $recipients  List of project administrators emails we want to notify
  * @param String  $projectName Public name of the project we want to notify its administrators
  * @param PFUser  $user        Suspended user after LDAP daily synchro
  * @param String  $subject     The subject of the notification mail
  * @param String  $body        The content of the notification mail
  *
  * @return boolean
  */
 public function notifyProjectsAdmins($recipients, $projectName, $user, $subject, $body)
 {
     $notificationStatus = true;
     try {
         $mail = $this->prepareMail($recipients, $projectName, $subject, $body);
         if (!$mail->send()) {
             $this->logger->error("LDAP daily synchro job has suspended this user " . $user->getRealName() . " (" . $user->getEmail() . ", but failed to notify administrators of <{$projectName}> project :" . $e->getMessage());
             $notificationStatus = false;
         }
     } catch (InvalidArgumentException $e) {
         $this->logger->warn("LDAP daily synchro job has suspended this user " . $user->getRealName() . " (" . $user->getEmail() . ":" . $e->getMessage());
         $notificationStatus = false;
     } catch (Zend_Mail_Exception $e) {
         $this->logger->error("LDAP daily synchro job has suspended this user " . $user->getRealName() . " (" . $user->getEmail() . "), but faced an issue during project administrators notification :" . $e->getMessage());
     }
     return $notificationStatus;
 }