public static function setUpBeforeClass()
 {
     self::$org = new Organization();
     self::$org->grantAllPermissions();
     self::$org->create(['name' => 'Test Org', 'email' => '*****@*****.**', 'username' => 'test' . time()]);
     $uid = TestBootstrap::app('user')->id();
     TestBootstrap::app('user')->enableSU();
     $volunteer = new Volunteer();
     $volunteer->create(['organization' => self::$org->id(), 'uid' => $uid, 'role' => Volunteer::ROLE_ADMIN]);
     TestBootstrap::app('user')->disableSU();
     self::$ogUserId = $uid;
 }
 public static function setUpBeforeClass()
 {
     // reset counts
     $user = TestBootstrap::app('user');
     $user->set(['volunteer_hours' => 0, 'twitter_id' => 100]);
     $uid = TestBootstrap::app('user')->id();
     self::$org = new Organization();
     self::$org->grantAllPermissions();
     self::$org->create(['name' => 'Test', 'email' => '*****@*****.**', 'username' => 'test' . time()]);
     self::$org2 = new Organization();
     self::$org2->grantAllPermissions();
     self::$org2->create(['name' => 'Test 2', 'email' => '*****@*****.**', 'username' => 'test2' . time()]);
     TestBootstrap::app('user')->enableSU();
     $volunteer = new Volunteer();
     $volunteer->create(['organization' => self::$org->id(), 'uid' => $uid, 'role' => Volunteer::ROLE_ADMIN]);
     $volunteer = new Volunteer();
     $volunteer->create(['organization' => self::$org2->id(), 'uid' => $uid, 'role' => Volunteer::ROLE_VOLUNTEER]);
     TestBootstrap::app('user')->disableSU();
     self::$place = new VolunteerPlace();
     self::$place->create(['name' => 'Test', 'organization' => self::$org->id(), 'place_type' => VolunteerPlace::EXTERNAL, 'verify_approved' => true, 'verify_name' => 'Jared', 'verify_email' => '*****@*****.**']);
     self::$ogUserId = $uid;
 }
示例#3
0
 /**
  * Adds a volunteer to the organization. If the volunteer is not a
  * member yet, then a temporary account will be created. This
  * will send an e-mail to the user.
  *
  * @param string $emailOrUsername
  *
  * @return Volunteer|false invited volunteer
  */
 public function inviteVolunteer($emailOrUsername)
 {
     $user = false;
     $isEmail = true;
     if (Validate::is($emailOrUsername, 'email')) {
         $user = User::findOne(['where' => ['user_email' => $emailOrUsername]]);
         $isEmail = true;
     } else {
         $user = User::findOne(['where' => ['username' => $emailOrUsername]]);
     }
     // create temporary user
     if (!$user && $isEmail) {
         $user = User::createTemporary(['user_email' => $emailOrUsername, 'invited_by' => $this->id()]);
     }
     if (!$user) {
         return false;
     }
     $isTemporary = $user->isTemporary();
     $volunteer = new Volunteer([$user->id(), $this->id()]);
     if ($volunteer->exists()) {
         return $volunteer;
     }
     $volunteer = new Volunteer();
     $volunteer->grantAllPermissions();
     $volunteer->create(['uid' => $user->id(), 'organization' => $this->id(), 'application_shared' => true, 'active' => true, 'role' => Volunteer::ROLE_VOLUNTEER]);
     $base = $this->app['base_url'];
     $orgName = $this->name;
     $ctaUrl = $isTemporary ? $base . 'signup?user_email=' . $user->user_email : $base . 'profile';
     $user->sendEmail('volunteer-invite', ['subject' => "{$orgName} has invited you as a volunteer", 'orgname' => $orgName, 'cta_url' => $ctaUrl]);
     return $volunteer;
 }
示例#4
0
 public function testCannotCreateBeyondCurrentRole()
 {
     $volunteer = new Volunteer();
     $this->assertFalse($volunteer->create(['uid' => TestBootstrap::app('user')->id(), 'organization' => self::$org->id(), 'role' => Volunteer::ROLE_ADMIN]));
 }
