Exemplo n.º 1
0
 public function checkAccess()
 {
     if (Yii::app()->user->checkAccess('superadmin')) {
         return true;
     }
     if (in_array($this->action->id, array('restDelete', 'restUpdate'))) {
         $id = (int) $_GET['id'];
         $group = $this->loadOneModel($id);
         if (!$group) {
             throw new CException('VoterGroup with id "' . $id . '" was not found');
         }
         if ($group->type == VoterGroup::TYPE_LOCAL) {
             $params = array('election' => $group->election);
             return Yii::app()->user->checkAccess('election_administration', $params);
         }
         return false;
     }
     if ($this->action->id == 'restCreate') {
         $data = $this->data();
         $type = $data['type'];
         if ($type == VoterGroup::TYPE_LOCAL) {
             $election = Election::model()->findByPk((int) $data['election_id']);
             if (!$election) {
                 throw new CException('Election with id "' . $data['election_id'] . '" was not found');
             }
             $params = array('election' => $election);
             return Yii::app()->user->checkAccess('election_administration', $params);
         }
         return false;
     }
 }
Exemplo n.º 2
0
 public function checkAccess()
 {
     if (!empty($_GET['id'])) {
         $id = $_GET['id'];
         $model = $this->loadOneModel((int) $id);
         if (!$model) {
             throw new Exception('ElectionAuthAssignment with id = ' . $id . ' was not found');
         }
         $election = $model->object;
     } else {
         $data = $this->data();
         $election = Election::model()->findByPk((int) $data['object_id']);
     }
     if (!$election) {
         throw new Exception('Related Election can\'t be fetched');
     }
     $params['election'] = $election;
     if ($this->action->id == 'restCreate' && Yii::app()->user->checkAccess('election_manageAdmins', $params)) {
         return true;
     }
     if ($this->action->id == 'restDelete' && Yii::app()->user->checkAccess('election_manageAdmins', $params)) {
         if ($model->right == 'election_creator') {
             throw new Exception('Election creator can\'t be deprived of power.');
         }
         return true;
     }
     return false;
 }
 public function checkAccess()
 {
     if (!empty($_GET['id'])) {
         $id = $_GET['id'];
         $model = $this->loadOneModel((int) $id);
         if (!$model) {
             throw new Exception('ElectorRegistrationRequest with id = ' . $id . ' was not found');
         }
         $election = $model->election;
     } else {
         $data = $this->data();
         $election = Election::model()->findByPk((int) $data['election_id']);
     }
     if (!$election) {
         throw new Exception('Related Election can\'t be fetched');
     }
     $params['election'] = $election;
     if ($this->action->id == 'restCreate' && Yii::app()->user->checkAccess('election_askToBecameElector', $params)) {
         return true;
     }
     if ($this->action->id == 'restUpdate' && Yii::app()->user->checkAccess('election_manage', $params)) {
         return true;
     }
     return false;
 }
 public function testRegisterButtonNotShowsWhenCandidateCanBeRegisteredOnlyByAdmin()
 {
     $this->login('*****@*****.**', 'qwerty');
     $election = Election::model()->findByPk(4);
     $election->cand_reg_type = Election::CAND_REG_TYPE_ADMIN;
     $election->save(false);
     $this->assertRegisterBtn($present = false, 4);
 }
 public function setElection($election)
 {
     if (is_numeric($election)) {
         $election = Election::model()->findByPk($election);
     }
     if (!$election) {
         throw new CException('Election was not found');
     }
     $this->election = $election;
 }
