Beispiel #1
0
 public function actionCopyGroup()
 {
     $id = (int) $_POST['id'];
     $group = VoterGroup::model()->findByPk($id);
     if (!$group) {
         $this->renderJson(array('success' => false, 'message' => 'Group with id "' . $id . '" was not found'));
         return;
     }
     $newGroup = $group->copy();
     if (!$newGroup) {
         $this->renderJson(array('success' => false, 'message' => 'Copying failed'));
         return;
     }
     $this->renderJson(array('success' => true, 'message' => 'Group copied successfully', 'data' => array('id' => $newGroup->id)));
 }
 public function checkAccess()
 {
     if (Yii::app()->user->checkAccess('superadmin')) {
         return true;
     }
     if (in_array($this->action->id, array('restDelete', 'restUpdate'))) {
         $id = (int) $_GET['id'];
         $member = $this->loadOneModel($id);
         if (!$member) {
             throw new CException('Member with id "' . $id . "' was not found");
         }
         $group = $member->voterGroup;
         if (!$group) {
             throw new CException('VoterGroup 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();
         $group = VoterGroup::model()->findByPk($data['voter_group_id']);
         if (!$group) {
             throw new CException('VoterGroup was not found');
         }
         $type = $group->type;
         if ($type == VoterGroup::TYPE_LOCAL) {
             $election = $group->election;
             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;
     }
 }
 public function testCopiedGlobalGroupManagement()
 {
     $this->openGlobalGroupsManagement();
     $this->assertCssCount('css=#groups-grid table.x-grid-item', 4);
     $rowSel = 'css=#groups-grid table.x-grid-item:nth-of-type(5) ';
     // copy from local
     $this->click('css=#groups-grid table.x-grid-item ' . 'td.x-grid-cell:nth-of-type(6) img:nth-of-type(3)');
     $this->waitForCssCount('css=#groups-grid table.x-grid-item', 5);
     $this->closeModal();
     $newGroupId = 6;
     $this->assertEquals($newGroupId, $this->getText($rowSel . 'td.x-grid-cell:nth-of-type(2)'));
     $this->assertElementContainsText($rowSel . 'td.x-grid-cell:nth-of-type(3)', $grName = 'Local group 1');
     $this->assertElementContainsText($rowSel . 'td.x-grid-cell:nth-of-type(4)', 'Global');
     $this->assertEmpty($this->getText($rowSel . 'td.x-grid-cell:nth-of-type(5)'));
     //Global group can't be copied again
     $this->assertElementHasClass($rowSel . 'td.x-grid-cell:nth-of-type(6) img:nth-of-type(3)', 'x-item-disabled');
     $this->assertInstanceOf('VoterGroup', $voterGroup = $vg = VoterGroup::model()->findByAttributes(array('name' => $grName, 'type' => VoterGroup::TYPE_GLOBAL, 'election_id' => null)));
     $this->assertEquals($newGroupId, $vg->id);
     // edit
     $this->click($rowSel . 'tr.x-grid-row td.x-grid-cell:nth-of-type(6) img:nth-of-type(2)');
     $this->type('css=#groups-grid .x-grid-row-editor input[type="text"]', $grName .= ' Edited');
     $this->waitForElementPresent($updateBtnSel = 'css=#groups-grid .x-grid-row-editor .x-grid-row-editor-buttons a.x-btn');
     $this->waitForElementHasNoClass($updateBtnSel, 'x-item-disabled');
     $this->click($updateBtnSel);
     $this->waitForNotVisible('css=#groups-grid .x-grid-row-editor');
     $this->waitForElementNotPresent($rowSel . '.x-grid-dirty-cell');
     $this->assertEquals($newGroupId, $this->getText($rowSel . 'tr.x-grid-row td.x-grid-cell:nth-of-type(2)'));
     $this->assertEquals($grName, $this->getText($rowSel . 'tr.x-grid-row td.x-grid-cell:nth-of-type(3)'));
     $this->assertEquals('Global', $this->getText($rowSel . 'tr.x-grid-row td.x-grid-cell:nth-of-type(4)'));
     $voterGroup->refresh();
     $this->assertEquals($grName, $voterGroup->name);
     $this->assertEquals(VoterGroup::TYPE_GLOBAL, $voterGroup->type);
     $this->assertNull($voterGroup->election_id);
     //open members list
     $this->assertCount(2, $voterGroup->getRelated('voterGroupMembers', true));
     $this->click($rowSel . 'tr.x-grid-row td.x-grid-cell:nth-of-type(6) img:nth-of-type(1)');
     $this->waitForElementPresent($tabHeaderSel = 'css=#members-tabs .x-tab-bar a.x-tab');
     $this->assertElementContainsText($tabHeaderSel, $grName);
     $this->sleep(1500);
     $this->assertCssCount('css=#members-tabs div[id|="groupmembersgrid"] table.x-grid-item', 2);
     $this->assertElementContainsText('css=#members-tabs div[id|="groupmembersgrid"]', 'Vasiliy');
     $this->assertElementContainsText('css=#members-tabs div[id|="groupmembersgrid"]', 'Another');
     // remove users
     $this->click('css=#members-tabs div[id|="groupmembersgrid"] .x-grid-header-ct .x-column-header-checkbox span');
     $this->assertCssCount('css=#members-tabs div[id|="groupmembersgrid"] table.x-grid-item-selected', 2);
     $this->click('css=#members-tabs div[id|="groupmembersgrid"] a.x-btn:nth-of-type(2)');
     $this->confirm();
     $this->waitForCssCount('css=#members-tabs div[id|="groupmembersgrid"] table.x-grid-item', 0);
     $this->assertCount(0, $voterGroup->getRelated('voterGroupMembers', true));
     // add users
     $this->click('css=#members-tabs div[id|="groupmembersgrid"] a.x-btn');
     $this->waitForPresent('css=#add-electors-window div[id|="aes-operableusersgrid"]', 20000);
     $this->waitForCssCount('css=#add-electors-window div[id|="aes-operableusersgrid"] table.x-grid-item', 6, 20000);
     $this->click('css=#add-electors-window div[id|="aes-operableusersgrid"] .x-grid-header-ct .x-column-header-checkbox span');
     $this->assertCssCount('css=#add-electors-window div[id|="aes-operableusersgrid"] table.x-grid-item-selected', 6);
     $this->click('css=#add-electors-window-body #add-users-btn');
     $this->waitForCssCount('css=#add-electors-window div[id|="aes-operableusersgrid"] table.x-grid-item', 0, 10000);
     $this->click('css=#add-electors-window img.x-tool-close');
     $this->waitForCssCount('css=#members-tabs div[id|="groupmembersgrid"] table.x-grid-item', 6);
     $this->sleep(1000);
     $this->assertCount(6, $voterGroup->getRelated('voterGroupMembers', true));
 }