Commit f153b423 authored by Thomas Löffler's avatar Thomas Löffler
Browse files

Add try/catch and return variables for functions

parent fce7d97a
Pipeline #8334 passed with stages
in 4 minutes and 37 seconds
......@@ -17,7 +17,7 @@ use TYPO3\CMS\Extbase\Mvc\Controller\ActionController;
*/
class GdprController extends ActionController
{
public function initializeAction()
public function initializeAction(): void
{
parent::initializeAction();
if (!$GLOBALS['BE_USER']) {
......@@ -37,7 +37,7 @@ class GdprController extends ActionController
/**
*
*/
public function step1Action()
public function step1Action(): void
{
$uriBuilder = GeneralUtility::makeInstance(UriBuilder::class);
......@@ -49,7 +49,7 @@ class GdprController extends ActionController
);
}
public function step2Action()
public function step2Action(): void
{
if ($this->request->hasArgument('username')) {
$userName = $this->request->getArgument('username');
......@@ -75,7 +75,7 @@ class GdprController extends ActionController
}
}
public function confirmAction()
public function confirmAction(): void
{
if (!$this->request->hasArgument('user')) {
$this->addFlashMessage('No user found', 'Error', AbstractMessage::ERROR);
......@@ -96,7 +96,7 @@ class GdprController extends ActionController
);
}
public function deleteAction()
public function deleteAction(): void
{
if (!$this->request->hasArgument('user')) {
$this->addFlashMessage('No user found', 'Error', AbstractMessage::ERROR);
......@@ -111,17 +111,21 @@ class GdprController extends ActionController
$data['gitlab_ticket'] = $this->request->getArgument('gitlab');
$data['comment'] = $this->request->getArgument('comment');
$this->sendORTSMail($data);
try {
$this->sendOtrsMail($data);
$this->createORTSTicket($data);
$this->createOtrsTicket($data);
$this->deleteLdapUser($data);
$this->deleteLdapUser($data);
$this->deleteLocalUser($data);
$this->deleteLocalUser($data);
$this->createOldUser($data);
$this->createOldUser($data);
$this->addFlashMessage('The user was deleted successfully', 'LDAP deletion', AbstractMessage::OK);
$this->addFlashMessage('The user was deleted successfully', 'LDAP deletion', AbstractMessage::OK);
} catch (\Exception $e) {
$this->addFlashMessage('Deletion not successful. Error: ' . $e->getMessage(), 'LDAP deletion', AbstractMessage::ERROR);
}
$this->forward('step1');
}
......@@ -131,7 +135,7 @@ class GdprController extends ActionController
* @return bool
* @throws \Exception
*/
protected function checkLdapUser(string $userName)
protected function checkLdapUser(string $userName): bool
{
/** @var Ldap $ldap */
try {
......@@ -140,10 +144,7 @@ class GdprController extends ActionController
throw $e;
}
if ($ldap->userExists($userName)) {
return true;
}
return false;
return $ldap->userExists($userName);
}
/**
......@@ -151,7 +152,7 @@ class GdprController extends ActionController
* @return array
* @throws \Exception
*/
protected function getLdapUser(string $userName)
protected function getLdapUser(string $userName): array
{
/** @var Ldap $ldap */
try {
......@@ -163,30 +164,29 @@ class GdprController extends ActionController
return $ldap->getUser($userName);
}
protected function createOldUser(array $data)
protected function createOldUser(array $data): void
{
$dbConnection = GeneralUtility::makeInstance(ConnectionPool::class);
$dbConnection->getConnectionForTable('old_users')->insert('old_users', $data);
}
protected function sendORTSMail(array $data)
protected function sendOtrsMail(array $data): void
{
$message = 'Dear data privacy officer,
we like to inform you, that this
we like to inform you, that this
LDAP User: ' . $data['username'] . '
LDAP User: ' . $data['username'] . '
was deleted.
The Server Team is informed, and will remove all further account data (wiki, forge, talk, ...).
OTRS Link of initial Ticket from data privacy officer: ' . $data['otrs_ticket'] . '
Gitlab Link of typo3.org website team: ' . $data['gitlab_ticket'] . '
further comment:' . $data['comment'] . '
LDAP User deletion was performed by: ' . $GLOBALS['BE_USER']->name . '
was deleted.
Your TYPO3 website administration team
';
The Server Team is informed, and will remove all further account data (wiki, forge, talk, ...).
OTRS Link of initial Ticket from data privacy officer: ' . $data['otrs_ticket'] . '
Gitlab Link of typo3.org website team: ' . $data['gitlab_ticket'] . '
further comment:' . $data['comment'] . '
LDAP User deletion was performed by: ' . $GLOBALS['BE_USER']->name . '
Your TYPO3 website administration team';
$mail = GeneralUtility::makeInstance(MailMessage::class);
$mail->setSubject('[Ticket#' . $data['otrs'] . '] User deletion notification : ' . $data['username']);
$mail->setFrom(['confirm-t3o-account@typo3.org' => 'typo3.org administration']);
......@@ -195,21 +195,21 @@ class GdprController extends ActionController
$mail->send();
}
protected function createORTSTicket(array $data)
protected function createOtrsTicket(array $data): void
{
$message = 'Dear Server Team,
please delete all accounts from this LDAP User:
Username: ' . $data['username'] . '
Mail: ' . $data['email'] . '
OTRS Link of initial Ticket from data privacy officer: ' . $data['otrs_ticket'] . '
Gitlab Link of typo3.org website team: ' . $data['gitlab_ticket'] . '
further comment: ' . $data['comment'] . '
LDAP User deletion was performed by: ' . $GLOBALS['BE_USER']->name . '
Your TYPO3 website administration team';
please delete all accounts from this LDAP User:
Username: ' . $data['username'] . '
Mail: ' . $data['email'] . '
OTRS Link of initial Ticket from data privacy officer: ' . $data['otrs_ticket'] . '
Gitlab Link of typo3.org website team: ' . $data['gitlab_ticket'] . '
further comment: ' . $data['comment'] . '
LDAP User deletion was performed by: ' . $GLOBALS['BE_USER']->name . '
Your TYPO3 website administration team';
$mail = GeneralUtility::makeInstance(MailMessage::class);
$mail->setSubject('User delection process: ' . $data['username']);
......@@ -219,7 +219,7 @@ class GdprController extends ActionController
$mail->send();
}
protected function deleteLdapUser(array $data)
protected function deleteLdapUser(array $data): bool
{
// delete my.typo3.org user
/** @var Ldap $ldap */
......@@ -229,12 +229,10 @@ class GdprController extends ActionController
throw $e;
}
$ldap->deleteUser($data['userName']);
return true;
return $ldap->deleteUser($data['userName']);
}
protected function deleteLocalUser(array $data)
protected function deleteLocalUser(array $data): void
{
$dbConnection = GeneralUtility::makeInstance(ConnectionPool::class);
$dbConnection->getConnectionForTable('fe_users')->delete(
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment