protected function _initialize()
 {
     parent::_setup(self::B2DBNAME, self::ID);
     parent::_addForeignKeyColumn(self::PROJECT_ID, Projects::getTable());
     parent::_addForeignKeyColumn(self::USER_ID, Users::getTable());
     parent::_addForeignKeyColumn(self::ROLE_ID, ListTypes::getTable());
 }
Exemple #2
0
 protected function _initialize()
 {
     parent::_setup(self::B2DBNAME, self::ID);
     parent::_addBoolean(self::CONFIRMED);
     parent::_addForeignKeyColumn(self::USER_ID, Users::getTable(), Users::ID);
     parent::_addForeignKeyColumn(self::GROUP_ID, Groups::getTable(), Groups::ID);
 }
Exemple #3
0
 protected function _initialize()
 {
     parent::_setup(self::B2DBNAME, self::ID);
     parent::_addInteger(self::TARGET, 10);
     parent::_addInteger(self::VOTE, 2);
     parent::_addForeignKeyColumn(self::UID, Users::getTable(), Users::ID);
 }
Exemple #4
0
 protected function _initialize()
 {
     parent::_setup(self::B2DBNAME, self::ID);
     parent::_addForeignKeyColumn(self::UID, Users::getTable(), Users::ID);
     parent::_addForeignKeyColumn(self::ISSUE_ID, Issues::getTable(), Issues::ID);
     parent::_addForeignKeyColumn(self::FILE_ID, Files::getTable(), Files::ID);
     parent::_addInteger(self::ATTACHED_AT, 10);
 }
 protected function _initialize()
 {
     parent::_setup(self::B2DBNAME, self::ID);
     parent::_addForeignKeyColumn(self::UID, \thebuggenie\core\entities\tables\Users::getTable(), \thebuggenie\core\entities\tables\Users::ID);
     parent::_addForeignKeyColumn(self::ARTICLE_ID, Articles::getTable(), Articles::ID);
     parent::_addForeignKeyColumn(self::FILE_ID, \thebuggenie\core\entities\tables\Files::getTable(), \thebuggenie\core\entities\tables\Files::ID);
     parent::_addInteger(self::ATTACHED_AT, 10);
 }
 protected function _initialize()
 {
     parent::_setup(self::B2DBNAME, self::ID);
     parent::_addVarchar(self::IDENTITY, 300);
     parent::_addVarchar(self::IDENTITY_HASH, 300);
     parent::_addVarchar(self::EMAIL, 300);
     parent::_addVarchar(self::TYPE, 300);
     parent::_addForeignKeyColumn(self::UID, Users::getTable(), Users::ID);
 }
Exemple #7
0
 protected function _initialize()
 {
     parent::_setup(self::B2DBNAME, self::ID);
     parent::_addVarchar(self::URL, 300);
     parent::_addInteger(self::LINK_ORDER, 3);
     parent::_addVarchar(self::TARGET_TYPE, 30);
     parent::_addInteger(self::TARGET_ID, 10);
     parent::_addVarchar(self::DESCRIPTION, 100, '');
     parent::_addForeignKeyColumn(self::UID, Users::getTable(), Users::ID);
 }
 protected function _parse_mention($matches)
 {
     $user = \thebuggenie\core\entities\tables\Users::getTable()->getByUsername($matches[1]);
     if ($user instanceof \thebuggenie\core\entities\User) {
         $output = framework\Action::returnComponentHTML('main/userdropdown_inline', array('user' => $matches[1], 'displayname' => $matches[0]));
         $this->mentions[$user->getID()] = $user;
     } else {
         $output = $matches[0];
     }
     return $output;
 }
 protected function _initialize()
 {
     parent::_setup(self::B2DBNAME, self::ID);
     parent::_addVarchar(self::ARTICLE_NAME, 255);
     parent::_addText(self::OLD_CONTENT, false);
     parent::_addText(self::NEW_CONTENT, false);
     parent::_addVarchar(self::REASON, 255);
     parent::_addInteger(self::DATE, 10);
     parent::_addInteger(self::REVISION, 10);
     parent::_addForeignKeyColumn(self::AUTHOR, \thebuggenie\core\entities\tables\Users::getTable(), \thebuggenie\core\entities\tables\Users::ID);
 }
 protected function _initialize()
 {
     parent::_setup(self::B2DBNAME, self::ID);
     parent::_addForeignKeyColumn(self::ISSUE_ID, Issues::getTable(), Issues::ID);
     parent::_addForeignKeyColumn(self::EDITED_BY, Users::getTable(), Users::ID);
     parent::_addInteger(self::EDITED_AT, 10);
     parent::_addInteger(self::ESTIMATED_MONTHS, 10);
     parent::_addInteger(self::ESTIMATED_WEEKS, 10);
     parent::_addInteger(self::ESTIMATED_DAYS, 10);
     parent::_addInteger(self::ESTIMATED_HOURS, 10);
     parent::_addFloat(self::ESTIMATED_POINTS);
 }
Exemple #11
0
 protected function _initialize()
 {
     parent::_setup(self::B2DBNAME, self::ID);
     parent::_addVarchar(self::PERMISSION_TYPE, 100);
     parent::_addVarchar(self::TARGET_ID, 200, 0);
     parent::_addBoolean(self::ALLOWED);
     parent::_addVarchar(self::MODULE, 50);
     parent::_addForeignKeyColumn(self::UID, Users::getTable());
     parent::_addForeignKeyColumn(self::GID, Groups::getTable());
     parent::_addForeignKeyColumn(self::TID, Teams::getTable());
     parent::_addForeignKeyColumn(self::ROLE_ID, ListTypes::getTable());
 }
Exemple #12
0
 public function componentUserdropdown()
 {
     framework\Logging::log('user dropdown component');
     $this->rnd_no = rand();
     try {
         if (!$this->user instanceof entities\User) {
             framework\Logging::log('loading user object in dropdown');
             if (is_numeric($this->user)) {
                 $this->user = tables\Users::getTable()->getByUserId($this->user);
             } else {
                 $this->user = tables\Users::getTable()->getByUsername($this->user);
             }
             framework\Logging::log('done (loading user object in dropdown)');
         }
     } catch (\Exception $e) {
     }
     $this->show_avatar = isset($this->show_avatar) ? $this->show_avatar : true;
     framework\Logging::log('done (user dropdown component)');
 }
Exemple #13
0
 public function runAuthenticate(framework\Request $request)
 {
     $username = trim($request['username']);
     $password = trim($request['password']);
     if ($username) {
         $user = tables\Users::getTable()->getByUsername($username);
         if ($password && $user instanceof entities\User) {
             foreach ($user->getApplicationPasswords() as $app_password) {
                 if (!$app_password->isUsed()) {
                     if ($app_password->getHashPassword() == entities\User::hashPassword($password, $user->getSalt())) {
                         $app_password->useOnce();
                         $app_password->save();
                         return $this->renderJSON(array('token' => $app_password->getHashPassword()));
                     }
                 }
             }
         }
     }
     $this->getResponse()->setHttpStatus(400);
     return $this->renderJSON(array('error' => 'Incorrect username or application password'));
 }
Exemple #14
0
 protected function _initialize()
 {
     parent::_setup(self::B2DBNAME, self::ID);
     parent::_addForeignKeyColumn(self::UID, Users::getTable());
     parent::_addForeignKeyColumn(self::TID, Teams::getTable());
 }
Exemple #15
0
 public function runFilterFindUsers(framework\Request $request)
 {
     $filter = $request['filter'];
     $filterkey = $request['filterkey'];
     $existing_users = $request['existing_id'];
     if (strlen($filter) < 3) {
         return $this->renderJSON(array('results' => '<li>' . $this->getI18n()->__('Please enter 3 characters or more') . '</li>'));
     }
     $users = tables\Users::getTable()->getByDetails($filter, 10);
     foreach ($existing_users as $id) {
         if (isset($users[$id])) {
             unset($users[$id]);
         }
     }
     return $this->renderJSON(array('results' => $this->getComponentHTML('search/filterfindusers', compact('users', 'filterkey'))));
 }
 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;
 }
Exemple #17
0
 protected function _addUpdateNotifications($updated_by)
 {
     $uids = tables\UserIssues::getTable()->getUserIDsByIssueID($this->getID());
     $users = tables\Users::getTable()->getByUserIDs($uids);
     foreach ($users as $user) {
         if ($user->getNotificationSetting(framework\Settings::SETTINGS_USER_NOTIFY_SUBSCRIBED_ISSUES, false)->isOn() && $this->isSubscriber($user)) {
             $subscribed_category_id = $user->getNotificationSetting(\thebuggenie\core\framework\Settings::SETTINGS_USER_SUBSCRIBE_NEW_ISSUES_MY_PROJECTS_CATEGORY, null)->getValue();
             if ($subscribed_category_id === null || $subscribed_category_id == 0 || $this->getCategory() instanceof Category && $this->getCategory()->getID() == $subscribed_category_id) {
                 $this->_addNotificationIfNotNotified(Notification::TYPE_ISSUE_UPDATED, $user, $updated_by);
             }
         }
     }
 }
Exemple #18
0
 /**
  * Find users and show selection box
  *
  * @param framework\Request $request The request object
  */
 public function runFindAssignee(framework\Request $request)
 {
     $this->forward403unless($request->isPost());
     $this->message = false;
     if ($request['find_by']) {
         $this->selected_project = entities\Project::getB2DBTable()->selectById($request['project_id']);
         $this->users = tables\Users::getTable()->getByDetails($request['find_by'], 10);
         $this->teams = tables\Teams::getTable()->quickfind($request['find_by']);
         $this->global_roles = entities\Role::getAll();
         $this->project_roles = entities\Role::getByProjectID($this->selected_project->getID());
     } else {
         $this->message = true;
     }
 }
Exemple #19
0
 public function doLogin($username, $password, $mode = 1)
 {
     $validgroups = $this->getSetting('groups');
     $base_dn = $this->getSetting('b_dn');
     $dn_attr = $this->escape($this->getSetting('dn_attr'));
     $username_attr = $this->escape($this->getSetting('u_attr'));
     $fullname_attr = $this->escape($this->getSetting('f_attr'));
     $buddyname_attr = $this->escape($this->getSetting('b_attr'));
     $email_attr = $this->escape($this->getSetting('e_attr'));
     $groups_members_attr = $this->escape($this->getSetting('g_attr'));
     $user_class = framework\Context::getModule('auth_ldap')->getSetting('u_type');
     $group_class = framework\Context::getModule('auth_ldap')->getSetting('g_type');
     $email = null;
     $integrated_auth = $this->getSetting('integrated_auth');
     /*
      * Do the LDAP check here.
      *
      * If a connection error or something, throw an exception and log
      *
      * If we can, set $mail and $realname to correct values from LDAP
      * otherwise don't touch those variables.
      *
      * To log do:
      * framework\Logging::log('error goes here', 'ldap', framework\Logging::LEVEL_FATAL);
      */
     try {
         /*
          * First job is to connect to our control user (may be an anonymous bind)
          * so we can find the user we want to log in as/validate.
          */
         $connection = $this->connect();
         $control_user = $this->getSetting('control_user');
         $control_password = $this->getSetting('control_pass');
         $this->bind($connection, $control_user, $control_password);
         // Assume bind successful, otherwise we would have had an exception
         /*
          * Search for a user with the username specified. We search in the base_dn, so we can
          * find users in multiple parts of the directory, and only return users of a specific
          * class (default person).
          *
          * We want exactly 1 user to be returned. We get the user's full name, email, cn
          * and dn.
          */
         $fields = array($fullname_attr, $buddyname_attr, $email_attr, 'cn', $dn_attr);
         $filter = '(&(objectClass=' . $this->escape($user_class) . ')(' . $username_attr . '=' . $this->escape($username) . '))';
         $results = ldap_search($connection, $base_dn, $filter, $fields);
         if (!$results) {
             framework\Logging::log('failed to search for user: '******'ldap', framework\Logging::LEVEL_FATAL);
             throw new \Exception(framework\Context::geti18n()->__('Search failed: ') . ldap_error($connection));
         }
         $data = ldap_get_entries($connection, $results);
         // User does not exist
         if ($data['count'] == 0) {
             framework\Logging::log('could not find user ' . $username . ', class ' . $user_class . ', attribute ' . $username_attr, 'ldap', framework\Logging::LEVEL_FATAL);
             throw new \Exception(framework\Context::geti18n()->__('User does not exist in the directory'));
         }
         // If we have more than 1 user, something is seriously messed up...
         if ($data['count'] > 1) {
             framework\Logging::log('too many users for ' . $username . ', class ' . $user_class . ', attribute ' . $username_attr, 'ldap', framework\Logging::LEVEL_FATAL);
             throw new \Exception(framework\Context::geti18n()->__('This user was found multiple times in the directory, please contact your administrator'));
         }
         /*
          * If groups are specified, perform group restriction tests
          */
         if ($validgroups != '') {
             /*
              * We will repeat this for every group, but groups are supplied as a comma-separated list
              */
             if (strstr($validgroups, ',')) {
                 $groups = explode(',', $validgroups);
             } else {
                 $groups = array();
                 $groups[] = $validgroups;
             }
             // Assumed we are initially banned
             $allowed = false;
             foreach ($groups as $group) {
                 // No need to carry on looking if we have access
                 if ($allowed == true) {
                     continue;
                 }
                 /*
                  * Find the group we are looking for, we search the entire directory as per users (See that stuff)
                  * We want to find 1 group, if we don't get 1, silently ignore this group.
                  */
                 $fields2 = array($groups_members_attr);
                 $filter2 = '(&(objectClass=' . $this->escape($group_class) . ')(cn=' . $this->escape($group) . '))';
                 $results2 = ldap_search($connection, $base_dn, $filter2, $fields2);
                 if (!$results2) {
                     framework\Logging::log('failed to search for user after binding: ' . ldap_error($connection), 'ldap', framework\Logging::LEVEL_FATAL);
                     throw new \Exception(framework\Context::geti18n()->__('Search failed ') . ldap_error($connection));
                 }
                 $data2 = ldap_get_entries($connection, $results2);
                 if ($data2['count'] != 1) {
                     continue;
                 }
                 /*
                  * Look through the group's member list. If we are found, grant access.
                  */
                 foreach ($data2[0][strtolower($groups_members_attr)] as $member) {
                     $member = preg_replace('/(?<=,) +(?=[a-zA-Z])/', '', $member);
                     $user_dn = preg_replace('/(?<=,) +(?=[a-zA-Z])/', '', $data[0][strtolower($dn_attr)][0]);
                     if (!is_numeric($member) && strtolower($member) == strtolower($user_dn)) {
                         $allowed = true;
                     }
                 }
             }
             if ($allowed == false) {
                 throw new \Exception(framework\Context::getI18n()->__('You are not a member of a group allowed to log in'));
             }
         }
         /*
          * Set user's properties.
          * Realname is obtained from directory, if not found we set it to the username
          * Email is obtained from directory, if not found we set it to blank
          */
         if (!array_key_exists(strtolower($fullname_attr), $data[0])) {
             $realname = $username;
         } else {
             $realname = $data[0][strtolower($fullname_attr)][0];
         }
         if (!array_key_exists(strtolower($buddyname_attr), $data[0])) {
             $buddyname = $username;
         } else {
             $buddyname = $data[0][strtolower($buddyname_attr)][0];
         }
         if (!array_key_exists(strtolower($email_attr), $data[0])) {
             $email = '';
         } else {
             $email = $data[0][strtolower($email_attr)][0];
         }
         /*
          * If we are performing a non integrated authentication login,
          * now bind to the user and see if the credentials
          * are valid. We bind using the full DN of the user, so no need for DOMAIN\ stuff
          * on Windows, and more importantly it fixes other servers.
          *
          * If the bind fails (exception), we throw a nicer exception and don't continue.
          */
         if ($mode == 1 && !$integrated_auth) {
             try {
                 if (!is_array($data[0][strtolower($dn_attr)])) {
                     $dn = $data[0][strtolower($dn_attr)];
                 } else {
                     $dn = $data[0][strtolower($dn_attr)][0];
                 }
                 $bind = $this->bind($connection, $this->escape($dn), $password);
             } catch (\Exception $e) {
                 throw new \Exception(framework\Context::geti18n()->__('Your password was not accepted by the server'));
             }
         } elseif ($mode == 1) {
             if (!isset($_SERVER[$this->getSetting('integrated_auth_header')]) || $_SERVER[$this->getSetting('integrated_auth_header')] != $username) {
                 throw new \Exception(framework\Context::geti18n()->__('HTTP authentication internal error.'));
             }
         }
     } catch (\Exception $e) {
         ldap_unbind($connection);
         throw $e;
     }
     try {
         /*
          * Get the user object. If the user exists, update the user's
          * data from the directory.
          */
         $user = \thebuggenie\core\entities\User::getByUsername($username);
         if ($user instanceof \thebuggenie\core\entities\User) {
             $user->setBuddyname($buddyname);
             $user->setRealname($realname);
             $user->setPassword($user->getJoinedDate() . $username);
             // update password
             $user->setEmail($email);
             // update email address
             $user->save();
         } else {
             /*
              * If not, and we are performing an initial login, create the user object
              * if we are validating a log in, kick the user out as the session is invalid.
              */
             if ($mode == 1) {
                 // create user
                 $user = new \thebuggenie\core\entities\User();
                 $user->setUsername($username);
                 $user->setRealname('temporary');
                 $user->setBuddyname($username);
                 $user->setEmail('temporary');
                 $user->setEnabled();
                 $user->setActivated();
                 $user->setJoined();
                 $user->setPassword($user->getJoinedDate() . $username);
                 $user->save();
             } else {
                 throw new \Exception('User does not exist in TBG');
             }
         }
     } catch (\Exception $e) {
         ldap_unbind($connection);
         throw $e;
     }
     ldap_unbind($connection);
     /*
      * Set cookies and return user row for general operations.
      */
     framework\Context::getResponse()->setCookie('tbg3_username', $username);
     framework\Context::getResponse()->setCookie('tbg3_password', \thebuggenie\core\entities\User::hashPassword($user->getJoinedDate() . $username, $user->getSalt()));
     return \thebuggenie\core\entities\tables\Users::getTable()->getByUsername($username);
 }
