Skip to content

Commit

Permalink
Fixed issue #15813: Group name not accessible anymore via RemoteControl
Browse files Browse the repository at this point in the history
  • Loading branch information
olleharstedt committed Feb 4, 2020
1 parent cffda86 commit 5a39b15
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 7 deletions.
31 changes: 24 additions & 7 deletions application/helpers/remotecontrol/remotecontrol_handle.php
Expand Up @@ -1191,38 +1191,55 @@ public function get_response_ids($sSessionKey, $iSurveyID, $sToken)
* @param string $sSessionKey Auth credentials
* @param int $iGroupID Id of the group to get properties of
* @param array $aGroupSettings The properties to get
* @param string $sLanguage Optional parameter language for multilingual groups
* @return array in case of success the requested values in array
*/
public function get_group_properties($sSessionKey, $iGroupID, $aGroupSettings = null)
public function get_group_properties($sSessionKey, $iGroupID, $aGroupSettings = null, $sLanguage = null)
{
if ($this->_checkSessionKey($sSessionKey)) {
$iGroupID = (int) $iGroupID;
$oGroup = QuestionGroup::model()->findByAttributes(array('gid' => $iGroupID));
$oGroup = QuestionGroup::model()->with('questionGroupL10ns')->findByAttributes(array('gid' => $iGroupID));
if (!isset($oGroup)) {
return array('status' => 'Error: Invalid group ID');
return array('status' => 'Error: Invalid group ID');
}

if (Permission::model()->hasSurveyPermission($oGroup->sid, 'survey', 'read')) {
$iSurveyID = $oGroup->sid;
if (is_null($sLanguage)) {
$sLanguage = Survey::model()->findByPk($iSurveyID)->language;
}

if (!array_key_exists($sLanguage, getLanguageDataRestricted())) {
return array('status' => 'Error: Invalid language');
}

$aBasicDestinationFields = QuestionGroup::model()->tableSchema->columnNames;
array_push($aBasicDestinationFields, 'group_name');
array_push($aBasicDestinationFields, 'description');
if (!empty($aGroupSettings)) {
$aGroupSettings = array_intersect($aGroupSettings, $aBasicDestinationFields);
} else {
$aGroupSettings = $aBasicDestinationFields;
}

if (empty($aGroupSettings)) {
return array('status' => 'No valid Data');
return array('status' => 'No valid Data');
}

foreach ($aGroupSettings as $sGroupSetting) {
$aResult[$sGroupSetting] = $oGroup->$sGroupSetting;
if (isset($oGroup->$sGroupSetting)) {
$aResult[$sGroupSetting] = $oGroup->$sGroupSetting;
} elseif (isset($oGroup->questionGroupL10ns[$sLanguage])
&& isset($oGroup->questionGroupL10ns[$sLanguage]->$sGroupSetting)) {
$aResult[$sGroupSetting] = $oGroup->questionGroupL10ns[$sLanguage]->$sGroupSetting;
}
}
return $aResult;
} else {
return array('status' => 'No permission');
return array('status' => 'No permission');
}
} else {
return array('status' => 'Invalid Session Key');
return array('status' => 'Invalid Session Key');
}
}

Expand Down
52 changes: 52 additions & 0 deletions tests/unit/helpers/RemoteControlTest.php
Expand Up @@ -159,4 +159,56 @@ public function testListGroups()
$this->assertCount(1, $result);
$this->assertEquals(null, $result[0]['group_name']);
}

/**
* @see https://bugs.limesurvey.org/view.php?id=15813
*/
public function testGetGroupProperties()
{
\Yii::import('application.helpers.remotecontrol.remotecontrol_handle', true);
\Yii::import('application.helpers.viewHelper', true);
\Yii::import('application.libraries.BigData', true);
$dbo = \Yii::app()->getDb();

// Make sure the Authdb is in database (might not be the case if no browser login attempt has been made).
$plugin = \Plugin::model()->findByAttributes(array('name'=>'Authdb'));
if (!$plugin) {
$plugin = new \Plugin();
$plugin->name = 'Authdb';
$plugin->active = 1;
$plugin->save();
} else {
$plugin->active = 1;
$plugin->save();
}
App()->getPluginManager()->loadPlugin('Authdb', $plugin->id);
// Clear login attempts.
$query = sprintf('DELETE FROM {{failed_login_attempts}}');
$dbo->createCommand($query)->execute();


$filename = self::$surveysFolder . '/limesurvey_survey_remote_api_group_language.lss';
self::importSurvey($filename);

// Create handler.
$admin = new \AdminController('dummyid');
$handler = new \remotecontrol_handle($admin);

// Get session key.
$sessionKey = $handler->get_session_key(
self::$username,
self::$password
);
$this->assertNotEquals(['status' => 'Invalid user name or password'], $sessionKey);

$survey = \Survey::model()->findByPk(self::$surveyId);
$group = $survey->groups[0];

// Fetch English group text.
$result = $handler->get_group_properties($sessionKey, $group->gid, ['group_name'], 'en');
$this->assertEquals('My first question group', $result['group_name']);

$result = $handler->get_group_properties($sessionKey, $group->gid, ['group_name'], 'de');
$this->assertEquals('Das Deutsch title', $result['group_name']);
}
}

0 comments on commit 5a39b15

Please sign in to comment.