Exemplo n.º 6
0
 public function doRestList()
 {
     if (empty($this->plainFilter['election_id'])) {
         throw new Exception('Election id filter property missed');
     }
     $election = Election::model()->findByPk($this->plainFilter['election_id']);
     if (!$election) {
         throw new Exception('Election was not found');
     }
     $criteria = new CDbCriteria(array('condition' => 't.election_id = ' . $election->id));
     if (isset($this->plainFilter['user_id'])) {
         $criteria->mergeWith(array('condition' => 't.user_id = ' . (int) $this->plainFilter['user_id']));
     }
     if (isset($this->plainFilter['candidate_id'])) {
         $criteria->mergeWith(array('condition' => 't.candidate_id = ' . (int) $this->plainFilter['candidate_id']));
     }
     if (isset($this->plainFilter['accepted_only']) && $this->plainFilter['accepted_only']) {
         $criteria->addCondition('t.status = ' . Vote::STATUS_PASSED);
     }
     $peopleSearch = new PeopleSearch();
     if ($name = $this->plainFilter['name']) {
         $peopleSearch->name = $name;
     }
     if ($ageFrom = $this->plainFilter['ageFrom']) {
         $peopleSearch->ageFrom = $ageFrom;
     }
     if ($ageTo = $this->plainFilter['ageTo']) {
         $peopleSearch->ageTo = $ageTo;
     }
     if ($birth_place = $this->plainFilter['birth_place']) {
         $peopleSearch->birth_place = $birth_place;
     }
     if ($gender = $this->plainFilter['gender']) {
         $peopleSearch->gender = $gender;
     }
     $arProvCriteria = $peopleSearch->search('profile')->criteria;
     if ($arProvCriteria) {
         $originalCriteria = clone $criteria;
         $criteria->mergeWith($arProvCriteria);
     }
     $results = $this->getModel()->with($this->nestedRelations)->limit($this->restLimit)->offset($this->restOffset)->findAll($criteria);
     $totalCount = $this->getModel()->with($this->nestedRelations)->count($criteria);
     $extraData = $totalCount;
     if (isset($this->plainFilter['candidate_id'])) {
         if (isset($originalCriteria)) {
             $criteria = $originalCriteria;
         }
         $acceptedCountCritetia = clone $criteria;
         $acceptedCount = $this->getModel()->with($this->nestedRelations)->count($acceptedCountCritetia->addCondition('t.status = ' . Vote::STATUS_PASSED));
         $extraData = array('totalCount' => $totalCount, 'acceptedCount' => $acceptedCount);
     }
     $this->outputHelper('Records Retrieved Successfully', $results, $extraData);
 }
 public function checkAccess()
 {
     if (isset($_GET['id'])) {
         $model = $this->loadOneModel($id = (int) $_GET['id']);
         $election = $model->election;
     } else {
         $data = $this->data();
         $election = Election::model()->findByPk((int) $data['election_id']);
     }
     if (!$election) {
         throw new CException('Related election was not found');
     }
     $params = array('election' => $election);
     return Yii::app()->user->checkAccess('election_administration', $params);
 }
 public function testRegistration()
 {
     $election = Election::model()->findByPk(1);
     $el2 = Election::model()->findByPk(2);
     $el2StartElectors = array(2, 3, 4);
     $this->checkUsersAreElectors(array('1', '2'), $election->id);
     $this->checkUsersAreElectors($el2StartElectors, $el2->id);
     $reg = new VoterGroupMembersRegistration($election);
     $reg->run();
     $this->checkUsersAreElectors(array('1', '2', '3', '4', '5'), $election->id);
     $this->checkUsersAreElectors($el2StartElectors, $el2->id);
     $reg = new VoterGroupMembersRegistration($el2);
     $reg->run();
     $this->checkUsersAreElectors(array('1', '2', '3', '4', '5'), $election->id);
     $this->checkUsersAreElectors(array(2, 3, 4, 5, 6), $el2->id);
 }
Exemplo n.º 9
0
 public function testRestrictCreatePostForNotParticipants()
 {
     $auth = Yii::app()->authManager;
     $user = Yii::app()->user;
     $election1 = Election::model()->findByPk(1);
     //user 5 is not a participant
     $user->id = 5;
     $this->assertFalse($auth->checkAccess('createPost', 5, array('disabledRoles' => array('poster'), 'election' => $election1)));
     // user 6 is participant
     $user->id = 6;
     $election1->assignRoleToUser($user->id, 'election_participant');
     $this->assertTrue($auth->checkAccess('createPost', 6, array('disabledRoles' => array('poster'), 'election' => $election1)));
     // user 4 is moderator
     $user->id = 4;
     $this->assertTrue($auth->checkAccess('createPost', 4, array('disabledRoles' => array('poster'), 'election' => $election1)));
     // user ??? is creator ?
 }