Exemple #20
0
 protected function _addUpdateNotifications($updated_by)
 {
     $uids = tables\UserIssues::getTable()->getUserIDsByIssueID($this->getID());
     $users = tables\Users::getTable()->getByUserIDs($uids);
     foreach ($users as $user) {
         $this->_addNotification(Notification::TYPE_ISSUE_UPDATED, $user, $updated_by);
     }
 }
Exemple #21
0
 protected function _parse_mention($matches)
 {
     $matched_user = $matches[1];
     $use_dot = false;
     if (mb_substr($matched_user, -1) === '.') {
         $matched_user = mb_substr($matched_user, 0, -1);
         $use_dot = true;
     }
     $user = \thebuggenie\core\entities\tables\Users::getTable()->getByUsername($matched_user);
     if ($user instanceof \thebuggenie\core\entities\User) {
         $output = framework\Action::returnComponentHTML('main/userdropdown_inline', array('user' => $matched_user, 'in_email' => isset($this->options['in_email']) ? $this->options['in_email'] : false));
         if ($use_dot) {
             $output .= '.';
         }
         $this->mentions[$user->getID()] = $user;
     } else {
         $output = $matches[0];
     }
     return $output;
 }
Exemple #22
0
 protected function _upgradeFrom3dot2(framework\Request $request)
 {
     set_time_limit(0);
     \thebuggenie\core\entities\tables\Milestones::getTable()->upgrade(\thebuggenie\core\modules\installation\upgrade_32\TBGMilestone::getB2DBTable());
     \thebuggenie\core\entities\tables\Projects::getTable()->upgrade(\thebuggenie\core\modules\installation\upgrade_32\TBGProjectsTable::getTable());
     \thebuggenie\core\entities\tables\Log::getTable()->upgrade(\thebuggenie\core\modules\installation\upgrade_32\TBGLogTable::getTable());
     \thebuggenie\core\entities\tables\Users::getTable()->upgrade(\thebuggenie\core\modules\installation\upgrade_32\TBGUsersTable::getTable());
     \thebuggenie\core\entities\tables\Issues::getTable()->upgrade(\thebuggenie\core\modules\installation\upgrade_32\TBGIssuesTable::getTable());
     \thebuggenie\core\entities\tables\Workflows::getTable()->upgrade(\thebuggenie\core\modules\installation\upgrade_32\TBGWorkflowsTable::getTable());
     \thebuggenie\core\entities\tables\IssueSpentTimes::getTable()->upgrade(\thebuggenie\core\modules\installation\upgrade_32\TBGIssueSpentTimesTable::getTable());
     \thebuggenie\core\entities\tables\Comments::getTable()->upgrade(\thebuggenie\core\modules\installation\upgrade_32\TBGCommentsTable::getTable());
     \thebuggenie\core\entities\tables\SavedSearches::getTable()->upgrade(\thebuggenie\core\modules\installation\upgrade_32\TBGSavedSearchesTable::getTable());
     \thebuggenie\core\entities\tables\Settings::getTable()->upgrade(\thebuggenie\core\modules\installation\upgrade_32\TBGSettingsTable::getTable());
     \thebuggenie\core\entities\tables\Notifications::getTable()->upgrade(\thebuggenie\core\modules\installation\upgrade_32\TBGNotificationsTable::getTable());
     \thebuggenie\core\entities\tables\Permissions::getTable()->upgrade(\thebuggenie\core\modules\installation\upgrade_32\TBGPermissionsTable::getTable());
     \thebuggenie\core\entities\Dashboard::getB2DBTable()->create();
     \thebuggenie\core\entities\DashboardView::getB2DBTable()->upgrade(\thebuggenie\core\modules\installation\upgrade_32\TBGDashboardViewsTable::getTable());
     \thebuggenie\core\entities\ApplicationPassword::getB2DBTable()->create();
     \thebuggenie\core\entities\NotificationSetting::getB2DBTable()->create();
     $transaction = \b2db\Core::startTransaction();
     // Upgrade user passwords
     switch ($request['upgrade_passwords']) {
         case 'manual':
             $password = $request['manual_password'];
             foreach (\thebuggenie\core\entities\tables\Users::getTable()->selectAll() as $user) {
                 $user->setPassword($password);
                 $user->save();
             }
             break;
         case 'auto':
             $field = $request['upgrade_passwords_pick'] == 'username' ? 'username' : 'email';
             foreach (\thebuggenie\core\entities\tables\Users::getTable()->selectAll() as $user) {
                 if ($field == 'username' && trim($user->getUsername())) {
                     $user->setPassword(trim($user->getUsername()));
                     $user->save();
                 } elseif ($field == 'email' && trim($user->getEmail())) {
                     $user->setPassword(trim($user->getEmail()));
                     $user->save();
                 }
             }
             break;
     }
     $adminuser = \thebuggenie\core\entities\User::getB2DBTable()->selectById(1);
     $adminuser->setPassword($request['admin_password']);
     $adminuser->save();
     // Add new settings
     framework\Settings::saveSetting(framework\Settings::SETTING_SERVER_TIMEZONE, 'core', date_default_timezone_get(), 0, 1);
     foreach ($request->getParameter('status') as $scope_id => $status_id) {
         $scope = \thebuggenie\core\entities\tables\Scopes::getTable()->selectById((int) $scope_id);
         if ($scope instanceof \thebuggenie\core\entities\Scope) {
             $epic = new \thebuggenie\core\entities\Issuetype();
             $epic->setName('Epic');
             $epic->setIcon('epic');
             $epic->setDescription('Issue type suited for entering epics');
             $epic->setScope($scope_id);
             $epic->save();
             framework\Settings::saveSetting('issuetype_epic', $epic->getID(), 'core', $scope_id);
             foreach (\thebuggenie\core\entities\tables\Workflows::getTable()->getAll((int) $scope_id) as $workflow) {
                 $transition = new \thebuggenie\core\entities\WorkflowTransition();
                 $steps = $workflow->getSteps();
                 $step = array_shift($steps);
                 $step->setLinkedStatusID((int) $status_id);
                 $step->save();
                 $transition->setOutgoingStep($step);
                 $transition->setName('Issue created');
                 $transition->setWorkflow($workflow);
                 $transition->setScope($scope);
                 $transition->setDescription('This is the initial transition for issues using this workflow');
                 $transition->save();
                 $workflow->setInitialTransition($transition);
                 $workflow->save();
             }
             \thebuggenie\core\entities\ActivityType::loadFixtures($scope);
         }
     }
     $transaction->commitAndEnd();
     framework\Context::finishUpgrading();
     foreach (framework\Context::getModules() as $module) {
         $module->upgrade();
     }
     $this->upgrade_complete = true;
 }
