Commit bea247c9 authored by Stefan Busemann's avatar Stefan Busemann
Browse files

[TASK] Add Slackbot support

parent 180b7006
Pipeline #1722 failed with stages
in 23 seconds
...@@ -31,7 +31,9 @@ namespace T3o\T3omy\Hooks; ...@@ -31,7 +31,9 @@ namespace T3o\T3omy\Hooks;
use In2code\Femanager\Domain\Model\User; use In2code\Femanager\Domain\Model\User;
use T3o\T3oLdap\Connectors\Ldap; use T3o\T3oLdap\Connectors\Ldap;
use T3o\T3oLdap\Utility\UserCreateUpdateDelete; use T3o\T3oLdap\Utility\UserCreateUpdateDelete;
use TYPO3\CMS\Core\TypoScript\TypoScriptService;
use TYPO3\CMS\Core\Utility\GeneralUtility; use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Utility\DebuggerUtility;
/** /**
* Hook Functions for \ * Hook Functions for \
...@@ -43,20 +45,31 @@ class FeManagerHooks ...@@ -43,20 +45,31 @@ class FeManagerHooks
*/ */
protected $ldapUserCreateUpdateDelete; protected $ldapUserCreateUpdateDelete;
/**
* @var settings
*/
protected $settings;
/** /**
* DataHandlerHook constructor * DataHandlerHook constructor
*/ */
public function __construct() public function __construct()
{ {
$this->ldapUserCreateUpdateDelete = new UserCreateUpdateDelete();
$this->settings = $this->getTSConifiguration();
#$this->ldapUserCreateUpdateDelete = new UserCreateUpdateDelete();
} }
public function newUserNotification() public function newUserNotification(User $user, $plugin)
{ {
// @todo add user location
$mapsLink = ' - na - ';
// this event happens, when a user registered himself and no autoapprovement got active // this event happens, when a user registered himself and no autoapprovement got active
die ('newUserNotification');
// @todo slack message notification // @todo add second confirmation email
$this->sendConfirmationMessage($user); $this->sendConfirmationEmail($user);
$this->sendSlackBotMessage( $this->sendSlackBotMessage(
'New User Registration', 'New User Registration',
sprintf( sprintf(
...@@ -71,12 +84,14 @@ class FeManagerHooks ...@@ -71,12 +84,14 @@ class FeManagerHooks
} }
public function newUserAutoApprovement(User $user, $plugin)
public function newUserAutoApprovement()
{ {
// @todo add user location
$mapsLink = ' - na - ';
// this event happens, when a user registered himself and an autoapprovement got active // this event happens, when a user registered himself and an autoapprovement got active
die('AutoApprovementDone');
// @todo slack message notification $this->createUser($user);
$this->sendSlackBotMessage( $this->sendSlackBotMessage(
'New user auto approvement', 'New user auto approvement',
sprintf( sprintf(
...@@ -88,13 +103,11 @@ class FeManagerHooks ...@@ -88,13 +103,11 @@ class FeManagerHooks
), ),
'info' 'info'
); );
} }
public function newUserAdminApprovement() public function newUserAdminApprovement(User $user)
{ {
#AutoApprovementRefused #AutoApprovementRefused
die('AdminApprovementDone');
$this->sendSlackBotMessage( $this->sendSlackBotMessage(
'User approved', 'User approved',
sprintf( sprintf(
...@@ -107,15 +120,14 @@ class FeManagerHooks ...@@ -107,15 +120,14 @@ class FeManagerHooks
); );
} }
public function newUserAdminDecline() public function newUserAdminDecline(User $user)
{ {
#AutoApprovementRefused #AutoApprovementRefused
die('AdminApprovementRefused');
$this->sendSlackBotMessage( $this->sendSlackBotMessage(
'User declined', 'User declined',
sprintf( sprintf(
'the user *%s* with email *%s* has been declined by *%s*', 'the user *%s* with email *%s* has been declined by *%s*',
$username, $user->getUsername(),
$user->getEmail(), $user->getEmail(),
$GLOBALS['BE_USER']->user['username'] $GLOBALS['BE_USER']->user['username']
), ),
...@@ -128,11 +140,11 @@ class FeManagerHooks ...@@ -128,11 +140,11 @@ class FeManagerHooks
* in LDAP. * in LDAP.
* *
* @param \In2code\Femanager\Domain\Model\User $user * @param \In2code\Femanager\Domain\Model\User $user
* @return void * @return bool
*/ */
public function createUser(User $user) public function createUser(User $user)
{ {
$result = $this->ldapUserCreateUpdateDelete->updateUser($user->getUid(), $user->toArray()); #$result = $this->ldapUserCreateUpdateDelete->updateUser($user->getUid(), $user->toArray());
// TODO: Create log entry if user has been successfully added or throw an exception otherwise // TODO: Create log entry if user has been successfully added or throw an exception otherwise
...@@ -141,6 +153,8 @@ class FeManagerHooks ...@@ -141,6 +153,8 @@ class FeManagerHooks
} else { } else {
} }
return true;
} }
/** /**
...@@ -211,9 +225,9 @@ class FeManagerHooks ...@@ -211,9 +225,9 @@ class FeManagerHooks
*/ */
protected function sendSlackBotMessage($title, $text, $color = 'notice') protected function sendSlackBotMessage($title, $text, $color = 'notice')
{ {
$url = $this->settings['webhook']['url']; $url = $this->settings['slackbot']['webhook']['url'];
$content = json_encode(array( $content = json_encode(array(
'securityToken' => $this->settings['webhook']['securityToken'], 'securityToken' => $this->settings['slackbot']['webhook']['securityToken'],
'color' => $color, 'color' => $color,
'title' => $title, 'title' => $title,
'text' => $text 'text' => $text
...@@ -228,4 +242,26 @@ class FeManagerHooks ...@@ -228,4 +242,26 @@ class FeManagerHooks
curl_exec($curl); curl_exec($curl);
curl_close($curl); curl_close($curl);
} }
protected function getTSConifiguration()
{
// init ConfigurationManager
$configurationManager = GeneralUtility::makeInstance('TYPO3\\CMS\\Extbase\\Configuration\\ConfigurationManager');
// load complete ts
$tsSettings = $configurationManager->getConfiguration(\TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface::CONFIGURATION_TYPE_FULL_TYPOSCRIPT);
// remove dots from configuration
$typoscriptService = GeneralUtility::makeInstance(TypoScriptService::class);
$tsSettings = $typoscriptService->convertTypoScriptArrayToPlainArray($tsSettings);
return $this->settings = $tsSettings['plugin']['tx_t3omy'];
}
/**
* @return bool
*/
protected function sendConfirmationEmail(User $user ){
return true;
}
} }
Supports Markdown
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