Exemplo n.º 10
0
 public function testGroupsManagementMenuItemNotShowsForNotAdmins()
 {
     $election = Election::model()->findByPk(1);
     $election->status = Election::STATUS_REGISTRATION;
     $election->save();
     $this->open('election/view/1');
     $this->waitForPageToLoad();
     $anchorSel = 'link=Voters and Groups Management';
     $this->assertElementNotPresent($anchorSel);
     $this->login('*****@*****.**', 'qwerty');
     $this->open('election/view/1');
     $this->waitForPageToLoad();
     $this->assertElementNotPresent($anchorSel);
     $this->logout();
     $this->login('*****@*****.**', 'qwerty');
     $this->open('election/view/1');
     $this->waitForPageToLoad();
     $this->assertElementPresent($anchorSel);
 }
Exemplo n.º 11
0
 public function testCreateMandateMethod()
 {
     $candidate = $this->getFixtureManager()->getRecord('candidate', 3);
     $electedCandidateId = $candidate->id;
     $election = Election::model()->findByPk($candidate->election_id);
     $election->quote = 1;
     $election->status = Election::STATUS_REGISTRATION;
     $this->assertTrue($election->save());
     $election->status = Election::STATUS_ELECTION;
     $this->assertTrue($election->save());
     $vote = new Vote();
     $vote->candidate_id = $electedCandidateId;
     $vote->election_id = $candidate->election_id;
     $vote->user_id = $election->electors[0]->user_id;
     $this->assertTrue($vote->save(), print_r($vote->getErrors(), true));
     $election->status = Election::STATUS_FINISHED;
     $election->save();
     $mandate = Mandate::model()->findByAttributes(array('election_id' => $candidate->election_id, 'candidate_id' => $candidate->id));
     $this->assertEquals($election->mandate, $mandate->name);
     $this->assertEquals($election->validity, $mandate->validity);
 }
 /**
  * @dataProvider electionsWithoutVoterGroupsRestrictions
  */
 public function testAutomaticRegistration($electionId)
 {
     $this->login('*****@*****.**', 'qwerty');
     $this->open('election/view/' . $electionId);
     $this->waitForPageToLoad();
     $this->waitForPresent($regBtnSel = 'css=button#register-candidate');
     $this->assertVisible($regBtnSel);
     $election = Election::model()->findByPk($electionId);
     if ($election->voter_reg_type == Election::VOTER_REG_TYPE_SELF) {
         $this->waitForPresent($regElectorBtnSel = 'css=button#register-elector');
         $this->assertVisible($regElectorBtnSel);
     }
     $this->click($regBtnSel);
     $this->waitForTextPresent('You have been registered as candidate and elector');
     $this->waitForElementNotPresent($regElectorBtnSel);
     $this->open('election/electorate/' . $electionId);
     $this->waitForPageToLoad();
     $this->waitForElementPresent($electorsContSel = 'css=#dest-tab.active div.items');
     $this->waitForCssCount($electorsContSel .= ' > div.user-info', 1);
     $this->assertElementContainsText($electorsContSel, 'Another User');
 }
Exemplo n.º 13
0
 public function checkAccess()
 {
     Yii::app()->authManager->defaultRoles = array_merge(Yii::app()->authManager->defaultRoles, array('election_updateCandidateOwnStatus'));
     $data = $this->data();
     if (!empty($_GET['id'])) {
         $id = $_GET['id'];
         $model = $this->loadOneModel((int) $id);
         if (!$model) {
             throw new Exception('Candidate with id = ' . $id . ' was not found');
         }
         $election = $model->election;
     } else {
         $election = Election::model()->findByPk((int) $data['election_id']);
         $params['candidate_user_id'] = $data['user_id'];
     }
     if (!$election) {
         throw new Exception('Related Election can\'t be fetched');
     }
     $params['election'] = $election;
     if ($model) {
         $params['candidate'] = $model;
         if (isset($data['status'])) {
             $params['status'] = $data['status'];
         }
     }
     if ($this->action->id == 'restCreate' && Yii::app()->user->checkAccess('election_createCandidate', $params)) {
         return true;
     }
     if ($this->action->id == 'restDelete' && Yii::app()->user->checkAccess('election_deleteCandidate', $params)) {
         return true;
     }
     if ($this->action->id == 'restUpdate' && Yii::app()->user->checkAccess('election_updateCandidateStatus', $params)) {
         return true;
     }
     return false;
 }