Exemple #23
0
 /**
  * Find users and show selection links
  *
  * @param \thebuggenie\core\framework\Request $request The request object
  */
 public function runFindIdentifiable(framework\Request $request)
 {
     $this->forward403unless($request->isPost());
     $users = array();
     if ($find_identifiable_by = $request['find_identifiable_by']) {
         if ($request['include_clients']) {
             $clients = tables\Clients::getTable()->quickfind($find_identifiable_by);
         } else {
             $users = tables\Users::getTable()->getByDetails($find_identifiable_by, 10);
             if ($request['include_teams']) {
                 $teams = tables\Teams::getTable()->quickfind($find_identifiable_by);
             } else {
                 $teams = array();
             }
         }
     }
     $teamup_callback = $request['teamup_callback'];
     $team_callback = $request['team_callback'];
     $callback = $request['callback'];
     return $this->renderComponent('identifiableselectorresults', compact('users', 'teams', 'clients', 'callback', 'teamup_callback', 'team_callback'));
 }
Exemple #24
0
 public function runFindUsers(framework\Request $request)
 {
     $this->too_short = false;
     $findstring = $request['findstring'];
     if (mb_strlen($findstring) >= 1) {
         $this->users = tables\Users::getTable()->findInConfig($findstring);
         $this->total_results = count($this->users);
     } else {
         $this->too_short = true;
     }
     switch ($findstring) {
         case 'unactivated':
             $this->findstring = framework\Context::getI18n()->__('Unactivated users');
             break;
         case 'newusers':
             $this->findstring = framework\Context::getI18n()->__('New users');
             break;
         case 'all':
             $this->findstring = framework\Context::getI18n()->__('All users');
             break;
         default:
             $this->findstring = $findstring;
     }
 }
Exemple #25
0
 /**
  * Returns the scope administrator
  *
  * @return \thebuggenie\core\entities\User
  */
 public function getScopeAdmin()
 {
     if (!$this->_administrator instanceof \thebuggenie\core\entities\User && $this->_administrator != 0) {
         try {
             $this->_administrator = tables\Users::getTable()->selectById($this->_administrator);
         } catch (\Exception $e) {
         }
     }
     return $this->_administrator;
 }
