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

Merge branch 'introduce-test-build' into 'develop'

Introduce test build and fix CGL issues

See merge request !77
parents 0fe7fa63 4032840e
Pipeline #4900 failed with stages
in 5 minutes and 38 seconds
......@@ -7,10 +7,21 @@ before_script:
stages:
- dump
- test
- build
- layout
- deploy
test:php:
stage: test
image: ekreative/php-cs-fixer:2
variables:
GIT_STRATEGY: "clone"
script:
- php-cs-fixer fix --dry-run --config=.gitlab-ci/build/.php_cs --diff
except:
- assets
build:
stage: build
image: php:7.0-alpine
......
<?php
/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/
/**
* This file represents the configuration for Code Sniffing PSR-2-related
* automatic checks of coding guidelines
* Install @fabpot's great php-cs-fixer tool via
*
* $ composer global require friendsofphp/php-cs-fixer
*
* And then simply run
*
* $ php-cs-fixer fix --config ../Build/.php_cs
*
* inside the TYPO3 directory. Warning: This may take up to 10 minutes.
*
* For more information read:
* https://www.php-fig.org/psr/psr-2/
* https://cs.sensiolabs.org
*/
if (PHP_SAPI !== 'cli') {
die('This script supports command line usage only. Please check your command.');
}
// Define in which folders to search and which folders to exclude
// Exclude some directories that are excluded by Git anyways to speed up the sniffing
$finder = PhpCsFixer\Finder::create()
->exclude('vendor')
->exclude('typo3temp')
->in(__DIR__ . '/../../');
// Return a Code Sniffing configuration using
// all sniffers needed for PSR-2
// and additionally:
// - Remove leading slashes in use clauses.
// - PHP single-line arrays should not have trailing comma.
// - Single-line whitespace before closing semicolon are prohibited.
// - Remove unused use statements in the PHP source code
// - Ensure Concatenation to have at least one whitespace around
// - Remove trailing whitespace at the end of blank lines.
return PhpCsFixer\Config::create()->setRiskyAllowed(true)->setRules([
'@PSR2' => true,
'@DoctrineAnnotation' => true,
'no_leading_import_slash' => true,
'no_trailing_comma_in_singleline_array' => true,
'no_singleline_whitespace_before_semicolons' => true,
'no_unused_imports' => true,
'concat_space' => ['spacing' => 'one'],
'no_whitespace_in_blank_line' => true,
'ordered_imports' => true,
'single_quote' => true,
'no_empty_statement' => true,
'no_extra_consecutive_blank_lines' => true,
'phpdoc_no_package' => true,
'phpdoc_scalar' => true,
'no_blank_lines_after_phpdoc' => true,
'array_syntax' => ['syntax' => 'short'],
'whitespace_after_comma_in_array' => true,
'function_typehint_space' => true,
'hash_to_slash_comment' => true,
'no_alias_functions' => true,
'lowercase_cast' => true,
'no_leading_namespace_whitespace' => true,
'native_function_casing' => true,
'no_short_bool_cast' => true,
'no_unneeded_control_parentheses' => true,
'phpdoc_no_empty_return' => true,
'phpdoc_trim' => true,
'no_superfluous_elseif' => true,
'no_useless_else' => true,
'phpdoc_types' => true,
'phpdoc_types_order' => ['null_adjustment' => 'always_last', 'sort_algorithm' => 'none'],
'return_type_declaration' => ['space_before' => 'none'],
'cast_spaces' => ['space' => 'none'],
'declare_equal_normalize' => ['space' => 'single'],
'dir_constant' => true,
])->setFinder($finder);
......@@ -2,7 +2,6 @@
/** #ddev-generated: Automatically generated TYPO3 AdditionalConfiguration.php file.
ddev manages this file and may delete or overwrite the file unless this comment is removed.
*/
$GLOBALS['TYPO3_CONF_VARS']['SYS']['trustedHostsPattern'] = '.*';
$GLOBALS['TYPO3_CONF_VARS']['DB']['Connections']['Default'] = array_merge($GLOBALS['TYPO3_CONF_VARS']['DB']['Connections']['Default'], [
......@@ -23,4 +22,4 @@ $GLOBALS['TYPO3_CONF_VARS']['MAIL'] = [
];
$GLOBALS['TYPO3_CONF_VARS']['BE']['installToolPassword'] = '$P$CZqeoYBTHC0kXKny4tpTvBSzzV5wVY0'; /* joh316 */
$GLOBALS['TYPO3_CONF_VARS']['BE']['loginSecurityLevel'] = 'normal';
\ No newline at end of file
$GLOBALS['TYPO3_CONF_VARS']['BE']['loginSecurityLevel'] = 'normal';
<?php
namespace T3o\T3oSlack\Command;
use T3o\T3oSlack\Domain\Model\SlackUser;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use \TYPO3\CMS\Extbase\Mvc\Controller\CommandController;
use \T3o\T3oSlack\Domain\Service\SlackApi;
use T3o\T3oSlack\Domain\Service\SlackApi;
use TYPO3\CMS\Core\TypoScript\TypoScriptService;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Mvc\Controller\CommandController;
/***************************************************************
* Copyright notice
......@@ -35,7 +33,6 @@ use TYPO3\CMS\Core\TypoScript\TypoScriptService;
*
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
class SlackImportCommandController extends CommandController
{
/**
......@@ -50,15 +47,15 @@ class SlackImportCommandController extends CommandController
public $settings;
/**
* @var \TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface
* @inject
* @var \T3o\T3oSlack\Domain\Service\SlackApi;
*/
protected $configurationManager;
public $slackApi;
/**
* @var \T3o\T3oSlack\Service\SlackApi;
* @var \TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface
* @inject
*/
public $slackApi;
protected $configurationManager;
/**
* @var \TYPO3\CMS\Extbase\Persistence\Generic\PersistenceManager
......@@ -68,12 +65,12 @@ class SlackImportCommandController extends CommandController
/**
* Import all Slack Users
*
* @return string '1' for success, '0' for error
* @throws \Exception
*/
public function importCommand()
{
$this->getTSConfiguration();
// delete all uses before fresh import
......@@ -82,57 +79,51 @@ class SlackImportCommandController extends CommandController
$this->persistenceManager->persistAll();
$this->slackApi = GeneralUtility::makeInstance(SlackApi::class);
$cursor='';
$cursor = '';
$limiter = 0;
$counter = 0;
do {
$response = $this->slackApi->getUsers($cursor);
if ($response['ok']) {
foreach ($response['members'] as $member ) {
if ($member['is_bot']==false) {
$slackUser = GeneralUtility::makeInstance(SlackUser::class);
$slackUser->setEmail ($member['profile']['email']);
$slackUser->setRealName ($member['real_name']);
$slackUser->setSlackId($member['id']);
$slackUser->setSlackUserName($member['name']);
$counter++;
$this->slackUserRepository->add($slackUser);
}
}
if ($response['response_metadata']['next_cursor'])
{
$cursor = $response['response_metadata']['next_cursor'];
}
else {
$cursor = '';
}
$this->persistenceManager->persistAll();
$limiter++;
if (!$response['ok']) {
throw new \Exception('Slack API error . Reason: ' . $response['error']);
}
if ($limiter>999)
{
// break loop, if we have more then 999 loops
throw new \Exception('Slack import stopped, due to many loops.');
$cursor='';
foreach ($response['members'] as $member) {
if ($member['is_bot'] == false) {
$slackUser = GeneralUtility::makeInstance(SlackUser::class);
$slackUser->setEmail($member['profile']['email']);
$slackUser->setRealName($member['real_name']);
$slackUser->setSlackId($member['id']);
$slackUser->setSlackUserName($member['name']);
$counter++;
$this->slackUserRepository->add($slackUser);
}
}
else {
throw new \Exception('Slack API error . Reason: ' . $response['error']);
if ($response['response_metadata']['next_cursor']) {
$cursor = $response['response_metadata']['next_cursor'];
} else {
$cursor = '';
}
$this->persistenceManager->persistAll();
$limiter++;
if ($limiter > 999) {
// break loop, if we have more then 999 loops
throw new \Exception('Slack import stopped, due to many loops.');
}
} while ($cursor);
$GLOBALS['BE_USER']->simplelog('Import of Slack User sucessful - imported ' . $counter . ' users', $extKey='t3o_slack', $error=0);
$GLOBALS['BE_USER']->simplelog(
'Import of Slack User sucessful - imported ' . $counter . ' users',
't3o_slack'
);
return '1';
}
/**
* @return void
*/
protected function getTSConfiguration()
{
// load complete ts
......
<?php
namespace T3o\T3oSlack\Controller;
use In2code\Femanager\Domain\Model\User;
......@@ -9,18 +8,11 @@ use In2code\Femanager\Utility\HashUtility;
use In2code\Femanager\Utility\StringUtility;
use T3o\T3oSlack\Domain\Model\SlackUser;
use T3o\T3oSlack\Domain\Service\SlackApi;
use TYPO3\CMS\Core\Messaging\AbstractMessage;
use TYPO3\CMS\Core\Messaging\FlashMessage;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Mvc\Controller\ActionController;
use TYPO3\CMS\Extbase\Utility\LocalizationUtility;
/**
*
*
* @package t3o_slack
* @license http://www.gnu.org/licenses/gpl.html GNU General Public License, version 3 or later
*
*/
class SlackUserController extends ActionController
{
/**
......@@ -46,7 +38,6 @@ class SlackUserController extends ActionController
*
* @param \T3o\T3oSlack\Domain\Model\SlackUser $newSlackUser
* @dontvalidate $newSlackUser
* @return void
*/
public function newAction(SlackUser $newSlackUser = null)
{
......@@ -57,13 +48,26 @@ class SlackUserController extends ActionController
$this->view->assign('newSlackUser', $newSlackUser);
}
/**
* @return SlackUser
*/
public function initUser()
{
/** @var \T3o\T3oSlack\Domain\Model\SlackUser $newSlackUser */
$newSlackUser = $this->objectManager->get('T3o\T3oSlack\Domain\Model\SlackUser');
// initialize user with fe_user data if there is no object
$newSlackUser->setSlackUserName($GLOBALS['TSFE']->fe_user->user['username']);
$newSlackUser->setRealName($GLOBALS['TSFE']->fe_user->user['name']);
$newSlackUser->setEmail($GLOBALS['TSFE']->fe_user->user['email']);
return $newSlackUser;
}
/**
* action for errors and messages
*
* @param \T3o\T3oSlack\Domain\Model\SlackUser $newSlackUser
* @dontvalidate $newSlackUser
* @return void
*/
public function messageAction(SlackUser $newSlackUser = null)
{
......@@ -72,8 +76,6 @@ class SlackUserController extends ActionController
/**
* action to prepare connection of existing slack user with typo3.org accout
*
* @return void
*/
public function connectAction()
{
......@@ -84,7 +86,10 @@ class SlackUserController extends ActionController
* action create
*
* @param \T3o\T3oSlack\Domain\Model\SlackUser $newSlackUser
* @return void
* @throws \TYPO3\CMS\Extbase\Mvc\Exception\StopActionException
* @throws \TYPO3\CMS\Extbase\Mvc\Exception\UnsupportedRequestTypeException
* @throws \TYPO3\CMS\Extbase\Persistence\Exception\IllegalObjectTypeException
* @throws \TYPO3\CMS\Extbase\Persistence\Exception\UnknownObjectException
*/
public function createAction(SlackUser $newSlackUser)
{
......@@ -94,29 +99,39 @@ class SlackUserController extends ActionController
switch ($response['error']) {
case 'already_in_team':
$this->addFlashMessage(LocalizationUtility::translate('tx_t3oslack.existingAccount',
$this->extensionName) . $newSlackUser->getEmail(), '', AbstractMessage::WARNING);
$this->addFlashMessage(
LocalizationUtility::translate('tx_t3oslack.existingAccount', $this->extensionName) . $newSlackUser->getEmail(),
'',
FlashMessage::WARNING
);
break;
case 'missing_scope':
$this->addFlashMessage(LocalizationUtility::translate('tx_t3oslack.apiKeyMissing',
$this->extensionName), '', AbstractMessage::ERROR);
$this->addFlashMessage(
LocalizationUtility::translate('tx_t3oslack.apiKeyMissing', $this->extensionName),
'',
FlashMessage::ERROR
);
break;
case 'already_invited':
$this->addFlashMessage('You are already invited. Please check your inbox and confirm your invitation',
'Pending invitation', AbstractMessage::ERROR);
$this->addFlashMessage(
'You are already invited. Please check your inbox and confirm your invitation',
'Pending invitation',
FlashMessage::ERROR
);
break;
default:
if ($response['error']) {
$message = ' Error code: ' . $response['error'];
}
$this->addFlashMessage(LocalizationUtility::translate('tx_t3oslack.noConnection',
$this->extensionName) . $message, '', AbstractMessage::ERROR);
$this->addFlashMessage(
LocalizationUtility::translate('tx_t3oslack.noConnection', $this->extensionName) . $message,
'',
FlashMessage::ERROR
);
break;
}
if ($response['ok'] == 1) {
if ($response['ok']) {
$this->addFlashMessage(LocalizationUtility::translate('tx_t3oslack.userCreated', $this->extensionName));
// add temp slack ID
......@@ -125,15 +140,11 @@ class SlackUserController extends ActionController
$this->slackFrontendUserRepository->update($slackFrontendUser);
$this->persistenceManager->persistAll();
}
$this->redirect('message');
}
/**
*
*/
public function indexAction()
{
$this->checkAccessAndConfig();
......@@ -153,16 +164,22 @@ class SlackUserController extends ActionController
$GLOBALS['TSFE']->fe_user->user['slack_id'] = $slackUser->getSlackId();
$this->slackFrontendUserRepository->update($slackFrontendUser);
$this->persistenceManager->persistAll();
$this->addFlashMessage('Your typo3.org account is now connected with Slack.',
'Success', AbstractMessage::OK);
$this->addFlashMessage(
'Your typo3.org account is now connected with Slack.',
'Success',
FlashMessage::OK
);
} else {
$this->addFlashMessage('Your account is not confirmed yet. Please check your inbox and confirm your invitation',
'Slack account not yet created', AbstractMessage::INFO);
$this->addFlashMessage(
'Your account is not confirmed yet. Please check your inbox and confirm your invitation',
'Slack account not yet created',
FlashMessage::INFO
);
}
} else {
$slackUser = $this->slackUserRepository->findBySlackId($GLOBALS['TSFE']->fe_user->user['slack_id']);
$this->view->assign('SlackUser',$slackUser);
$this->view->assign('SlackUser', $slackUser);
}
} else {
$this->findExistingSlackUserByEmail($GLOBALS['TSFE']->fe_user->user['email']);
......@@ -171,30 +188,23 @@ class SlackUserController extends ActionController
$this->view->assign('Slack', $GLOBALS['TSFE']->fe_user->user['slack_id']);
}
/**
* @return SlackUser
*/
public function initUser()
{
/** @var \T3o\T3oSlack\Domain\Model\SlackUser $newSlackUser */
$newSlackUser = $this->objectManager->get('T3o\T3oSlack\Domain\Model\SlackUser');
// initialize user with fe_user data if there is no object
$newSlackUser->setSlackUserName($GLOBALS['TSFE']->fe_user->user['username']);
$newSlackUser->setRealName($GLOBALS['TSFE']->fe_user->user['name']);
$newSlackUser->setEmail($GLOBALS['TSFE']->fe_user->user['email']);
return $newSlackUser;
}
public function checkAccessAndConfig()
{
if (!$GLOBALS['TSFE']->fe_user->user['uid']) {
$this->addFlashMessage('You need to login first', 'No access', AbstractMessage::ERROR);
$this->addFlashMessage(
'You need to login first',
'No access',
FlashMessage::ERROR
);
$this->redirect('message');
}
// configuration check
if (!$this->settings['Slack']['teamUrl'] or !$this->settings['Slack']['token']) {
$this->addFlashMessage('no slack config found', 'Error', AbstractMessage::ERROR);
$this->addFlashMessage(
'no slack config found',
'Error',
FlashMessage::ERROR
);
$this->redirect('message');
}
}
......@@ -216,7 +226,6 @@ class SlackUserController extends ActionController
}
/**
*
* @param \T3o\T3oSlack\Domain\Model\SlackUser $newSlackUser
* @dontvalidate $newSlackUser
*/
......@@ -224,7 +233,11 @@ class SlackUserController extends ActionController
{
// check if email is valid
if (!GeneralUtility::validEmail($newSlackUser->getEmail())) {
$this->addFlashMessage('Please enter a valid email adress', 'No valid email', AbstractMessage::ERROR);
$this->addFlashMessage(
'Please enter a valid email adress',
'No valid email',
FlashMessage::ERROR
);
$this->redirect('connect');
}
......@@ -232,17 +245,26 @@ class SlackUserController extends ActionController
$slackUser = $this->slackUserRepository->findByEmail($newSlackUser->getEmail());
if ($slackUser) {
if ($this->sendConfirmationMail($newSlackUser)) {
$this->addFlashMessage('We have send you an confirmation email. Please confirm your account',
'Confirm your account', AbstractMessage::INFO);
$this->addFlashMessage(
'We have send you an confirmation email. Please confirm your account',
'Confirm your account',
FlashMessage::INFO
);
$this->redirect('message');
} else {
$this->addFlashMessage('Sorry, we were not able to send you a confirmation email', 'Mail failed',
AbstractMessage::ERROR);
$this->addFlashMessage(
'Sorry, we were not able to send you a confirmation email',
'Mail failed',
FlashMessage::ERROR
);
$this->redirect('message');
}
} else {
$this->addFlashMessage('Sorry, we were not able to find this slack account', 'No account found',
AbstractMessage::ERROR);
$this->addFlashMessage(
'Sorry, we were not able to find this slack account',
'No account found',
FlashMessage::ERROR
);
$this->redirect('message');
}
}
......@@ -257,13 +279,9 @@ class SlackUserController extends ActionController
// send mail with to slack Adress (given Adress)
// create hash
$userRepo = $this->objectManager->get(UserRepository::class);
$user = $userRepo->findByUid($GLOBALS['TSFE']->fe_user->user['uid']);
$femanagerSettings = $GLOBALS['TSFE']->tmpl->setup['plugin.']['tx_femanager.']['settings.'];
$sendMailService = $this->objectManager->get(SendMailService::class);
$sendMailService->send(
'ConfirmationMail',
StringUtility::makeEmailArray($newSlackUser->getEmail(), $user->getUsername()),
......@@ -287,8 +305,11 @@ class SlackUserController extends ActionController
* @param \In2code\Femanager\Domain\Model\User $user
* @param string $hash
* @param string $mail
* @throws \TYPO3\CMS\Extbase\Mvc\Exception\StopActionException
* @throws \TYPO3\CMS\Extbase\Mvc\Exception\UnsupportedRequestTypeException
* @throws \TYPO3\CMS\Extbase\Persistence\Exception\IllegalObjectTypeException
* @throws \TYPO3\CMS\Extbase\Persistence\Exception\UnknownObjectException
*/
public function confirmationAction(User $user, $hash, $mail)
{
// check link
......@@ -300,13 +321,19 @@ class SlackUserController extends ActionController
$this->slackFrontendUserRepository->update($slackFrontendUser);
$this->persistenceManager->persistAll();
$this->addFlashMessage('Your Slack profile is now connected to your TYPO3 profile.', 'Slack connected',
AbstractMessage::OK);
$this->addFlashMessage(
'Your Slack profile is now connected to your TYPO3 profile.',
'Slack connected',
FlashMessage::OK
);
$this->redirect('message');
} else {
$this->addFlashMessage('Sorry the parameters are not valid', 'Validation failed', AbstractMessage::ERROR);
$this->addFlashMessage(
'Sorry the parameters are not valid',
'Validation failed',
FlashMessage::ERROR
);
$this->redirect('message');
}
}
}
<?php
declare(strict_types=1);
declare(strict_types = 1);
namespace T3o\T3oSlack\Domain\Model;