Skip to content

Commit

Permalink
Merge pull request #15 from FreePBX/bugfix/FREEPBX17-784-v17
Browse files Browse the repository at this point in the history
FREEPBX17-784 added validations to ucp voicemail widget
  • Loading branch information
kguptasangoma authored May 28, 2024
2 parents c6c2425 + 0945f4c commit faaa069
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 23 deletions.
5 changes: 5 additions & 0 deletions Voicemail.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -2964,4 +2964,9 @@ private function regenerateVMMsgId($data, $messages) {
}
return $data;
}

public function checkVoicemailEnabled($extension) {
$voicemailStatus = $this->astman->database_get("AMPUSER", $extension."/voicemail");
return $voicemailStatus != 'novm' ? true : false;
}
}
77 changes: 54 additions & 23 deletions ucp/Voicemail.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,21 @@ function __construct($Modules) {
}

public function getWidgetList() {
if (!$this->enabled) {
return array();
$responseData = array(
"rawname" => "voicemail",
"display" => _("Voicemail"),
"icon" => "fa fa-inbox",
"list" => []
);
$errors = $this->validate();
if ($errors['hasError']) {
return array_merge($responseData, $errors);
}

$widgets = array();

$extensions = $this->extensions;
if (!empty($extensions)) {
$boxes = $this->getMailboxCount($extensions);
foreach ($extensions as $extension) {
$data = $this->UCP->FreePBX->Core->getDevice($extension);
if (empty($data) || empty($data['description'])) {
Expand All @@ -78,36 +84,61 @@ public function getWidgetList() {
else {
$name = $data['description'];
}
$o = $this->UCP->FreePBX->Voicemail->getVoicemailBoxByExtension($extension);
if (!empty($o) && isset($boxes['extensions'][$extension])) {
$widgets[$extension] = array(
"display" => $name,
"hasSettings" => true,
"minsize" => array( "height" => 5, "width" => 5 ),
"defaultsize" => array( "height" => 7, "width" => 6 )
);
}
$widgets[$extension] = array(
"display" => $name,
"hasSettings" => true,
"minsize" => array( "height" => 5, "width" => 5 ),
"defaultsize" => array( "height" => 7, "width" => 6 )
);
}
}

if (empty($widgets)) {
return array();
}
$responseData['list'] = $widgets;
return $responseData;
}

return array(
"rawname" => "voicemail",
"display" => _("Voicemail"),
"icon" => "fa fa-inbox",
"list" => $widgets
/**
* validate against rules
*/
private function validate($extension = false) {
$data = array(
'hasError' => false,
'errorMessages' => []
);

if (!$this->enabled) {
$data['hasError'] = true;
$data['errorMessages'][] = _('UCP Voicemail is not enabled for this user.');
}
if (empty($this->extensions)) {
$data['hasError'] = true;
$data['errorMessages'][] = _('There are no assigned extensions.');
}
if ($extension !== false) {
if (empty($extension)) {
$data['hasError'] = true;
$data['errorMessages'][] = _('The given extension is empty.');
}
if (!$this->_checkExtension($extension)) {
$data['hasError'] = true;
$data['errorMessages'][] = _('This extension is not assigned to this user.');
}
if (!$this->UCP->FreePBX->Voicemail->checkVoicemailEnabled($extension)) {
$data['hasError'] = true;
$data['errorMessages'][] = _('Voicemail is not enabled for this extension.');
}
}

return $data;
}

public function getWidgetDisplay($id) {
$errors = $this->validate($id);
if ($errors['hasError']) {
return $errors;
}
$html = '';
$ext = !empty($id) ? $id : '';
if (!empty($ext) && !$this->_checkExtension($ext)) {
return array();
}
$view = !empty($_REQUEST['view']) ? $_REQUEST['view'] : 'folder';
$page = !empty($_REQUEST['page']) ? $_REQUEST['page'] : 1;
$folders = $this->UCP->FreePBX->Voicemail->getFolders();
Expand Down

0 comments on commit faaa069

Please sign in to comment.