new: [eventgraph:viewPicture] Allow access to saved picture from the eventgraph history

pull/7242/head
mokaddem 2021-03-24 13:42:30 +01:00
parent d7de209623
commit a1b5141a5a
No known key found for this signature in database
GPG Key ID: 164C473F627A06FA
3 changed files with 46 additions and 0 deletions

View File

@ -727,6 +727,7 @@ class ACLComponent extends Component
),
'eventGraph' => array(
'view' => array('*'),
'viewPicture' => array('*'),
'add' => array('perm_add'),
'delete' => array('perm_modify'),
)

View File

@ -50,6 +50,37 @@ class EventGraphController extends AppController
return $this->RestResponse->viewData($eventGraphs, $this->response->type());
}
public function viewPicture($event_id, $graph_id)
{
$this->loadModel('Event');
$event = $this->Event->fetchSimpleEvent($this->Auth->user(), $event_id);
if (empty($event)) {
throw new NotFoundException('Invalid event');
}
$conditions = [
'EventGraph.event_id' => $event['Event']['id'],
'EventGraph.org_id' => $this->Auth->user('org_id'),
'EventGraph.id' => $graph_id,
];
$eventGraph = $this->EventGraph->find('first', array(
'conditions' => $conditions,
'contain' => array(
'User' => array(
'fields' => array(
'User.email'
)
)
)
));
if (empty($eventGraph)) {
throw new MethodNotAllowedException('Invalid event graph');
}
$eventGraph = $eventGraph;
$imageData = $this->EventGraph->getPictureData($eventGraph);
return new CakeResponse(array('body' => $imageData, 'type' => 'png'));
}
public function add($event_id = false)
{
if ($this->request->is('get')) {

View File

@ -53,4 +53,18 @@ class EventGraph extends AppModel
}
return true;
}
public function getPictureData($eventGraph)
{
$b64 = str_replace('data:image/png;base64,', '', $eventGraph['EventGraph']['preview_img']);
$imageDecoded = base64_decode($b64);
$source = imagecreatefromstring($imageDecoded);
imagesavealpha($source, true);
ob_start();
imagepng($source, null, 9);
$imageData = ob_get_contents();
ob_end_clean();
imagedestroy($source);
return $imageData;
}
}