Exemple #26
0
 /**
  * Authenticate an application using a one-time application password.
  * Creates a token to be used for subsequent requests.
  * 
  * @param framework\Request $request
  */
 public function runAuthenticate(framework\Request $request)
 {
     framework\Logging::log('Authenticating new application password.', 'api', framework\Logging::LEVEL_INFO);
     $username = trim($request['username']);
     $password = trim($request['password']);
     if ($username) {
         $user = tables\Users::getTable()->getByUsername($username);
         if ($password && $user instanceof entities\User) {
             // Generate token from the application password
             $token = entities\ApplicationPassword::createToken($password);
             // Crypt, for comparison with db value
             $hashed_token = entities\User::hashPassword($token, $user->getSalt());
             foreach ($user->getApplicationPasswords() as $app_password) {
                 // Only return the token for new application passwords!
                 if (!$app_password->isUsed()) {
                     if ($app_password->getHashPassword() == $hashed_token) {
                         $app_password->useOnce();
                         $app_password->save();
                         return $this->renderJSON(array('token' => $token, 'name' => $app_password->getName(), 'created_at' => $app_password->getCreatedAt()));
                     }
                 }
             }
         }
         framework\Logging::log('No password matched.', 'api', framework\Logging::LEVEL_INFO);
     }
     $this->getResponse()->setHttpStatus(400);
     return $this->renderJSON(array('error' => 'Incorrect username or application password'));
 }
 public static function processCommit(\thebuggenie\core\entities\Project $project, $commit_msg, $old_rev, $new_rev, $date = null, $changed, $author, $branch = null, \Closure $callback = null)
 {
     $output = '';
     framework\Context::setCurrentProject($project);
     if ($project->isArchived()) {
         return;
     }
     if (Commits::getTable()->isProjectCommitProcessed($new_rev, $project->getID())) {
         return;
     }
     try {
         framework\Context::getI18n();
     } catch (\Exception $e) {
         framework\Context::reinitializeI18n(null);
     }
     // Is VCS Integration enabled?
     if (framework\Settings::get('vcs_mode_' . $project->getID(), 'vcs_integration') == self::MODE_DISABLED) {
         $output .= '[VCS ' . $project->getKey() . '] This project does not use VCS Integration' . "\n";
         return $output;
     }
     // Parse the commit message, and obtain the issues and transitions for issues.
     $parsed_commit = \thebuggenie\core\entities\Issue::getIssuesFromTextByRegex($commit_msg);
     $issues = $parsed_commit["issues"];
     $transitions = $parsed_commit["transitions"];
     // Build list of affected files
     $file_lines = preg_split('/[\\n\\r]+/', $changed);
     $files = array();
     foreach ($file_lines as $aline) {
         $action = mb_substr($aline, 0, 1);
         if ($action == "A" || $action == "U" || $action == "D" || $action == "M") {
             $theline = trim(mb_substr($aline, 1));
             $files[] = array($action, $theline);
         }
     }
     // Find author of commit, fallback is guest
     /*
      * Some VCSes use a different format of storing the committer's name. Systems like bzr, git and hg use the format
      * Joe Bloggs <*****@*****.**>, instead of a classic username. Therefore a user will be found via 4 queries:
      * a) First we extract the email if there is one, and find a user with that email
      * b) If one is not found - or if no email was specified, then instead test against the real name (using the name part if there was an email)
      * c) the username or full name is checked against the friendly name field
      * d) and if we still havent found one, then we check against the username
      * e) and if we STILL havent found one, we use the guest user
      */
     // a)
     $user = \thebuggenie\core\entities\tables\Users::getTable()->getByEmail($author);
     if (!$user instanceof \thebuggenie\core\entities\User && preg_match("/(?<=<)(.*)(?=>)/", $author, $matches)) {
         $email = $matches[0];
         // a2)
         $user = \thebuggenie\core\entities\tables\Users::getTable()->getByEmail($email);
         if (!$user instanceof \thebuggenie\core\entities\User) {
             // Not found by email
             preg_match("/(?<=^)(.*)(?= <)/", $author, $matches);
             $author = $matches[0];
         }
     }
     // b)
     if (!$user instanceof \thebuggenie\core\entities\User) {
         $user = \thebuggenie\core\entities\tables\Users::getTable()->getByRealname($author);
     }
     // c)
     if (!$user instanceof \thebuggenie\core\entities\User) {
         $user = \thebuggenie\core\entities\tables\Users::getTable()->getByBuddyname($author);
     }
     // d)
     if (!$user instanceof \thebuggenie\core\entities\User) {
         $user = \thebuggenie\core\entities\tables\Users::getTable()->getByUsername($author);
     }
     // e)
     if (!$user instanceof \thebuggenie\core\entities\User) {
         $user = framework\Settings::getDefaultUser();
     }
     framework\Context::setUser($user);
     framework\Settings::forceSettingsReload();
     framework\Context::cacheAllPermissions();
     $output .= '[VCS ' . $project->getKey() . '] Commit to be logged by user ' . $user->getName() . "\n";
     if ($date == null) {
         $date = NOW;
     }
     // Create the commit data
     $commit = new Commit();
     $commit->setAuthor($user);
     $commit->setDate($date);
     $commit->setLog($commit_msg);
     $commit->setPreviousRevision($old_rev);
     $commit->setRevision($new_rev);
     $commit->setProject($project);
     if ($branch !== null) {
         $data = 'branch:' . $branch;
         $commit->setMiscData($data);
     }
     if ($callback !== null) {
         $commit = $callback($commit);
     }
     $commit->save();
     $output .= '[VCS ' . $project->getKey() . '] Commit logged with revision ' . $commit->getRevision() . "\n";
     // Iterate over affected issues and update them.
     foreach ($issues as $issue) {
         $inst = new IssueLink();
         $inst->setIssue($issue);
         $inst->setCommit($commit);
         $inst->save();
         // Process all commit-message transitions for an issue.
         foreach ($transitions[$issue->getFormattedIssueNo()] as $transition) {
             if (framework\Settings::get('vcs_workflow_' . $project->getID(), 'vcs_integration') == self::WORKFLOW_ENABLED) {
                 framework\Context::setUser($user);
                 framework\Settings::forceSettingsReload();
                 framework\Context::cacheAllPermissions();
                 if ($issue->isWorkflowTransitionsAvailable()) {
                     // Go through the list of possible transitions for an issue. Only
                     // process transitions that are applicable to issue's workflow.
                     foreach ($issue->getAvailableWorkflowTransitions() as $possible_transition) {
                         if (mb_strtolower($possible_transition->getName()) == mb_strtolower($transition[0])) {
                             $output .= '[VCS ' . $project->getKey() . '] Running transition ' . $transition[0] . ' on issue ' . $issue->getFormattedIssueNo() . "\n";
                             // String representation of parameters. Used for log message.
                             $parameters_string = "";
                             // Iterate over the list of this transition's parameters, and
                             // set them.
                             foreach ($transition[1] as $parameter => $value) {
                                 $parameters_string .= "{$parameter}={$value} ";
                                 switch ($parameter) {
                                     case 'resolution':
                                         if (($resolution = \thebuggenie\core\entities\Resolution::getByKeyish($value)) instanceof \thebuggenie\core\entities\Resolution) {
                                             framework\Context::getRequest()->setParameter('resolution_id', $resolution->getID());
                                         }
                                         break;
                                     case 'status':
                                         if (($status = \thebuggenie\core\entities\Status::getByKeyish($value)) instanceof \thebuggenie\core\entities\Status) {
                                             framework\Context::getRequest()->setParameter('status_id', $status->getID());
                                         }
                                         break;
                                 }
                             }
                             // Run the transition.
                             $possible_transition->transitionIssueToOutgoingStepWithoutRequest($issue);
                             // Log an informative message about the transition.
                             $output .= '[VCS ' . $project->getKey() . '] Ran transition ' . $possible_transition->getName() . ' with parameters \'' . $parameters_string . '\' on issue ' . $issue->getFormattedIssueNo() . "\n";
                         }
                     }
                 }
             }
         }
         $issue->addSystemComment(framework\Context::getI18n()->__('This issue has been updated with the latest changes from the code repository.<source>%commit_msg</source>', array('%commit_msg' => $commit_msg)), $user->getID());
         $output .= '[VCS ' . $project->getKey() . '] Updated issue ' . $issue->getFormattedIssueNo() . "\n";
     }
     // Create file links
     foreach ($files as $afile) {
         // index 0 is action, index 1 is file
         $inst = new File();
         $inst->setAction($afile[0]);
         $inst->setFile($afile[1]);
         $inst->setCommit($commit);
         $inst->save();
         $output .= '[VCS ' . $project->getKey() . '] Added with action ' . $afile[0] . ' file ' . $afile[1] . "\n";
     }
     framework\Event::createNew('vcs_integration', 'new_commit')->trigger(array('commit' => $commit));
     return $output;
 }
