public function info($id) { $action = isset($_REQUEST['action']) ? $_REQUEST['action'] : false; $this->write('tab', isset($_REQUEST['tab']) ? $_REQUEST['tab'] : ""); $reqUserId = Session::uid(); $this->write('reqUserId', $reqUserId); $reqUser = new User(); if ($reqUserId > 0) { $reqUser->findUserById($reqUserId); $budget = $reqUser->getBudget(); } $this->write('reqUser', $reqUser); $is_runner = isset($_SESSION['is_runner']) ? $_SESSION['is_runner'] : 0; $is_payer = isset($_SESSION['is_payer']) ? $_SESSION['is_payer'] : 0; // admin posting data if (!empty($_POST) && ($is_runner || $is_payer) && !$action) { $user_id = (int) $_POST['user_id']; if (!empty($_POST['save-salary'])) { $field = 'salary'; $value = mysql_real_escape_string($_POST['value']); } else { $field = $_POST['field']; $value = (int) $_POST['value']; } $updateUser = new User(); if ($updateUser->findUserById($user_id)) { switch ($field) { case 'salary': $updateUser->setAnnual_salary($value); Utils::systemNotification("A new salary has been set for @" . $updateUser->getNickname()); break; case 'ispayer': $updateUser->setIs_payer($value); break; case 'isrunner': $updateUser->setIs_runner($value); break; case 'isinternal': $updateUser->setIs_internal($value); break; case 'ispaypalverified': $updateUser->setPaypal_verified($value); if ($value) { $updateUser->setHas_w2(false); } break; case 'isw2employee': $updateUser->setHas_w2($value); if ($value) { $updateUser->setPaypal_verified(false); $updateUser->setw9_status('not-applicable'); } break; case 'manager': $updateUser->setManager($value); if ($value) { $manager = new User(); $manager->findUserById($value); // Send journal notification Utils::systemNotification("The manager for @" . $updateUser->getNickname() . " is now set to @" . $manager->getNickname()); } else { Utils::systemNotification("The manager for @" . $updateUser->getNickname() . " has been removed"); } break; case 'referrer': $updateUser->setReferred_by($value); if ($value) { $referrer = new User(); $referrer->findUserById($value); // Send journal notification Utils::systemNotification("The referrer for @" . $updateUser->getNickname() . " is now set to @" . $referrer->getNickname()); } else { Utils::systemNotification("The referrer for @" . $updateUser->getNickname() . " has been removed"); } break; case 'isactive': $updateUser->setIs_active($value); break; default: break; } $updateUser->save(); $response = array('succeeded' => true, 'message' => 'User details updated successfully'); echo json_encode($response); exit(0); } else { die(json_encode(array('succeeded' => false, 'message' => 'Error: Could not determine the user_id'))); } } $user = new User(); $user = User::find($id ? $id : Session::uid()); $userId = $user->getId(); /** * If we couldn't find a valid User, return an ErrorView */ if (!$user->getId()) { $this->write('msg', 'That user doesn\'t exist.'); $this->write('link', WORKLIST_URL); $this->view = new ErrorView(); parent::run(); } $this->write('userId', $userId); $this->write('user', $user); $this->write('Annual_Salary', $user->getAnnual_salary() > 0 ? $user->getAnnual_salary() : ''); $this->write('manager', $user->getManager()); $this->write('referred_by', $user->getReferred_by()); if ($action == 'create-sandbox') { $result = array(); try { if (!$is_runner) { throw new Exception("Access Denied"); } $args = array('unixusername', 'projects'); foreach ($args as $arg) { ${$arg} = mysql_real_escape_string($_REQUEST[$arg]); } $projectList = explode(",", str_replace(" ", "", $projects)); // Create sandbox for user $sandboxUtil = new SandBoxUtil(); $sandboxUtil->createSandbox($user->getUsername(), $user->getNickname(), $unixusername, $projectList); // If sb creation was successful, update users table $user->setHas_sandbox(1); $user->setUnixusername($unixusername); $user->setProjects_checkedout($projects); $user->save(); // add to project_users table foreach ($projectList as $project) { $project_id = Project::getIdFromRepo($project); $user->checkoutProject($project_id); } } catch (Exception $e) { $result["error"] = $e->getMessage(); } echo json_encode($result); die; } $reviewee_id = (int) $userId; $review = new Review(); $this->write('reviewsList', $review->getReviews($reviewee_id, $reqUserId)); $this->write('projects', $this->getProjectList()); $user_projects = $user->getProjects_checkedout(); $this->write('has_sandbox', count($user_projects) > 0); $users_favorite = new Users_Favorite(); $favorite_enabled = 1; $favorite = $users_favorite->getMyFavoriteForUser($reqUserId, $userId); if (isset($favorite['favorite'])) { $favorite_enabled = $favorite['favorite']; } $favorite_count = $users_favorite->getUserFavoriteCount($userId); $this->write('favorite_count', $favorite_count); $this->write('favorite_enabled', $favorite_enabled); parent::run(); }
/** * Given a user's chosen nickname, generate their unixusername. * This is done by: * - lowercasing their nickname * - stripping non-alphanumeric * - verifying uniqueness in passwd file & user table * - if not unique, append a number :/ * (not the greatest, but it can be changed later) * */ public function generateUnixUsername($nickname) { // lowercase $unixname = strtolower($nickname); // find alphanumeric-only parts to use as unixname $disallowed_characters = "/[^a-z0-9]/"; $unixname = preg_replace($disallowed_characters, "", $unixname); // make sure first character is alpha character (can't start w/ a #) if (preg_match("/^[a-z]/", $unixname) == 0) { // lets not be fancy.. just prepend an "a" to their name. $unixname = "a" . $unixname; } // append numbers to the end of the name if it's not unique // to both the password file AND the user table // Test SanboxUtil last since that could be a remote call $attempted_unixname = $unixname; $x = 0; while (User::unixusernameExists($attempted_unixname) || SandBoxUtil::inPasswdFile($attempted_unixname)) { $x++; $attempted_unixname = $unixname . $x; } $unixname = $attempted_unixname; return $unixname; }
protected function changeStatus($workitem, $newStatus, $user) { $allowable = array("Draft", "Suggestion", "Code Review", "QA Ready", "Pass", "Merged"); if ($workitem->getIsRelRunner() || $user->getIs_admin() == 1 && $is_runner) { if ($newStatus == 'Bidding' && in_array($workitem->getStatus(), $allowable)) { $workitem->setRunnerId($user->getId()); } } if ($newStatus == 'Done' && $workitem->getProjectId() == 0) { return false; } // Set all 0.00 fees as paid if ($newStatus == 'Done') { if (!$workitem->flagAll0FeesAsPaid()) { return false; } } $workitem->setStatus($newStatus); $projectId = $workitem->getProjectId(); $thisProject = new Project($projectId); $repoType = $thisProject->getRepo_type(); // Generate diff and send to pastebin if we're in REVIEW if ($newStatus == "Code Review") { //reset code_review flags $workitem->resetCRFlags(); if ($repoType == 'svn') { if (substr($workitem->getSandbox(), 0, 4) == "http") { // Sandbox URLs look like: // https://dev.worklist.net/~johncarlson21/worklist // 0 12 3 4 $sandbox_array = explode("/", $workitem->getSandbox()); $username = isset($sandbox_array[3]) ? $sandbox_array[3] : "~"; $username = substr($username, 1); // eliminate the tilde $sandbox = isset($sandbox_array[4]) ? $sandbox_array[4] : ""; try { $result = SandBoxUtil::pasteSandboxDiff($username, $workitem->getId(), $sandbox); $comment = "Code Review available here:\n{$result}"; $rt = $this->addComment($workitem->getId(), $user->getId(), $comment); } catch (Exception $ex) { error_log("Could not paste diff: \n{$ex}"); } } } elseif ($repoType == 'git') { $GitHubUser = new User($workitem->getMechanicId()); $pullResults = $GitHubUser->createPullRequest($workitem->getId(), $workitem->getSummary(), $thisProject); if (!$pullResults['error'] && !isset($pullResults['data']['errors'])) { $codeReviewURL = $pullResults['data']['html_url'] . '/files'; $comment = "Code Review available here:\n" . $codeReviewURL; } else { $comment = $pullResults['error'] ? "We had problems making your request to GitHub\n" : "The following error was returned when making your pull request:\n"; $comment .= isset($pullResults['data']['errors']) ? $pullResults['data']['errors'][0]['message'] : "Unknown error"; } $rt = $this->addComment($workitem->getId(), $user->getId(), $comment); } } if ($newStatus == 'QA Ready' && $repoType == 'git') { $runner = $workitem->getRunnerId(); $GitHubUser = new User($runner); $runnerEmail = $GitHubUser->getUsername(); $GitHubBidder = new User($workitem->getMechanicId()); $githubDetails = $GitHubBidder->getGitHubUserDetails($thisProject); $gitHubUsername = $githubDetails['data']['login']; $repoDetails = $thisProject->extractOwnerAndNameFromRepoURL(); $usersFork = 'https://github.com/' . $gitHubUsername . "/" . $repoDetails['name'] . ".git"; $data = array('branch_name' => $workitem->getId(), 'runner' => $GitHubUser->getNickname(), 'users_fork' => $usersFork, 'master_repo' => str_replace('https://', 'git://', $thisProject->getRepository())); $senderEmail = 'Worklist <*****@*****.**>'; Utils::sendTemplateEmail($runnerEmail, $emailTemplate, $data, $senderEmail); } else { if ($newStatus == 'QA Ready' && !($workitem->getIsRelRunner() || $user->getIs_admin() == 1)) { return true; } } if ($newStatus == 'In Progress') { $thisProject->setActive(1); $thisProject->save(); $options = array('type' => 'status-notify', 'workitem' => $workitem); $data = array('nick' => $user->getNickname(), 'status' => $newStatus); Notification::workitemNotifyHipchat($options, $data); } // notifications for subscribed users Notification::massStatusNotify($workitem); if ($newStatus == 'Bidding') { $options = array('type' => 'new_bidding', 'workitem' => $workitem); Notification::massStatusNotify($workitem); } if ($newStatus == 'Code Review') { $options = array('type' => 'new_review', 'workitem' => $workitem); Notification::massStatusNotify($workitem); } return true; }