Skip to content

Commit 7702124

Browse files
Merge pull request #2 from Gamabunta57/master
PB-24082 - Improve Selenium API to allow mail type filtering
2 parents ade46d4 + eecb42d commit 7702124

File tree

2 files changed

+28
-4
lines changed

2 files changed

+28
-4
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "passbolt/passbolt-selenium-api",
33
"description": "Passbolt selenium testing helper endpoints",
44
"type": "cakephp-plugin",
5-
"version": "3.1.2",
5+
"version": "3.2.0",
66
"keywords": [
77
"password",
88
"passbolt",

src/Controller/EmailController.php

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,16 @@ public function showLastEmail($username)
6666
throw new HttpException(__('The username does not exist.'));
6767
}
6868
$EmailQueue = TableRegistry::getTableLocator()->get('EmailQueue.EmailQueue');
69-
$email = $EmailQueue->find('all')
69+
$emailQuery = $EmailQueue->find('all')
7070
->where(['email' => $username])
71-
->order(['created' => 'DESC'])
72-
->first();
71+
->order(['created' => 'DESC']);
72+
73+
$emailType = $this->getEmailType();
74+
if (!is_null($emailType)) {
75+
$emailQuery->where(['template' => $emailType]);
76+
}
77+
78+
$email = $emailQuery->first();
7379
if (empty($email)) {
7480
throw new HttpException(__('No email was sent to this user.'));
7581
}
@@ -85,4 +91,22 @@ public function showLastEmail($username)
8591
->setTemplate($email->template)
8692
->setTemplatePath("email/$format");
8793
}
94+
95+
/**
96+
* Returns a validated `has-type` filter set in the query parameters of the request if any.
97+
* @return string|null
98+
*/
99+
private function getEmailType() {
100+
$filter = $this->request->getQuery('filter');
101+
if (is_null($filter) || !is_array($filter)) {
102+
return null;
103+
}
104+
105+
$hasType = $filter['has-type'];
106+
if (empty($hasType) || !is_string($hasType)) {
107+
return null;
108+
}
109+
110+
return $hasType;
111+
}
88112
}

0 commit comments

Comments
 (0)