Exemple #28
0
 /**
  * Returns an array with everyone related to this project
  *
  * @return array|\thebuggenie\core\entities\User
  */
 public function getRelatedUsers()
 {
     $uids = array();
     $teams = array();
     // Add the author
     $uids[$this->getAuthorID()] = $this->getAuthorID();
     if ($this->getProject() instanceof \thebuggenie\core\entities\Project) {
         // Add all users in the team who leads the project, if valid
         // or add the user who leads the project, if valid
         if ($this->getProject()->getLeader() instanceof \thebuggenie\core\entities\Team) {
             $teams[$this->getProject()->getLeader()->getID()] = $this->getProject()->getLeader();
         } elseif ($this->getProject()->getLeader() instanceof \thebuggenie\core\entities\User) {
             $uids[$this->getProject()->getLeader()->getID()] = $this->getProject()->getLeader()->getID();
         }
         // Same for QA
         if ($this->getProject()->getQaResponsible() instanceof \thebuggenie\core\entities\Team) {
             $teams[$this->getProject()->getQaResponsible()->getID()] = $this->getProject()->getQaResponsible();
         } elseif ($this->getProject()->getQaResponsible() instanceof \thebuggenie\core\entities\User) {
             $uids[$this->getProject()->getQaResponsible()->getID()] = $this->getProject()->getQaResponsible()->getID();
         }
         foreach ($this->getProject()->getAssignedTeams() as $team) {
             $teams[$team->getID()] = $team;
         }
         foreach ($this->getProject()->getAssignedUsers() as $member) {
             $uids[$member->getID()] = $member->getID();
         }
     }
     foreach ($teams as $team) {
         foreach ($team->getMembers() as $user) {
             $uids[$user->getID()] = $user->getID();
         }
     }
     if (framework\Context::getUser() and isset($uids[framework\Context::getUser()->getID()])) {
         unset($uids[framework\Context::getUser()->getID()]);
     }
     $users = \thebuggenie\core\entities\tables\Users::getTable()->getByUserIDs($uids);
     return $users;
 }
