/** * Pre-execute function * * @param framework\Request $request * @param string $action */ public function preExecute(framework\Request $request, $action) { // forward 403 if you're not allowed here if ($request->isAjaxCall() == false) { $this->forward403unless(framework\Context::getUser()->canAccessConfigurationPage()); } $this->access_level = $this->getAccessLevel(framework\Settings::CONFIGURATION_SECTION_IMPORT, 'core'); if (!$request->isAjaxCall()) { $this->getResponse()->setPage('config'); framework\Context::loadLibrary('ui'); $this->getResponse()->addBreadcrumb(framework\Context::getI18n()->__('Configure %thebuggenie_name', array('%thebuggenie_name' => framework\Settings::getSiteHeaderName())), framework\Context::getRouting()->generate('configure'), $this->getResponse()->getPredefinedBreadcrumbLinks('configure')); } }
public function saveEstimate($issue_id, $months, $weeks, $days, $hours, $points) { $crit = $this->getCriteria(); $crit->addInsert(self::ESTIMATED_MONTHS, $months); $crit->addInsert(self::ESTIMATED_WEEKS, $weeks); $crit->addInsert(self::ESTIMATED_DAYS, $days); $crit->addInsert(self::ESTIMATED_HOURS, $hours); $crit->addInsert(self::ESTIMATED_POINTS, $points); $crit->addInsert(self::ISSUE_ID, $issue_id); $crit->addInsert(self::EDITED_AT, NOW); $crit->addInsert(self::EDITED_BY, framework\Context::getUser()->getID()); $crit->addInsert(self::SCOPE, framework\Context::getScope()->getID()); $this->doInsert($crit); }
public function componentEditAgileBoard() { $i18n = framework\Context::getI18n(); $this->autosearches = array(\thebuggenie\core\entities\SavedSearch::PREDEFINED_SEARCH_PROJECT_OPEN_ISSUES => $i18n->__('Project open issues (recommended)'), \thebuggenie\core\entities\SavedSearch::PREDEFINED_SEARCH_PROJECT_OPEN_ISSUES_INCLUDING_SUBPROJECTS => $i18n->__('Project open issues (including subprojects)'), \thebuggenie\core\entities\SavedSearch::PREDEFINED_SEARCH_PROJECT_CLOSED_ISSUES => $i18n->__('Project closed issues'), \thebuggenie\core\entities\SavedSearch::PREDEFINED_SEARCH_PROJECT_CLOSED_ISSUES_INCLUDING_SUBPROJECTS => $i18n->__('Project closed issues (including subprojects)'), \thebuggenie\core\entities\SavedSearch::PREDEFINED_SEARCH_PROJECT_REPORTED_THIS_MONTH => $i18n->__('Project issues reported last month'), \thebuggenie\core\entities\SavedSearch::PREDEFINED_SEARCH_PROJECT_WISHLIST => $i18n->__('Project wishlist')); $this->savedsearches = \thebuggenie\core\entities\tables\SavedSearches::getTable()->getAllSavedSearchesByUserIDAndPossiblyProjectID(framework\Context::getUser()->getID(), $this->board->getProject()->getID()); $this->issuetypes = $this->board->getProject()->getIssuetypeScheme()->getIssuetypes(); $this->swimlane_groups = array('priority' => $i18n->__('Issue priority'), 'severity' => $i18n->__('Issue severity'), 'category' => $i18n->__('Issue category')); $this->priorities = \thebuggenie\core\entities\Priority::getAll(); $this->severities = \thebuggenie\core\entities\Severity::getAll(); $this->categories = \thebuggenie\core\entities\Category::getAll(); $fakecolumn = new entities\BoardColumn(); $fakecolumn->setBoard($this->board); $this->fakecolumn = $fakecolumn; }
public function saveFile($real_filename, $original_filename, $content_type, $description = null, $content = null) { $crit = $this->getCriteria(); $crit->addInsert(self::UID, framework\Context::getUser()->getID()); $crit->addInsert(self::REAL_FILENAME, $real_filename); $crit->addInsert(self::UPLOADED_AT, NOW); $crit->addInsert(self::ORIGINAL_FILENAME, $original_filename); $crit->addInsert(self::CONTENT_TYPE, $content_type); $crit->addInsert(self::SCOPE, framework\Context::getScope()->getID()); if ($description !== null) { $crit->addInsert(self::DESCRIPTION, $description); } if ($content !== null) { $crit->addInsert(self::CONTENT, $content, 'blob'); } $res = $this->doInsert($crit); return $res->getInsertID(); }
public function addLink($target_type, $target_id = 0, $url = null, $description = null, $link_order = null, $scope = null) { $scope = $scope === null ? framework\Context::getScope()->getID() : $scope; if ($link_order === null) { $crit = $this->getCriteria(); $crit->addSelectionColumn(self::LINK_ORDER, 'max_order', Criteria::DB_MAX, '', '+1'); $crit->addWhere(self::TARGET_TYPE, $target_type); $crit->addWhere(self::TARGET_ID, $target_id); $crit->addWhere(self::SCOPE, $scope); $row = $this->doSelectOne($crit); $link_order = $row->get('max_order') ? $row->get('max_order') : 1; } $crit = $this->getCriteria(); $crit->addInsert(self::TARGET_TYPE, $target_type); $crit->addInsert(self::TARGET_ID, $target_id); $crit->addInsert(self::URL, $url); $crit->addInsert(self::DESCRIPTION, $description); $crit->addInsert(self::LINK_ORDER, $link_order); $crit->addInsert(self::UID, framework\Context::getUser() instanceof \thebuggenie\core\entities\User ? framework\Context::getUser()->getID() : 0); $crit->addInsert(self::SCOPE, $scope); $res = $this->doInsert($crit); framework\Context::getCache()->clearCacheKeys(array(framework\Cache::KEY_MAIN_MENU_LINKS)); return $res->getInsertID(); }
public static function getAvailableViews($target_type) { $i18n = framework\Context::getI18n(); $searches = array('info' => array(), 'searches' => array()); switch ($target_type) { case self::TYPE_USER: $searches['info'][self::VIEW_LOGGED_ACTIONS] = array(0 => array('title' => $i18n->__("What you've done recently"), 'description' => $i18n->__('A widget that shows your most recent actions, such as issue edits, wiki edits and more'))); if (framework\Context::getUser()->canViewComments()) { $searches['info'][self::VIEW_RECENT_COMMENTS] = array(0 => array('title' => $i18n->__('Recent comments'), 'description' => $i18n->__('Shows a list of your most recent comments'))); } $searches['searches'][self::VIEW_PREDEFINED_SEARCH] = array(\thebuggenie\core\entities\SavedSearch::PREDEFINED_SEARCH_MY_REPORTED_ISSUES => array('title' => $i18n->__('Issues reported by me'), 'description' => $i18n->__('Shows a list of all issues you have reported, across all projects')), \thebuggenie\core\entities\SavedSearch::PREDEFINED_SEARCH_MY_ASSIGNED_OPEN_ISSUES => array('title' => $i18n->__('Open issues assigned to me'), 'description' => $i18n->__('Shows a list of all issues assigned to you')), \thebuggenie\core\entities\SavedSearch::PREDEFINED_SEARCH_MY_OWNED_OPEN_ISSUES => array('title' => $i18n->__('Open issues owned by me'), 'description' => $i18n->__('Shows a list of all issues owned by you')), \thebuggenie\core\entities\SavedSearch::PREDEFINED_SEARCH_TEAM_ASSIGNED_OPEN_ISSUES => array('title' => $i18n->__('Open issues assigned to my teams'), 'description' => $i18n->__('Shows all issues assigned to any of your teams'))); $searches['info'][self::VIEW_PROJECTS] = array(0 => array('title' => $i18n->__("Your projects"), 'description' => $i18n->__('A widget that shows projects you are involved in'))); $searches['info'][self::VIEW_MILESTONES] = array(0 => array('title' => $i18n->__("Upcoming milestones / sprints"), 'description' => $i18n->__('A widget that shows all upcoming milestones or sprints for any projects you are involved in'))); break; case self::TYPE_PROJECT: $searches['statistics'] = array(); $issuetype_icons = array(); foreach (Issuetype::getAll() as $id => $issuetype) { $issuetype_icons[$id] = array('title' => $i18n->__('Recent issues: %issuetype', array('%issuetype' => $issuetype->getName())), 'description' => $i18n->__('Show recent issues of type %issuetype', array('%issuetype' => $issuetype->getName()))); } $searches['info'][self::VIEW_PROJECT_INFO] = array(0 => array('title' => $i18n->__('About this project'), 'description' => $i18n->__('Basic project information widget, showing project name, important people and links'))); $searches['info'][self::VIEW_PROJECT_TEAM] = array(0 => array('title' => $i18n->__('Project team'), 'description' => $i18n->__('A widget with information about project developers and the project team and their respective project roles'))); $searches['info'][self::VIEW_PROJECT_CLIENT] = array(0 => array('title' => $i18n->__('Project client'), 'description' => $i18n->__('Shows information about the associated project client (if any)'))); $searches['info'][self::VIEW_PROJECT_SUBPROJECTS] = array(0 => array('title' => $i18n->__('Subprojects'), 'description' => $i18n->__('Lists all subprojects of this project, with quick links to report an issue, open the project wiki and more'))); $searches['info'][self::VIEW_PROJECT_RECENT_ACTIVITIES] = array(0 => array('title' => $i18n->__('Recent activities'), 'description' => $i18n->__('Displays project timeline'))); $searches['info'][self::VIEW_PROJECT_UPCOMING] = array(0 => array('title' => $i18n->__('Upcoming milestones and deadlines'), 'description' => $i18n->__('A widget showing a list of upcoming milestones and deadlines for the next three weeks'))); $searches['info'][self::VIEW_PROJECT_DOWNLOADS] = array(0 => array('title' => $i18n->__('Latest downloads'), 'description' => $i18n->__('Lists recent downloads released in the release center'))); $searches['statistics'][self::VIEW_PROJECT_STATISTICS_LAST15] = array(0 => array('title' => $i18n->__('Graph of closed vs open issues'), 'description' => $i18n->__('Shows a line graph comparing closed vs open issues for the past 15 days'))); $searches['statistics'][self::VIEW_PROJECT_STATISTICS_PRIORITY] = array(0 => array('title' => $i18n->__('Statistics by priority'), 'description' => $i18n->__('Displays a bar graph of open and closed issues grouped by priority'))); $searches['statistics'][self::VIEW_PROJECT_STATISTICS_SEVERITY] = array(0 => array('title' => $i18n->__('Statistics by severity'), 'description' => $i18n->__('Displays a bar graph of open and closed issues grouped by severity'))); $searches['statistics'][self::VIEW_PROJECT_STATISTICS_CATEGORY] = array(0 => array('title' => $i18n->__('Statistics by category'), 'description' => $i18n->__('Displays a bar graph of open and closed issues grouped by category'))); $searches['statistics'][self::VIEW_PROJECT_STATISTICS_STATUS] = array(0 => array('title' => $i18n->__('Statistics by status'), 'description' => $i18n->__('Displays a bar graph of open and closed issues grouped by status'))); $searches['statistics'][self::VIEW_PROJECT_STATISTICS_RESOLUTION] = array(0 => array('title' => $i18n->__('Statistics by resolution'), 'description' => $i18n->__('Displays a bar graph of open and closed issues grouped by resolution'))); $searches['statistics'][self::VIEW_PROJECT_STATISTICS_WORKFLOW_STEP] = array(0 => array('title' => $i18n->__('Statistics by workflow step'), 'description' => $i18n->__('Displays a bar graph of open and closed issues grouped by current workflow step'))); $searches['searches'][self::VIEW_PROJECT_RECENT_ISSUES] = $issuetype_icons; break; } return $searches; }
public function componentSidebar() { $savedsearches = tables\SavedSearches::getTable()->getAllSavedSearchesByUserIDAndPossiblyProjectID(framework\Context::getUser()->getID(), framework\Context::isProjectContext() ? framework\Context::getCurrentProject()->getID() : 0); foreach ($savedsearches['user'] as $a_savedsearch) { $this->getResponse()->addFeed(make_url('search', array('saved_search' => $a_savedsearch->getID(), 'search' => true, 'format' => 'rss')), __($a_savedsearch->getName())); } foreach ($savedsearches['public'] as $a_savedsearch) { $this->getResponse()->addFeed(make_url('search', array('saved_search' => $a_savedsearch->getID(), 'search' => true, 'format' => 'rss')), __($a_savedsearch->getName())); } $this->savedsearches = $savedsearches; }
/** * Transition an issue to the outgoing step, based on request data if available * * @param \thebuggenie\core\entities\Issue $issue * @param \thebuggenie\core\framework\Request $request */ public function transitionIssueToOutgoingStepFromRequest(\thebuggenie\core\entities\Issue $issue, $request = null) { $request = $request !== null ? $request : $this->_request; $this->getOutgoingStep()->applyToIssue($issue); if (!empty($this->_validation_errors)) { return false; } foreach ($this->getActions() as $action) { $action->perform($issue, $request); } foreach ($this->getPostValidationRules() as $rule) { if (!$rule->isValid($request)) { $this->_validation_errors[$rule->getRule()] = true; } } if (!empty($this->_validation_errors)) { return false; } if ($request->hasParameter('comment_body') && trim($request['comment_body'] != '')) { $comment = new \thebuggenie\core\entities\Comment(); $comment->setContent($request->getParameter('comment_body', null, false)); $comment->setPostedBy(framework\Context::getUser()->getID()); $comment->setTargetID($issue->getID()); $comment->setTargetType(Comment::TYPE_ISSUE); $comment->setModuleName('core'); $comment->setIsPublic(true); $comment->setSystemComment(false); $comment->save(); $issue->setSaveComment($comment); } $issue->save(); }
public function processIncomingEmailAccount(IncomingEmailAccount $account) { $count = 0; if ($emails = $account->getUnprocessedEmails()) { try { $current_user = framework\Context::getUser(); foreach ($emails as $email) { $user = $this->getOrCreateUserFromEmailString($email->from); if ($user instanceof User) { if (framework\Context::getUser()->getID() != $user->getID()) { framework\Context::switchUserContext($user); } $message = $account->getMessage($email); $data = $message->getBodyPlain() ? $message->getBodyPlain() : strip_tags($message->getBodyHTML()); if ($data) { if (mb_detect_encoding($data, 'UTF-8', true) === false) { $data = utf8_encode($data); } $new_data = ''; foreach (explode("\n", $data) as $line) { $line = trim($line); if ($line) { $line = preg_replace('/^(_{2,}|-{2,})$/', "<hr>", $line); $new_data .= $line . "\n"; } else { $new_data .= "\n"; } } $data = nl2br($new_data, false); } // Parse the subject, and obtain the issues. $parsed_commit = Issue::getIssuesFromTextByRegex(mb_decode_mimeheader($email->subject)); $issues = $parsed_commit["issues"]; // If any issues were found, add new comment to each issue. if ($issues) { foreach ($issues as $issue) { $text = preg_replace('#(^\\w.+:\\n)?(^>.*(\\n|$))+#mi', "", $data); $text = trim($text); if (!$this->processIncomingEmailCommand($text, $issue) && $user->canPostComments()) { $comment = new Comment(); $comment->setContent($text); $comment->setPostedBy($user); $comment->setTargetID($issue->getID()); $comment->setTargetType(Comment::TYPE_ISSUE); $comment->save(); } } } else { if ($user->canReportIssues($account->getProject())) { $issue = new Issue(); $issue->setProject($account->getProject()); $issue->setTitle(mb_decode_mimeheader($email->subject)); $issue->setDescription($data); $issue->setPostedBy($user); $issue->setIssuetype($account->getIssuetype()); $issue->save(); // Append the new issue to the list of affected issues. This // is necessary in order to process the attachments properly. $issues[] = $issue; } } // If there was at least a single affected issue, and mail // contains attachments, add those attachments to related issues. if ($issues && $message->hasAttachments()) { foreach ($message->getAttachments() as $attachment_no => $attachment) { echo 'saving attachment ' . $attachment_no; $name = $attachment['filename']; $new_filename = framework\Context::getUser()->getID() . '_' . NOW . '_' . basename($name); if (framework\Settings::getUploadStorage() == 'files') { $files_dir = framework\Settings::getUploadsLocalpath(); $filename = $files_dir . $new_filename; } else { $filename = $name; } Logging::log('Creating issue attachment ' . $filename . ' from attachment ' . $attachment_no); echo 'Creating issue attachment ' . $filename . ' from attachment ' . $attachment_no; $content_type = $attachment['type'] . '/' . $attachment['subtype']; $file = new File(); $file->setRealFilename($new_filename); $file->setOriginalFilename(basename($name)); $file->setContentType($content_type); $file->setDescription($name); $file->setUploadedBy(framework\Context::getUser()); if (framework\Settings::getUploadStorage() == 'database') { $file->setContent($attachment['data']); } else { Logging::log('Saving file ' . $new_filename . ' with content from attachment ' . $attachment_no); file_put_contents($new_filename, $attachment['data']); } $file->save(); // Attach file to each related issue. foreach ($issues as $issue) { $issue->attachFile($file); } } } $count++; } } } catch (\Exception $e) { } if (framework\Context::getUser()->getID() != $current_user->getID()) { framework\Context::switchUserContext($current_user); } } $account->setTimeLastFetched(time()); $account->setNumberOfEmailsLastFetched($count); $account->save(); return $count; }
public static function getToggle($toggle) { return (bool) self::get(self::TOGGLE_PREFIX . $toggle, 'core', Context::getScope()->getID(), Context::getUser()->getID()); }
protected function _checkProjectPageAccess($page) { return framework\Context::getUser()->hasProjectPageAccess($page, $this->selected_project); }
public function toJSON($detailed = true) { $returnJSON = array('id' => $this->getID(), 'name' => $this->getName(), 'username' => $this->getUsername(), 'type' => 'user'); if ($detailed) { $returnJSON['display_name'] = $this->getDisplayName(); $returnJSON['realname'] = $this->getRealname(); $returnJSON['buddyname'] = $this->getBuddyname(); // Only return email if it is public or we are looking at the currently logged-in user if ($this->isEmailPublic() || framework\Context::getUser()->getID() == $this->getID()) { $returnJSON['email'] = $this->getEmail(); } $returnJSON['avatar'] = $this->getAvatar(); $returnJSON['avatar_url'] = $this->getAvatarURL(false); $returnJSON['avatar_url_small'] = $this->getAvatarURL(true); $returnJSON['url_homepage'] = $this->getHomepage(); $returnJSON['date_joined'] = $this->getJoinedDate(); $returnJSON['last_seen'] = $this->getLastSeen(); $returnJSON['timezone'] = $this->getTimezoneIdentifier(); $returnJSON['language'] = $this->getLanguage(); $returnJSON['state'] = $this->getState()->toJSON(); /* * TODO... */ // $this->getClients(); // $this->getDashboards(); // $this->getDefaultDashboard(); // $this->getFriends(); // $this->getGroup(); // $this->getTeams(); /* * TODO: Return these? */ // $this->isActivated(); // $this->isDeleted(); // $this->isEnabled(); } return $returnJSON; }
public function componentAddDashboardView() { $request = framework\Context::getRequest(); $this->dashboard = entities\Dashboard::getB2DBTable()->selectById($request['dashboard_id']); $this->column = $request['column']; $this->views = entities\DashboardView::getAvailableViews($this->dashboard->getType()); $this->savedsearches = tables\SavedSearches::getTable()->getAllSavedSearchesByUserIDAndPossiblyProjectID(framework\Context::getUser()->getID(), $this->dashboard->getProject() instanceof entities\Project ? $this->dashboard->getProject()->getID() : 0); }
public function doSave($options = array(), $reason = null) { if (tables\Articles::getTable()->doesNameConflictExist($this->_name, $this->_id, framework\Context::getScope()->getID())) { if (!array_key_exists('overwrite', $options) || !$options['overwrite']) { throw new \Exception(framework\Context::getI18n()->__('Another article with this name already exists')); } } $user_id = framework\Context::getUser() instanceof User ? framework\Context::getUser()->getID() : 0; if (!isset($options['revert']) || !$options['revert']) { $revision = tables\ArticleHistory::getTable()->addArticleHistory($this->_name, $this->_old_content, $this->_content, $user_id, $reason); } else { $revision = null; } tables\ArticleLinks::getTable()->deleteLinksByArticle($this->_name); ArticleCategories::getTable()->deleteCategoriesByArticle($this->_name); $this->save(); $this->_old_content = $this->_content; if (mb_substr($this->getContent(), 0, 10) == "#REDIRECT ") { $content = explode("\n", $this->getContent()); preg_match('/(\\[\\[([^\\]]*?)\\]\\])$/im', mb_substr(array_shift($content), 10), $matches); if (count($matches) == 3) { return; } } list($links, $categories) = $this->_retrieveLinksAndCategoriesFromContent($options); foreach ($links as $link => $occurrences) { tables\ArticleLinks::getTable()->addArticleLink($this->_name, $link); } foreach ($categories as $category => $occurrences) { ArticleCategories::getTable()->addArticleCategory($this->_name, $category, $this->isCategory()); } $this->_history = null; \thebuggenie\core\framework\Event::createNew('core', 'thebuggenie\\modules\\publish\\entities\\Article::doSave', $this, compact('reason', 'revision', 'user_id'))->trigger(); return true; }
public function listen_project_links(framework\Event $event) { if (framework\Context::getUser()->hasProjectPageAccess('project_commits', framework\Context::getCurrentProject())) { $event->addToReturnList(array('url' => framework\Context::getRouting()->generate('vcs_commitspage', array('project_key' => framework\Context::getCurrentProject()->getKey())), 'title' => framework\Context::getI18n()->__('Commits'))); } }
protected function _checkArticlePermissions($article_name, $permission_name) { $user = framework\Context::getUser(); switch ($this->getSetting('free_edit')) { case 1: $permissive = !$user->isGuest(); break; case 2: $permissive = true; break; case 0: default: $permissive = false; break; } $retval = $user->hasPermission($permission_name, $article_name, 'publish'); if ($retval !== null) { return $retval; } $namespaces = explode(':', $article_name); if (count($namespaces) > 1) { array_pop($namespaces); $composite_ns = ''; foreach ($namespaces as $namespace) { $composite_ns .= $composite_ns != '' ? ":{$namespace}" : $namespace; $retval = $user->hasPermission($permission_name, $composite_ns, 'publish'); if ($retval !== null) { return $retval; } } } $permissive = $permission_name == self::PERMISSION_READ_ARTICLE ? false : $permissive; $retval = $user->hasPermission($permission_name, 0, 'publish'); return $retval !== null ? $retval : $permissive; }
public function getAccessLevel($section, $module) { return framework\Context::getUser()->canSaveConfiguration($section, $module) ? framework\Settings::ACCESS_FULL : framework\Settings::ACCESS_READ; }
function tbg_get_timezone_offset($skipusertimestamp = false) { // offset the timestamp properly if (!$skipusertimestamp) { $tz = \thebuggenie\core\framework\Context::getUser()->getTimezone(); $tstamp = $tz->getOffset(new DateTime(null, \thebuggenie\core\framework\Settings::getServerTimezone())); } else { $tstamp = \thebuggenie\core\framework\Settings::getServerTimezone()->getOffset(new DateTime('GMT')); } return $tstamp; }
/** * Perform a permission check based on a key, and whether or not to * check if the permission is explicitly set * * @param string $key The permission key to check for * @param boolean $explicit (optional) Whether to make sure the permission is explicitly set * * @return boolean */ public function permissionCheck($key, $explicit = false) { $retval = framework\Context::getUser()->hasPermission($key, $this->getID(), 'core'); if ($explicit) { $retval = $retval !== null ? $retval : framework\Context::getUser()->hasPermission($key, 0, 'core'); } else { $retval = $retval !== null ? $retval : framework\Context::getUser()->hasPermission($key); } return $retval; }
public function isValid($input) { switch ($this->_name) { case self::RULE_MAX_ASSIGNED_ISSUES: $num_issues = (int) $this->getRuleValue(); return $num_issues ? (bool) (count(framework\Context::getUser()->getUserAssignedIssues()) < $num_issues) : true; break; case self::RULE_TEAM_MEMBERSHIP_VALID: $valid_items = explode(',', $this->getRuleValue()); $teams = \thebuggenie\core\entities\Team::getAll(); if ($this->isPost()) { if ($input instanceof \thebuggenie\core\entities\Issue) { $assignee = $input->getAssignee(); } } if (!isset($assignee)) { $assignee = framework\Context::getUser(); } if ($assignee instanceof \thebuggenie\core\entities\User) { if (count($valid_items) == 1 && reset($valid_items) == '') { return true; } foreach ($valid_items as $team_id) { if ($assignee->isMemberOfTeam($teams[$team_id])) { return true; } } } elseif ($assignee instanceof \thebuggenie\core\entities\Team) { foreach ($valid_items as $team_id) { if ($assignee->getID() == $team_id) { return true; } } } return false; case self::RULE_ISSUE_IN_MILESTONE_VALID: $valid_items = explode(',', $this->getRuleValue()); if ($input instanceof \thebuggenie\core\entities\Issue) { $issue = $input; } else { if ($input->hasParameter('issue_id')) { $issue = \thebuggenie\core\entities\Issue::getB2DBTable()->selectByID((int) $input->getParameter('issue_id')); } } if (isset($issue) && $issue instanceof \thebuggenie\core\entities\Issue) { if (!$issue->getMilestone() instanceof \thebuggenie\core\entities\Milestone) { return false; } if (count($valid_items) == 1 && reset($valid_items) == '') { return true; } return in_array($issue->getMilestone()->getID(), $valid_items); } return false; case self::RULE_STATUS_VALID: case self::RULE_PRIORITY_VALID: case self::RULE_RESOLUTION_VALID: case self::RULE_REPRODUCABILITY_VALID: $valid_items = explode(',', $this->getRuleValue()); $valid = false; if ($this->_name == self::RULE_STATUS_VALID) { $fieldname = 'Status'; $fieldname_small = 'status'; } elseif ($this->_name == self::RULE_RESOLUTION_VALID) { $fieldname = 'Resolution'; $fieldname_small = 'resolution'; } elseif ($this->_name == self::RULE_REPRODUCABILITY_VALID) { $fieldname = 'Reproducability'; $fieldname_small = 'reproducability'; } elseif ($this->_name == self::RULE_PRIORITY_VALID) { $fieldname = 'Priority'; $fieldname_small = 'priority'; } else { throw new framework\exceptions\ConfigurationException(framework\Context::getI18n()->__('Invalid workflow validation rule: %rule_name', array('%rule_name' => $this->_name))); } if (!$this->getRuleValue()) { if ($input instanceof \thebuggenie\core\entities\Issue) { $getter = "get{$fieldname}"; if (is_object($input->{$getter}())) { $valid = true; } } elseif ($input instanceof framework\Request) { if ($input->getParameter("{$fieldname_small}_id") && Status::has($input->getParameter("{$fieldname_small}_id"))) { $valid = true; } } } else { foreach ($valid_items as $item) { if ($input instanceof \thebuggenie\core\entities\Issue) { $type = "\\thebuggenie\\core\\entities\\{$fieldname}"; $getter = "get{$fieldname}"; if (is_object($input->{$getter}()) && $type::getB2DBTable()->selectByID((int) $item)->getID() == $input->{$getter}()->getID()) { $valid = true; break; } } elseif ($input instanceof framework\Request) { if ($input->getParameter("{$fieldname_small}_id") == $item) { $valid = true; break; } } } } return $valid; break; default: if ($this->isCustom()) { switch ($this->getCustomType()) { case CustomDatatype::RADIO_CHOICE: case CustomDatatype::DROPDOWN_CHOICE_TEXT: case CustomDatatype::TEAM_CHOICE: case CustomDatatype::STATUS_CHOICE: case CustomDatatype::MILESTONE_CHOICE: case CustomDatatype::CLIENT_CHOICE: case CustomDatatype::COMPONENTS_CHOICE: case CustomDatatype::EDITIONS_CHOICE: case CustomDatatype::RELEASES_CHOICE: $valid_items = explode(',', $this->getRuleValue()); if ($input instanceof \thebuggenie\core\entities\Issue) { $value = $input->getCustomField($this->getCustomFieldname()); } elseif ($input instanceof framework\Request) { $value = $input->getParameter($this->getCustomFieldname() . "_id"); } $valid = false; if (!$this->getRuleValue()) { foreach ($this->getCustomField()->getOptions() as $item) { if ($item->getID() == $value) { $valid = true; break; } } } else { foreach ($valid_items as $item) { if ($value instanceof Identifiable && $value->getID() == $item) { $valid = true; break; } elseif (is_numeric($value) && $value == $item) { $valid = true; break; } } } return $valid; break; } } else { $event = new \thebuggenie\core\framework\Event('core', 'WorkflowTransitionValidationRule::isValid', $this); $event->setReturnValue(false); $event->triggerUntilProcessed(array('input' => $input)); return $event->getReturnValue(); } } }
/** * Whether this user is authenticated or just an authenticated guest * * @return boolean */ public function isAuthenticated() { return (bool) ($this->getID() == framework\Context::getUser()->getID()); }
/** * Add a build (AJAX call) * * @param framework\Request $request The request object */ public function runProjectBuild(framework\Request $request) { $i18n = framework\Context::getI18n(); if ($this->getUser()->canManageProjectReleases($this->selected_project)) { try { if (framework\Context::getUser()->canManageProjectReleases($this->selected_project)) { if (($b_name = $request['build_name']) && trim($b_name) != '') { $build = new entities\Build($request['build_id']); $build->setName($b_name); $build->setVersion($request->getParameter('ver_mj', 0), $request->getParameter('ver_mn', 0), $request->getParameter('ver_rev', 0)); $build->setReleased((bool) $request['isreleased']); $build->setLocked((bool) $request['locked']); if ($request['milestone'] && ($milestone = entities\Milestone::getB2DBTable()->selectById($request['milestone']))) { $build->setMilestone($milestone); } else { $build->clearMilestone(); } if ($request['edition'] && ($edition = entities\Edition::getB2DBTable()->selectById($request['edition']))) { $build->setEdition($edition); } else { $build->clearEdition(); } $release_date = null; if ($request['has_release_date']) { $release_date = mktime($request['release_hour'], $request['release_minute'], 1, $request['release_month'], $request['release_day'], $request['release_year']); } $build->setReleaseDate($release_date); switch ($request->getParameter('download', 'leave_file')) { case '0': $build->clearFile(); $build->setFileURL(''); break; case 'upload_file': if ($build->hasFile()) { $build->getFile()->delete(); $build->clearFile(); } $file = framework\Context::getRequest()->handleUpload('upload_file'); $build->setFile($file); $build->setFileURL(''); break; case 'url': $build->clearFile(); $build->setFileURL($request['file_url']); break; } if (!$build->getID()) { $build->setProject($this->selected_project); } $build->save(); } else { throw new \Exception($i18n->__('You need to specify a name for the release')); } } else { throw new \Exception($i18n->__('You do not have access to this project')); } } catch (\Exception $e) { framework\Context::setMessage('build_error', $e->getMessage()); } $this->forward(framework\Context::getRouting()->generate('project_release_center', array('project_key' => $this->selected_project->getKey()))); } return $this->forward403($i18n->__("You don't have access to add releases")); }
/** * Assign a user story to a milestone id * * @Route(url="/assign/issue/milestone/:milestone_id") * * @param framework\Request $request */ public function runAssignMilestone(framework\Request $request) { $this->forward403if(framework\Context::getCurrentProject()->isArchived()); $this->forward403unless($this->_checkProjectPageAccess('project_scrum') && framework\Context::getUser()->canAssignScrumUserStories($this->selected_project)); try { $issue = \thebuggenie\core\entities\Issue::getB2DBTable()->selectById((int) $request['issue_id']); $milestone = \thebuggenie\core\entities\tables\Milestones::getTable()->selectById($request['milestone_id']); if (!$issue instanceof \thebuggenie\core\entities\Issue) { throw new \Exception($this->getI18n()->__('This is not a valid issue')); } $issue->setMilestone($milestone); $issue->save(); foreach ($issue->getChildIssues() as $child_issue) { $child_issue->setMilestone($milestone); $child_issue->save(); } $new_issues = $milestone instanceof \thebuggenie\core\entities\Milestone ? $milestone->countIssues() : 0; $new_e_points = $milestone instanceof \thebuggenie\core\entities\Milestone ? $milestone->getPointsEstimated() : 0; $new_e_hours = $milestone instanceof \thebuggenie\core\entities\Milestone ? $milestone->getHoursEstimated() : 0; return $this->renderJSON(array('issue_id' => $issue->getID(), 'issues' => $new_issues, 'points' => $new_e_points, 'hours' => $new_e_hours)); } catch (\Exception $e) { $this->getResponse()->setHttpStatus(400); return $this->renderJSON(array('error' => $e->getMessage())); } }
public function hasAccess() { return (bool) (framework\Context::getUser()->hasPageAccess('teamlist') || framework\Context::getUser()->isMemberOfTeam($this)); }
/** * Handles an uploaded file, stores it to the correct folder, adds an entry * to the database and returns a \thebuggenie\core\entities\File object * * @param string $key The request parameter the file was sent as * * @return \thebuggenie\core\entities\File The File object */ public function handleUpload($key) { $apc_exists = self::CanGetUploadStatus(); if ($apc_exists && !array_key_exists($this->getParameter('APC_UPLOAD_PROGRESS'), $_SESSION['__upload_status'])) { $_SESSION['__upload_status'][$this->getParameter('APC_UPLOAD_PROGRESS')] = array('id' => $this->getParameter('APC_UPLOAD_PROGRESS'), 'finished' => false, 'percent' => 0, 'total' => 0, 'complete' => 0); } try { if ($this->getUploadedFile($key) !== null) { $thefile = $this->getUploadedFile($key); if (Settings::isUploadsEnabled()) { Logging::log('Uploads enabled'); if ($thefile['error'] == UPLOAD_ERR_OK) { Logging::log('No upload errors'); if (filesize($thefile['tmp_name']) > Settings::getUploadsEffectiveMaxSize(true)) { throw new \Exception(Context::getI18n()->__('You cannot upload files bigger than %max_size MB', array('%max_size' => Settings::getUploadsEffectiveMaxSize()))); } Logging::log('Upload filesize ok'); $extension = mb_substr(basename($thefile['name']), mb_strrpos(basename($thefile['name']), '.')); if ($extension == '') { Logging::log('OOps, could not determine upload filetype', 'main', Logging::LEVEL_WARNING_RISK); //throw new \Exception(Context::getI18n()->__('Could not determine filetype')); } else { Logging::log('Checking uploaded file extension'); $extension = mb_substr($extension, 1); $upload_extensions = Settings::getUploadsExtensionsList(); if (Settings::getUploadsRestrictionMode() == 'blacklist') { Logging::log('... using blacklist'); foreach ($upload_extensions as $an_ext) { if (mb_strtolower(trim($extension)) == mb_strtolower(trim($an_ext))) { Logging::log('Upload extension not ok'); throw new \Exception(Context::getI18n()->__('This filetype is not allowed')); } } Logging::log('Upload extension ok'); } else { Logging::log('... using whitelist'); $is_ok = false; foreach ($upload_extensions as $an_ext) { if (mb_strtolower(trim($extension)) == mb_strtolower(trim($an_ext))) { Logging::log('Upload extension ok'); $is_ok = true; break; } } if (!$is_ok) { Logging::log('Upload extension not ok'); throw new \Exception(Context::getI18n()->__('This filetype is not allowed')); } } /*if (in_array(mb_strtolower(trim($extension)), array('php', 'asp'))) { Logging::log('Upload extension is php or asp'); throw new \Exception(Context::getI18n()->__('This filetype is not allowed')); }*/ } if (is_uploaded_file($thefile['tmp_name'])) { Logging::log('Uploaded file is uploaded'); $new_filename = Context::getUser()->getID() . '_' . NOW . '_' . basename($thefile['name']); if (Settings::getUploadStorage() == 'files') { $files_dir = Settings::getUploadsLocalpath(); $filename = $files_dir . $new_filename; } else { $filename = $thefile['tmp_name']; } Logging::log('Moving uploaded file to ' . $filename); if (Settings::getUploadStorage() == 'files' && !move_uploaded_file($thefile['tmp_name'], $filename)) { Logging::log('Moving uploaded file failed!'); throw new \Exception(Context::getI18n()->__('An error occured when saving the file')); } else { Logging::log('Upload complete and ok, storing upload status and returning filename ' . $new_filename); $content_type = File::getMimeType($filename); $file = new File(); $file->setRealFilename($new_filename); $file->setOriginalFilename(basename($thefile['name'])); $file->setContentType($content_type); $file->setDescription($this->getParameter($key . '_description')); $file->setUploadedBy(Context::getUser()); if (Settings::getUploadStorage() == 'database') { $file->setContent(file_get_contents($filename)); } $file->save(); if ($apc_exists) { $_SESSION['__upload_status'][$this->getParameter('APC_UPLOAD_PROGRESS')] = array('id' => $this->getParameter('APC_UPLOAD_PROGRESS'), 'finished' => true, 'percent' => 100, 'total' => 0, 'complete' => 0, 'file_id' => $file->getID()); } return $file; } } else { Logging::log('Uploaded file was not uploaded correctly'); throw new \Exception(Context::getI18n()->__('The file was not uploaded correctly')); } } else { Logging::log('Upload error: ' . $thefile['error']); switch ($thefile['error']) { case UPLOAD_ERR_INI_SIZE: case UPLOAD_ERR_FORM_SIZE: throw new \Exception(Context::getI18n()->__('You cannot upload files bigger than %max_size MB', array('%max_size' => Settings::getUploadsEffectiveMaxSize()))); case UPLOAD_ERR_PARTIAL: throw new \Exception(Context::getI18n()->__('The upload was interrupted, please try again')); case UPLOAD_ERR_NO_FILE: throw new \Exception(Context::getI18n()->__('No file was uploaded')); default: throw new \Exception(Context::getI18n()->__('An unhandled error occured') . ': ' . $thefile['error']); } } } else { Logging::log('Uploads not enabled'); throw new \Exception(Context::getI18n()->__('Uploads are not enabled')); } } Logging::log('Could not find uploaded file' . $key); throw new \Exception(Context::getI18n()->__('Could not find the uploaded file. Please make sure that it is not too big.')); } catch (\Exception $e) { Logging::log('Upload exception: ' . $e->getMessage()); if ($apc_exists) { $_SESSION['__upload_status'][$this->getParameter('APC_UPLOAD_PROGRESS')]['error'] = $e->getMessage(); $_SESSION['__upload_status'][$this->getParameter('APC_UPLOAD_PROGRESS')]['finished'] = true; $_SESSION['__upload_status'][$this->getParameter('APC_UPLOAD_PROGRESS')]['percent'] = 100; } throw $e; } }
public function perform(\thebuggenie\core\entities\Issue $issue, $request = null) { switch ($this->_action_type) { case self::ACTION_ASSIGN_ISSUE_SELF: $issue->setAssignee(framework\Context::getUser()); break; case self::ACTION_SET_STATUS: if ($this->getTargetValue()) { $issue->setStatus(Status::getB2DBTable()->selectById((int) $this->getTargetValue())); } else { $issue->setStatus($request['status_id']); } break; case self::ACTION_CLEAR_MILESTONE: $issue->setMilestone(null); break; case self::ACTION_SET_MILESTONE: if ($this->getTargetValue()) { $issue->setMilestone(Milestone::getB2DBTable()->selectById((int) $this->getTargetValue())); } else { $issue->setMilestone($request['milestone_id']); } break; case self::ACTION_CLEAR_PRIORITY: $issue->setPriority(null); break; case self::ACTION_SET_PRIORITY: if ($this->getTargetValue()) { $issue->setPriority(Priority::getB2DBTable()->selectById((int) $this->getTargetValue())); } else { $issue->setPriority($request['priority_id']); } break; case self::ACTION_CLEAR_PERCENT: $issue->setPercentCompleted(0); break; case self::ACTION_SET_PERCENT: if ($this->getTargetValue()) { $issue->setPercentCompleted((int) $this->getTargetValue()); } else { $issue->setPercentCompleted((int) $request['percent_complete_id']); } break; case self::ACTION_CLEAR_DUPLICATE: $issue->setDuplicateOf(null); break; case self::ACTION_SET_DUPLICATE: $issue->setDuplicateOf($request['duplicate_issue_id']); break; case self::ACTION_CLEAR_RESOLUTION: $issue->setResolution(null); break; case self::ACTION_SET_RESOLUTION: if ($this->getTargetValue()) { $issue->setResolution(Resolution::getB2DBTable()->selectById((int) $this->getTargetValue())); } else { $issue->setResolution($request['resolution_id']); } break; case self::ACTION_CLEAR_REPRODUCABILITY: $issue->setReproducability(null); break; case self::ACTION_SET_REPRODUCABILITY: if ($this->getTargetValue()) { $issue->setReproducability(Reproducability::getB2DBTable()->selectById((int) $this->getTargetValue())); } else { $issue->setReproducability($request['reproducability_id']); } break; case self::ACTION_CLEAR_ASSIGNEE: $issue->clearAssignee(); break; case self::ACTION_ASSIGN_ISSUE: if ($this->getTargetValue()) { $target_details = explode('_', $this->_target_value); if ($target_details[0] == 'user') { $assignee = \thebuggenie\core\entities\User::getB2DBTable()->selectById((int) $target_details[1]); } else { $assignee = Team::getB2DBTable()->selectById((int) $target_details[1]); } $issue->setAssignee($assignee); } else { $assignee = null; switch ($request['assignee_type']) { case 'user': $assignee = \thebuggenie\core\entities\User::getB2DBTable()->selectById((int) $request['assignee_id']); break; case 'team': $assignee = Team::getB2DBTable()->selectById((int) $request['assignee_id']); break; } if ((bool) $request->getParameter('assignee_teamup', false) && $assignee instanceof \thebuggenie\core\entities\User && $assignee->getID() != framework\Context::getUser()->getID()) { $team = new \thebuggenie\core\entities\Team(); $team->setName($assignee->getBuddyname() . ' & ' . framework\Context::getUser()->getBuddyname()); $team->setOndemand(true); $team->save(); $team->addMember($assignee); $team->addMember(framework\Context::getUser()); $assignee = $team; } $issue->setAssignee($assignee); } break; case self::ACTION_USER_START_WORKING: $issue->clearUserWorkingOnIssue(); if ($issue->getAssignee() instanceof \thebuggenie\core\entities\Team && $issue->getAssignee()->isOndemand()) { $members = $issue->getAssignee()->getMembers(); $issue->startWorkingOnIssue(array_shift($members)); } elseif ($issue->getAssignee() instanceof \thebuggenie\core\entities\User) { $issue->startWorkingOnIssue($issue->getAssignee()); } break; case self::ACTION_USER_STOP_WORKING: if ($request->getParameter('did', 'nothing') == 'nothing') { $issue->clearUserWorkingOnIssue(); } elseif ($request->getParameter('did', 'nothing') == 'this') { $times = array(); if ($request['timespent_manual']) { $times = Issue::convertFancyStringToTime($request['timespent_manual']); } elseif ($request['timespent_specified_type']) { $times = array('points' => 0, 'hours' => 0, 'days' => 0, 'weeks' => 0, 'months' => 0); $times[$request['timespent_specified_type']] = $request['timespent_specified_value']; } if (array_sum($times) > 0) { $times['hours'] *= 100; $spenttime = new \thebuggenie\core\entities\IssueSpentTime(); $spenttime->setIssue($issue); $spenttime->setUser(framework\Context::getUser()); $spenttime->setSpentPoints($times['points']); $spenttime->setSpentHours($times['hours']); $spenttime->setSpentDays($times['days']); $spenttime->setSpentWeeks($times['weeks']); $spenttime->setSpentMonths($times['months']); $spenttime->setActivityType($request['timespent_activitytype']); $spenttime->setComment($request['timespent_comment']); $spenttime->save(); } $issue->clearUserWorkingOnIssue(); } else { $issue->stopWorkingOnIssue(); } break; default: if (strpos($this->_action_type, self::CUSTOMFIELD_CLEAR_PREFIX) === 0) { $customkey = substr($this->_action_type, strlen(self::CUSTOMFIELD_CLEAR_PREFIX)); $issue->setCustomField($customkey, null); } elseif (strpos($this->_action_type, self::CUSTOMFIELD_SET_PREFIX) === 0) { $customkey = substr($this->_action_type, strlen(self::CUSTOMFIELD_SET_PREFIX)); if ($this->getTargetValue()) { $issue->setCustomField($customkey, $this->getTargetValue()); } else { $issue->setCustomField($customkey, $request[$customkey . '_id']); } } else { $event = new \thebuggenie\core\framework\Event('core', 'WorkflowTransitionAction::perform', $issue, array('request' => $request)); $event->triggerUntilProcessed(); } } }
protected function _postSave($is_new) { if ($is_new) { if ($this->_getParser()->hasMentions()) { foreach ($this->_getParser()->getMentions() as $user) { if ($user->getID() == framework\Context::getUser()->getID()) { continue; } $this->_addNotification(Notification::TYPE_ARTICLE_MENTIONED, $user, $this->getAuthor()); } } } }
protected function _getAvailableUserChoices() { $me = framework\Context::getUser(); $filters = array($me->getID() => $me); foreach ($me->getFriends() as $user) { $filters[$user->getID()] = $user; } if (count($this->getValues())) { $users = tables\Users::getTable()->getByUserIDs($this->getValues()); foreach ($users as $user) { $filters[$user->getID()] = $user; } } return $filters; }
/** * Whether or not the current user can access the milestones * * @return boolean */ public function hasAccess() { return $this->getProject()->canSeeAllMilestones() || framework\Context::getUser()->hasPermission('canseemilestone', $this->getID()); }
protected function _postSave($is_new) { $this->_saveCustomFieldValues(); if (!$is_new) { $related_issues_to_save = $this->_processChanges(); $comment = isset($this->_save_comment) ? $this->_save_comment : $this->addSystemComment('', framework\Context::getUser()->getID()); $this->triggerSaveEvent($comment, framework\Context::getUser()); if (count($related_issues_to_save)) { foreach (array_keys($related_issues_to_save) as $i_id) { $related_issue = \thebuggenie\core\entities\Issue::getB2DBTable()->selectById((int) $i_id); $related_issue->save(); } } } else { $_description_parser = $this->_getDescriptionParser(); $_reproduction_steps_parser = $this->_getReproductionStepsParser(); if (!is_null($_description_parser) && $_description_parser->hasMentions()) { foreach ($_description_parser->getMentions() as $user) { if ($user->getID() == framework\Context::getUser()->getID()) { continue; } $this->_addNotification(Notification::TYPE_ISSUE_MENTIONED, $user, $this->getPostedBy()); } } if (!is_null($_reproduction_steps_parser) && $_reproduction_steps_parser->hasMentions()) { foreach ($_reproduction_steps_parser->getMentions() as $user) { if ($user->getID() == framework\Context::getUser()->getID()) { continue; } $this->_addNotification(Notification::TYPE_ISSUE_MENTIONED, $user, $this->getPostedBy()); } } $this->addLogEntry(tables\Log::LOG_ISSUE_CREATED, null, false, $this->getPosted()); $this->_addCreateNotifications($this->getPostedBy()); \thebuggenie\core\framework\Event::createNew('core', 'thebuggenie\\core\\entities\\Issue::createNew', $this)->trigger(); } if (in_array(\thebuggenie\core\framework\Settings::getUserSetting(\thebuggenie\core\framework\Settings::SETTINGS_USER_SUBSCRIBE_CREATED_UPDATED_COMMENTED_ISSUES, framework\Context::getUser()->getID()), array(null, true))) { $this->addSubscriber(framework\Context::getUser()->getID()); } $this->_clearChangedProperties(); $this->_log_items_added = array(); $this->getProject()->clearRecentActivities(); if ($this->isChildIssue() && ($this->hasEstimatedTime() || $this->hasSpentTime())) { foreach ($this->getParentIssues() as $issue) { $issue->calculateTime(); $issue->save(); } } if ($this->getMilestone() instanceof \thebuggenie\core\entities\Milestone) { $this->getMilestone()->updateStatus(); $this->getMilestone()->save(); } return true; }