Exemplo n.º 14
0
 public function testRevokeVoteFailsWithMessageBecauseOfTimeout()
 {
     $this->login("*****@*****.**", "qwerty");
     $this->open('election/candidates/1');
     $this->waitForPageToLoad("30000");
     $voteBox = "css=div.checkbox.vote";
     $this->waitForElementPresent($voteBox);
     //first vote
     $this->click($voteBox);
     $this->waitForElementContainsText($voteBox . ' span.value', '✓');
     //Simulating that timer is expired
     $candidate = Candidate::model()->findByAttributes(array('electoral_list_pos' => 1, 'election_id' => 1));
     $vote = Vote::model()->findByAttributes(array('candidate_id' => $candidate->id, 'user_id' => 1));
     $voted = new DateTime($vote->date);
     $voted->sub(new DateInterval('PT' . (Election::model()->findByPk(1)->remove_vote_time - 1) . 'M' . '54S'));
     $voted = $voted->format('Y-m-d H:i:s');
     Yii::app()->db->createCommand()->update('vote', array('date' => $voted), 'id = ' . $vote->id);
     $this->open('election/candidates/1');
     $this->sleep(7000);
     $this->click($voteBox);
     $this->assertElementPresent($errorBox = 'css=div.flash-messages div.alert-error');
     $this->assertElementContainsText($errorBox, 'Action is unavailable because of timeout');
     //check all candidates are inactive for voting
     $this->waitForCssCount($voteBox . '.inactive', 3);
 }
Exemplo n.º 15
0
 /**
  * Return TRUE if registration request is available to user
  * for specified election
  * 
  * @param Election|int $election
  * @param int $user userId
  * @return boolean
  */
 public static function isAvailable($election, $user)
 {
     $userId = $user;
     if (is_numeric($election)) {
         $electionId = $election;
         $election = Election::model()->findByPk($electionId);
     } else {
         $electionId = $election->id;
     }
     if (!$election->isElectorsRegistrationOpen()) {
         return false;
     }
     $elector = Elector::model()->findByAttributes(array('user_id' => $userId, 'election_id' => $electionId));
     if ($elector) {
         return false;
     }
     $registration = self::model()->findByAttributes(array('user_id' => $userId, 'election_id' => $electionId));
     if ($registration) {
         return false;
     }
     return true;
 }
Exemplo n.º 16
0
 protected function getModel($id)
 {
     $model = Election::model()->findByPk($id);
     if (!$model) {
         throw new CHttpException('404', 'Page not found');
     }
     return $model;
 }
Exemplo n.º 17
0
<?php

$this->layout = '//layouts/main';
$election = Election::model()->findByPk(1);
?>

<h1>RatesWidget sandbox</h1>

<hr>

<i>With fetching set of models</i>

<div id="something-1">
<p>Lorem ipsum dolor. And comments to it below.</p>

<?php 
$this->widget('RatesMarionetteWidget', array('jsConstructorOptions' => array('targetId' => $election->id, 'targetType' => 'Election', 'targetEl' => '#something-1'), 'show' => array('div')));
?>
</div>
Exemplo n.º 18
0
 public function testAdminCanBlockCandidate()
 {
     $elecion = Election::model()->findByPk(5);
     $elecion->status = Election::STATUS_ELECTION;
     $elecion->save(false);
     $this->login('*****@*****.**', 'qwerty');
     $this->open('/index-test.php/election/candidates/5/details/8');
     $this->waitForPageToLoad();
     $this->waitForVisible('css=#candidate-details #controls');
     $this->waitForCssCount('css=#controls button', 1);
     $this->click('css=#controls button.block');
     $this->waitForElementContainsText('css=#candidate-info .body > div:nth-of-type(3)', 'Refused');
     $this->sleep(250);
     $this->assertElementNotPresent('css=#controls button');
     //check nominations
     $this->logout();
     $this->login('*****@*****.**', 'qwerty');
     $this->click("link=My nominations");
     $this->waitForPageToLoad();
     $this->waitForCssCount('css=#nominations-feed-container .items > div', 2);
     $this->assertElementContainsText('css=#nominations-feed-container .items > div:nth-of-type(2) h4', 'Election 5');
     $this->assertElementContainsText('css=#nominations-feed-container .items > div:nth-of-type(2) .status', 'Blocked');
 }