Exemple #29
0
 public function findIssues($filters = array(), $results_per_page = 30, $offset = 0, $groupby = null, $grouporder = null, $sortfields = array(self::LAST_UPDATED => 'asc'), $include_deleted = false)
 {
     $crit = $this->getCriteria();
     if (!$include_deleted) {
         $crit->addWhere(self::DELETED, false);
     }
     $crit->addWhere(self::SCOPE, framework\Context::getScope()->getID());
     if (count($filters) > 0) {
         $crit->addJoin(IssueCustomFields::getTable(), IssueCustomFields::ISSUE_ID, Issues::ID);
         $crit->addJoin(IssueAffectsComponent::getTable(), IssueAffectsComponent::ISSUE, self::ID);
         $crit->addJoin(IssueAffectsEdition::getTable(), IssueAffectsEdition::ISSUE, self::ID);
         $crit->addJoin(IssueAffectsBuild::getTable(), IssueAffectsBuild::ISSUE, self::ID);
         $filter_keys = array_keys($filters);
         foreach ($filters as $filter) {
             self::parseFilter($crit, $filter, $filter_keys);
         }
     }
     $crit->addSelectionColumn(self::ID);
     $crit->setDistinct();
     if ($offset != 0) {
         $crit->setOffset($offset);
     }
     $crit2 = clone $crit;
     $count = $this->doCount($crit2);
     if ($count > 0) {
         $crit3 = $this->getCriteria();
         if ($results_per_page != 0) {
             $crit->setLimit($results_per_page);
         }
         if ($offset != 0) {
             $crit->setOffset($offset);
         }
         if ($groupby !== null) {
             $grouporder = $grouporder !== null ? $grouporder == 'asc' ? Criteria::SORT_ASC : Criteria::SORT_DESC : Criteria::SORT_ASC;
             switch ($groupby) {
                 case 'category':
                     $crit->addJoin(ListTypes::getTable(), ListTypes::ID, self::CATEGORY);
                     $crit->addSelectionColumn(ListTypes::NAME);
                     $crit->addOrderBy(ListTypes::NAME, $grouporder);
                     $crit3->addJoin(ListTypes::getTable(), ListTypes::ID, self::CATEGORY);
                     $crit3->addOrderBy(ListTypes::NAME, $grouporder);
                     break;
                 case 'status':
                     $crit->addJoin(ListTypes::getTable(), ListTypes::ID, self::STATUS);
                     $crit->addSelectionColumn(self::STATUS);
                     $crit->addOrderBy(ListTypes::ORDER, Criteria::SORT_DESC);
                     $crit3->addJoin(ListTypes::getTable(), ListTypes::ID, self::STATUS);
                     $crit3->addOrderBy(ListTypes::ORDER, Criteria::SORT_DESC);
                     break;
                 case 'milestone':
                     $crit->addSelectionColumn(self::MILESTONE);
                     $crit->addSelectionColumn(self::PERCENT_COMPLETE);
                     $crit->addOrderBy(self::MILESTONE, $grouporder);
                     $crit->addOrderBy(self::PERCENT_COMPLETE, 'desc');
                     $crit3->addOrderBy(self::MILESTONE, $grouporder);
                     $crit3->addOrderBy(self::PERCENT_COMPLETE, 'desc');
                     break;
                 case 'assignee':
                     $crit->addSelectionColumn(self::ASSIGNEE_TEAM);
                     $crit->addSelectionColumn(self::ASSIGNEE_USER);
                     $crit->addOrderBy(self::ASSIGNEE_TEAM);
                     $crit->addOrderBy(self::ASSIGNEE_USER, $grouporder);
                     $crit3->addOrderBy(self::ASSIGNEE_TEAM);
                     $crit3->addOrderBy(self::ASSIGNEE_USER, $grouporder);
                     break;
                 case 'posted_by':
                     $crit->addJoin(Users::getTable(), Users::ID, self::POSTED_BY);
                     $crit3->addJoin(Users::getTable(), Users::ID, self::POSTED_BY);
                     $crit->addSelectionColumn(self::POSTED_BY);
                     $crit->addSelectionColumn(Users::UNAME);
                     $crit->addOrderBy(Users::UNAME, $grouporder);
                     $crit3->addOrderBy(Users::UNAME, $grouporder);
                     break;
                 case 'state':
                     $crit->addSelectionColumn(self::STATE);
                     $crit->addOrderBy(self::STATE, $grouporder);
                     $crit3->addOrderBy(self::STATE, $grouporder);
                     break;
                 case 'posted':
                     $crit->addSelectionColumn(self::POSTED);
                     $crit->addOrderBy(self::POSTED, $grouporder);
                     $crit3->addOrderBy(self::POSTED, $grouporder);
                     break;
                 case 'severity':
                     $crit->addJoin(ListTypes::getTable(), ListTypes::ID, self::SEVERITY);
                     $crit->addSelectionColumn(self::SEVERITY);
                     $crit->addOrderBy(ListTypes::ORDER, $grouporder);
                     $crit3->addJoin(ListTypes::getTable(), ListTypes::ID, self::SEVERITY);
                     $crit3->addOrderBy(ListTypes::ORDER, $grouporder);
                     break;
                 case 'user_pain':
                     $crit->addSelectionColumn(self::USER_PAIN);
                     $crit->addOrderBy(self::USER_PAIN, $grouporder);
                     $crit3->addOrderBy(self::USER_PAIN, $grouporder);
                     break;
                 case 'votes':
                     $crit->addSelectionColumn(self::VOTES_TOTAL);
                     $crit->addOrderBy(self::VOTES_TOTAL, $grouporder);
                     $crit3->addOrderBy(self::VOTES_TOTAL, $grouporder);
                     break;
                 case 'resolution':
                     $crit->addJoin(ListTypes::getTable(), ListTypes::ID, self::RESOLUTION);
                     $crit->addSelectionColumn(self::RESOLUTION);
                     $crit->addOrderBy(ListTypes::ORDER, $grouporder);
                     $crit3->addJoin(ListTypes::getTable(), ListTypes::ID, self::RESOLUTION);
                     $crit3->addOrderBy(ListTypes::ORDER, $grouporder);
                     break;
                 case 'priority':
                     $crit->addJoin(ListTypes::getTable(), ListTypes::ID, self::PRIORITY);
                     $crit->addSelectionColumn(self::PRIORITY);
                     $crit->addOrderBy(ListTypes::ORDER, $grouporder);
                     $crit3->addJoin(ListTypes::getTable(), ListTypes::ID, self::PRIORITY);
                     $crit3->addOrderBy(ListTypes::ORDER, $grouporder);
                     break;
                 case 'issuetype':
                     $crit->addJoin(IssueTypes::getTable(), IssueTypes::ID, self::ISSUE_TYPE);
                     $crit->addSelectionColumn(IssueTypes::NAME);
                     $crit->addOrderBy(IssueTypes::NAME, $grouporder);
                     $crit3->addJoin(IssueTypes::getTable(), IssueTypes::ID, self::ISSUE_TYPE);
                     $crit3->addOrderBy(IssueTypes::NAME, $grouporder);
                     break;
                 case 'edition':
                     $crit->addJoin(IssueAffectsEdition::getTable(), IssueAffectsEdition::ISSUE, self::ID);
                     $crit->addJoin(Editions::getTable(), Editions::ID, IssueAffectsEdition::EDITION, array(), Criteria::DB_LEFT_JOIN, IssueAffectsEdition::getTable());
                     $crit->addSelectionColumn(Editions::NAME);
                     $crit->addOrderBy(Editions::NAME, $grouporder);
                     $crit3->addJoin(IssueAffectsEdition::getTable(), IssueAffectsEdition::ISSUE, self::ID);
                     $crit3->addJoin(Editions::getTable(), Editions::ID, IssueAffectsEdition::EDITION, array(), Criteria::DB_LEFT_JOIN, IssueAffectsEdition::getTable());
                     $crit3->addOrderBy(Editions::NAME, $grouporder);
                     break;
                 case 'build':
                     $crit->addJoin(IssueAffectsBuild::getTable(), IssueAffectsBuild::ISSUE, self::ID);
                     $crit->addJoin(Builds::getTable(), Builds::ID, IssueAffectsBuild::BUILD, array(), Criteria::DB_LEFT_JOIN, IssueAffectsBuild::getTable());
                     $crit->addSelectionColumn(Builds::NAME);
                     $crit->addOrderBy(Builds::NAME, $grouporder);
                     $crit3->addJoin(IssueAffectsBuild::getTable(), IssueAffectsBuild::ISSUE, self::ID);
                     $crit3->addJoin(Builds::getTable(), Builds::ID, IssueAffectsBuild::BUILD, array(), Criteria::DB_LEFT_JOIN, IssueAffectsBuild::getTable());
                     $crit3->addOrderBy(Builds::NAME, $grouporder);
                     break;
                 case 'component':
                     $crit->addJoin(IssueAffectsComponent::getTable(), IssueAffectsComponent::ISSUE, self::ID);
                     $crit->addJoin(Components::getTable(), Components::ID, IssueAffectsComponent::COMPONENT, array(), Criteria::DB_LEFT_JOIN, IssueAffectsComponent::getTable());
                     $crit->addSelectionColumn(Components::NAME);
                     $crit->addOrderBy(Components::NAME, $grouporder);
                     $crit3->addJoin(IssueAffectsComponent::getTable(), IssueAffectsComponent::ISSUE, self::ID);
                     $crit3->addJoin(Components::getTable(), Components::ID, IssueAffectsComponent::COMPONENT, array(), Criteria::DB_LEFT_JOIN, IssueAffectsComponent::getTable());
                     $crit3->addOrderBy(Components::NAME, $grouporder);
                     break;
             }
         }
         foreach ($sortfields as $field => $sortorder) {
             $crit->addSelectionColumn($field);
             $crit->addOrderBy($field, $sortorder);
         }
         $res = $this->doSelect($crit, 'none');
         $ids = array();
         if ($res) {
             while ($row = $res->getNextRow()) {
                 $ids[] = $row->get(self::ID);
             }
             $ids = array_reverse($ids);
             $crit3->addWhere(self::ID, $ids, Criteria::DB_IN);
             foreach ($sortfields as $field => $sortorder) {
                 $crit3->addOrderBy($field, $sortorder);
             }
             $res = $this->doSelect($crit3);
             $rows = $res->getAllRows();
         } else {
             $rows = array();
         }
         unset($res);
         return array($rows, $count, $ids);
     } else {
         return array(null, 0, array());
     }
 }
Exemple #30
0
 protected function _addUpdateNotifications($updated_by)
 {
     $uids = tables\UserIssues::getTable()->getUserIDsByIssueID($this->getID());
     $users = tables\Users::getTable()->getByUserIDs($uids);
     foreach ($users as $user) {
         if ($user->getNotificationSetting(framework\Settings::SETTINGS_USER_NOTIFY_SUBSCRIBED_ISSUES, false)->isOn() && $this->isSubscriber($user)) {
             $this->_addNotificationIfNotNotified(Notification::TYPE_ISSUE_UPDATED, $user, $updated_by);
         }
     }
 }