示例#5
0
 public function joinOrganization($req, $res)
 {
     $org = $this->getOrg($req, $res);
     if (!is_object($org)) {
         return $org;
     }
     $currentUser = $this->app['user'];
     // make sure the user is logged in
     if (!$currentUser->isLoggedIn()) {
         setcookie('redirect', $org->url(), time() + 3600, '/');
         return $res->redirect('/signup');
     }
     // application shared by default unless explicitly specified
     $applicationShared = $req->request('application_shared') === null || $req->request('application_shared');
     $volunteer = new Volunteer([$currentUser->id(), $org->id()]);
     $uid = $currentUser->id();
     // make sure the application has been shared with the org
     if ($volunteer->exists()) {
         $role = max($volunteer->role, Volunteer::ROLE_VOLUNTEER);
         $volunteer->grantAllPermissions();
         $volunteer->set(['application_shared' => $applicationShared, 'role' => $role]);
     } else {
         $volunteer = new Volunteer();
         $volunteer->create(['uid' => $uid, 'organization' => $org->id(), 'application_shared' => $applicationShared, 'active' => true, 'role' => Volunteer::ROLE_AWAITING_APPROVAL]);
     }
     if ($req->query('redir') == 'profile') {
         return $res->redirect('/profile');
     }
     return new View('joinOrganization', ['title' => 'Joined ' . $org->name, 'org' => $org->toArray(), 'orgObj' => $org]);
 }
 public function testCreate()
 {
     self::$org = new Organization();
     self::$org->grantAllPermissions();
     $this->assertTrue(self::$org->create(['name' => 'Test Organization', 'email' => '*****@*****.**', 'username' => 'test' . time()]));
     self::$org2 = new Organization();
     self::$org2->grantAllPermissions();
     $this->assertTrue(self::$org2->create(['name' => 'Test Org', 'email' => '*****@*****.**', 'username' => 'test2' . time()]));
     /* Create some volunteers */
     $user = TestBootstrap::app('user');
     $uid = $user->id();
     $user->enableSU();
     $volunteer = new Volunteer();
     $this->assertTrue($volunteer->create(['uid' => $uid, 'organization' => self::$org->id(), 'role' => Volunteer::ROLE_ADMIN]));
     $user->disableSU();
     $volunteer = new Volunteer();
     $this->assertTrue($volunteer->create(['uid' => -2, 'organization' => self::$org->id(), 'role' => Volunteer::ROLE_AWAITING_APPROVAL]));
     $volunteer = new Volunteer();
     $this->assertTrue($volunteer->create(['uid' => -3, 'organization' => self::$org->id(), 'role' => Volunteer::ROLE_VOLUNTEER]));
     $volunteer = new Volunteer();
     $this->assertTrue($volunteer->create(['organization' => self::$org->id(), 'uid' => -4, 'timestamp' => time(), 'approved' => true]));
     /* Create some hours */
     for ($i = 0; $i < 5; ++$i) {
         $hour = new VolunteerHour();
         $this->assertTrue($hour->create(['organization' => self::$org->id(), 'uid' => -3, 'hours' => 1, 'timestamp' => mktime(0, 0, 0, 5, 11, 2013), 'approved' => true]));
     }
     $hour = new VolunteerHour();
     $this->assertTrue($hour->create(['organization' => self::$org->id(), 'uid' => -4, 'hours' => 10, 'timestamp' => mktime(0, 0, 0, 5, 12, 2013), 'approved' => true]));
     $hour = new VolunteerHour();
     $this->assertTrue($hour->create(['organization' => self::$org->id(), 'uid' => $uid, 'timestamp' => mktime(10, 10, 10, 5, 10, 2013), 'hours' => 11, 'approved' => true]));
     // unapproved hours
     $hour = new VolunteerHour();
     $this->assertTrue($hour->create(['organization' => self::$org->id(), 'uid' => $uid, 'timestamp' => mktime(0, 0, 0, 5, 11, 2013), 'hours' => 10, 'tags' => ['yo', 'hello', 'test'], 'approved' => false]));
     // approved hours
     $hour = new VolunteerHour();
     $this->assertTrue($hour->create(['organization' => self::$org->id(), 'uid' => $uid, 'timestamp' => mktime(0, 0, 0, 5, 11, 2013), 'hours' => 5, 'approved' => true, 'tags' => ['test']]));
     $hour = new VolunteerHour();
     $this->assertTrue($hour->create(['organization' => self::$org->id(), 'uid' => $uid, 'timestamp' => mktime(0, 0, 0, 5, 11, 2013), 'hours' => 10, 'approved' => true, 'tags' => ['test', 'test2']]));
     // official, outside hours
     $user->enableSU();
     $hour = new VolunteerHour();
     $this->assertTrue($hour->create(['organization' => self::$org2->id(), 'uid' => $uid, 'timestamp' => mktime(0, 0, 0, 5, 15, 2013), 'hours' => 12, 'approved' => true]));
     $user->disableSU();
     self::$ogUserId = $uid;
 }