コード例 #1
0
 public function testSendAddedToProject_PropertiesFromToBodyOk()
 {
     $e = new MongoTestEnvironment();
     $e->clean();
     $inviterUserId = $e->createUser('inviterUser', 'Inviter User', '*****@*****.**');
     $inviterUser = new UserModel($inviterUserId);
     $toUserId = $e->createUser('touser', 'To Name', '*****@*****.**');
     $toUser = new UserModel($toUserId);
     $project = $e->createProjectSettings(SF_TESTPROJECTCODE);
     $delivery = new MockCommunicateDelivery();
     $project->addUser($inviterUserId, $e->website->userDefaultSiteRole);
     $project->write();
     $inviterUser->addProject($project->id->asString());
     $inviterUser->write();
     Communicate::sendAddedToProject($inviterUser, $toUser, $project, $e->website, $delivery);
     // What's in the delivery?
     $senderEmail = 'no-reply@' . $e->website->domain;
     $expectedFrom = array($senderEmail => $e->website->name);
     $expectedTo = array($toUser->email => $toUser->name);
     $this->assertEqual($expectedFrom, $delivery->from);
     $this->assertEqual($expectedTo, $delivery->to);
     $this->assertPattern('/To Name.*\\n*Inviter User/', $delivery->content);
 }
コード例 #2
0
 /**
  * Sends an email to invite emailee to join the project
  * @param string $projectId
  * @param string $inviterUserId
  * @param Website $website
  * @param string $toEmail
  * @param DeliveryInterface $delivery
  * @throws \Exception
  * @return string $userId
  */
 public static function sendInvite($projectId, $inviterUserId, $website, $toEmail, DeliveryInterface $delivery = null)
 {
     $newUser = new UserModel();
     $inviterUser = new UserModel($inviterUserId);
     $project = new ProjectModel($projectId);
     $newUser->emailPending = $toEmail;
     // Check if email already exists in an account
     $identityCheck = UserCommands::checkIdentity('', $toEmail, $website);
     if ($identityCheck->emailExists) {
         $newUser->readByProperty('email', $toEmail);
     }
     // Make sure the user exists on the site
     if (!$newUser->hasRoleOnSite($website)) {
         $newUser->siteRole[$website->domain] = $website->userDefaultSiteRole;
     }
     // Determine if user is already a member of the project
     if ($project->userIsMember($newUser->id->asString())) {
         return $newUser->id;
     }
     // Add the user to the project
     $newUser->addProject($project->id->asString());
     $userId = $newUser->write();
     $project->addUser($userId, ProjectRoles::CONTRIBUTOR);
     $project->write();
     if (!$identityCheck->emailExists) {
         // Email communication with new user
         Communicate::sendInvite($inviterUser, $newUser, $project, $website, $delivery);
     } else {
         // Tell existing user they're now part of the project
         Communicate::sendAddedToProject($inviterUser, $newUser, $project, $website, $delivery);
     }
     return $userId;
 }