Exemplo n.º 19
0
 public function testAdminCanCreateWithUnassignedLevelNone()
 {
     $election1 = Election::model()->findByPk(1);
     $election1->unassigned_access_level = Election::UNASSIGNED_CAN_NONE;
     $election1->save();
     $this->authenticate('*****@*****.**', 'qwerty');
     $result = $this->xhr('api/Election_comment', '{"target_id":"1","user_id":null,"user":{"user_id":null,"photo":"","displayName":""},"content":"Comment n+4","likes":null,"dislikes":null,"comments":[]}', 'POST', true);
     //assert created
     $this->assertTrue((bool) preg_match('~HTTP/1\\.1 2\\d\\d~m', $result));
     $this->assertTrue((bool) preg_match('~"success":\\s?"?true"?~m', $result));
 }
Exemplo n.º 20
0
 public function testRegisterInElectionWithAddingToGroupWithoutConfirmation()
 {
     $electionId = 11;
     $this->login('*****@*****.**', 'qwerty');
     $this->open('election/electorate/' . $electionId);
     $this->waitForPageToLoad();
     $this->waitForCssCount('css=#electoral-list-tab .items div.user-info', 0);
     $this->click('css=#register-elector');
     $this->sleep(500);
     $this->assertCssCount('css=div.flash-messages div.alert', 0);
     // Wait for visible modal
     $this->waitForPresent($modalSel = 'css=.modal');
     $this->waitForVisible($modalSel);
     // With visible local groups to select
     $election = Election::model()->findByPk($electionId);
     $availGroups = $election->localVoterGroups;
     $this->assertGreaterThan(0, $count = count($availGroups));
     $this->assertEquals(3, $count);
     $checkboxSel = 'css=div.modal-body > label.checkbox:nth-of-type({%index%}) > input';
     foreach ($availGroups as $index => $group) {
         $this->assertElementContainsText('css=.modal-body', $group->name);
         $this->assertEquals($group->id, $this->getAttribute($this->parseSel($checkboxSel, array('index' => $index + 1)), 'value'));
     }
     //Check that register button is inactive
     $this->assertElementAttributeEquals($regBtn = 'css=.modal-footer > button', 'disabled', 'disabled');
     // Select several
     $this->click($this->parseSel($checkboxSel, array('index' => 1)));
     $this->click($this->parseSel($checkboxSel, array('index' => 2)));
     //Check that register button was activated
     $this->assertElementAttributeEquals($regBtn, 'disabled', false);
     // Press submit button
     $this->click($regBtn);
     // Wait for modal hide
     $this->waitForNotPresent($modalSel);
     // Wait for #register-elector hide
     $this->waitForNotPresent('css=#register-elector');
     // Wait for notification present
     $this->assertCssCount('css=div.flash-messages div.alert', 1);
     $this->assertElementContainsText('css=div.flash-messages div.alert', 'You have been registered as elector.');
     $this->click('css=div.flash-messages div.alert a.close');
     $this->waitForNotPresent('css=div.flash-messages div.alert');
     $this->waitForCssCount('css=#dest-tab .items div.user-info', 1);
     $this->assertElementContainsText('css=#dest-tab .items div.user-info:nth-of-type(1) a', 'Another User');
     // Look into DB and check that Elector really was added to selected groups
     $this->assertInstanceOf(VoterGroupMember, VoterGroupMember::model()->findByAttributes(array('user_id' => 2, 'voter_group_id' => $availGroups[0]->id)));
     $this->assertInstanceOf(VoterGroupMember, VoterGroupMember::model()->findByAttributes(array('user_id' => 2, 'voter_group_id' => $availGroups[1]->id)));
 }
Exemplo n.º 21
0
 public function testNotRevokesWithRevoteLimitEqualsToZero()
 {
     $election = Election::model()->findByPk(1);
     $election->revotes_count = 0;
     $this->assertTrue($election->save());
     $vote = new Vote();
     $vote->election_id = 1;
     $vote->candidate_id = 3;
     $vote->user_id = 1;
     $this->assertTrue($vote->save());
     $this->setExpectedException('Exception', 'Revote limit has been reached');
     $vote->status = Vote::STATUS_REVOKED;
     $this->assertFalse($vote->save());
     $this->setExpectedException('Exception', 'Revote limit has been reached');
     $vote = new Vote();
     $vote->candidate_id = 5;
     $vote->user_id = 1;
     $vote->election_id = 1;
     $this->assertFalse($vote->save());
 }