diff options
Diffstat (limited to 'app/Subscriber')
-rw-r--r-- | app/Subscriber/AuthSubscriber.php | 95 | ||||
-rw-r--r-- | app/Subscriber/BaseSubscriber.php | 40 | ||||
-rw-r--r-- | app/Subscriber/BootstrapSubscriber.php | 29 | ||||
-rw-r--r-- | app/Subscriber/NotificationSubscriber.php | 49 | ||||
-rw-r--r-- | app/Subscriber/ProjectDailySummarySubscriber.php | 15 | ||||
-rw-r--r-- | app/Subscriber/ProjectModificationDateSubscriber.php | 21 | ||||
-rw-r--r-- | app/Subscriber/RecurringTaskSubscriber.php | 14 | ||||
-rw-r--r-- | app/Subscriber/SubtaskTimeTrackingSubscriber.php | 8 | ||||
-rw-r--r-- | app/Subscriber/TaskMovedDateSubscriber.php | 25 | ||||
-rw-r--r-- | app/Subscriber/TransitionSubscriber.php | 6 |
10 files changed, 217 insertions, 85 deletions
diff --git a/app/Subscriber/AuthSubscriber.php b/app/Subscriber/AuthSubscriber.php index 2461b52c..e839385f 100644 --- a/app/Subscriber/AuthSubscriber.php +++ b/app/Subscriber/AuthSubscriber.php @@ -2,26 +2,105 @@ namespace Kanboard\Subscriber; -use Kanboard\Core\Request; -use Kanboard\Event\AuthEvent; use Symfony\Component\EventDispatcher\EventSubscriberInterface; +use Kanboard\Core\Security\AuthenticationManager; +use Kanboard\Core\Session\SessionManager; +use Kanboard\Event\AuthSuccessEvent; +use Kanboard\Event\AuthFailureEvent; -class AuthSubscriber extends \Kanboard\Core\Base implements EventSubscriberInterface +/** + * Authentication Subscriber + * + * @package subscriber + * @author Frederic Guillot + */ +class AuthSubscriber extends BaseSubscriber implements EventSubscriberInterface { + /** + * Get event listeners + * + * @static + * @access public + * @return array + */ public static function getSubscribedEvents() { return array( - 'auth.success' => array('onSuccess', 0), + AuthenticationManager::EVENT_SUCCESS => 'afterLogin', + AuthenticationManager::EVENT_FAILURE => 'onLoginFailure', + SessionManager::EVENT_DESTROY => 'afterLogout', ); } - public function onSuccess(AuthEvent $event) + /** + * After Login callback + * + * @access public + * @param AuthSuccessEvent $event + */ + public function afterLogin(AuthSuccessEvent $event) { + $this->logger->debug('Subscriber executed: '.__METHOD__); + + $userAgent = $this->request->getUserAgent(); + $ipAddress = $this->request->getIpAddress(); + + $this->userLocking->resetFailedLogin($this->userSession->getUsername()); + $this->lastLogin->create( $event->getAuthType(), - $event->getUserId(), - Request::getIpAddress(), - Request::getUserAgent() + $this->userSession->getId(), + $ipAddress, + $userAgent ); + + if ($event->getAuthType() === 'RememberMe') { + $this->userSession->validatePostAuthentication(); + } + + if (isset($this->sessionStorage->hasRememberMe) && $this->sessionStorage->hasRememberMe) { + $session = $this->rememberMeSession->create($this->userSession->getId(), $ipAddress, $userAgent); + $this->rememberMeCookie->write($session['token'], $session['sequence'], $session['expiration']); + } + } + + /** + * Destroy RememberMe session on logout + * + * @access public + */ + public function afterLogout() + { + $this->logger->debug('Subscriber executed: '.__METHOD__); + $credentials = $this->rememberMeCookie->read(); + + if ($credentials !== false) { + $session = $this->rememberMeSession->find($credentials['token'], $credentials['sequence']); + + if (! empty($session)) { + $this->rememberMeSession->remove($session['id']); + } + + $this->rememberMeCookie->remove(); + } + } + + /** + * Increment failed login counter + * + * @access public + */ + public function onLoginFailure(AuthFailureEvent $event) + { + $this->logger->debug('Subscriber executed: '.__METHOD__); + $username = $event->getUsername(); + + if (! empty($username)) { + $this->userLocking->incrementFailedLogin($username); + + if ($this->userLocking->getFailedLogin($username) > BRUTEFORCE_LOCKDOWN) { + $this->userLocking->lock($username, BRUTEFORCE_LOCKDOWN_DURATION); + } + } } } diff --git a/app/Subscriber/BaseSubscriber.php b/app/Subscriber/BaseSubscriber.php new file mode 100644 index 00000000..2e41da76 --- /dev/null +++ b/app/Subscriber/BaseSubscriber.php @@ -0,0 +1,40 @@ +<?php + +namespace Kanboard\Subscriber; + +use Kanboard\Core\Base; + +/** + * Base class for subscribers + * + * @package subscriber + * @author Frederic Guillot + */ +class BaseSubscriber extends Base +{ + /** + * Method called + * + * @access private + * @var array + */ + private $called = array(); + + /** + * Check if a listener has been executed + * + * @access public + * @param string $key + * @return boolean + */ + public function isExecuted($key = '') + { + if (isset($this->called[$key])) { + return true; + } + + $this->called[$key] = true; + + return false; + } +} diff --git a/app/Subscriber/BootstrapSubscriber.php b/app/Subscriber/BootstrapSubscriber.php index 25b919f7..ef0215f3 100644 --- a/app/Subscriber/BootstrapSubscriber.php +++ b/app/Subscriber/BootstrapSubscriber.php @@ -4,20 +4,39 @@ namespace Kanboard\Subscriber; use Symfony\Component\EventDispatcher\EventSubscriberInterface; -class BootstrapSubscriber extends \Kanboard\Core\Base implements EventSubscriberInterface +class BootstrapSubscriber extends BaseSubscriber implements EventSubscriberInterface { public static function getSubscribedEvents() { return array( - 'session.bootstrap' => array('setup', 0), - 'api.bootstrap' => array('setup', 0), - 'console.bootstrap' => array('setup', 0), + 'app.bootstrap' => 'execute', ); } - public function setup() + public function execute() { + $this->logger->debug('Subscriber executed: '.__METHOD__); $this->config->setupTranslations(); $this->config->setupTimezone(); + $this->actionManager->attachEvents(); + + if ($this->userSession->isLogged()) { + $this->sessionStorage->hasSubtaskInProgress = $this->subtask->hasSubtaskInProgress($this->userSession->getId()); + } + } + + public function __destruct() + { + if (DEBUG) { + foreach ($this->db->getLogMessages() as $message) { + $this->logger->debug($message); + } + + $this->logger->debug('SQL_QUERIES={nb}', array('nb' => $this->container['db']->nbQueries)); + $this->logger->debug('RENDERING={time}', array('time' => microtime(true) - $this->request->getStartTime())); + $this->logger->debug('MEMORY='.$this->helper->text->bytes(memory_get_usage())); + $this->logger->debug('URI='.$this->request->getUri()); + $this->logger->debug('###############################################'); + } } } diff --git a/app/Subscriber/NotificationSubscriber.php b/app/Subscriber/NotificationSubscriber.php index 394573e4..651b8a96 100644 --- a/app/Subscriber/NotificationSubscriber.php +++ b/app/Subscriber/NotificationSubscriber.php @@ -6,37 +6,46 @@ use Kanboard\Event\GenericEvent; use Kanboard\Model\Task; use Kanboard\Model\Comment; use Kanboard\Model\Subtask; -use Kanboard\Model\File; +use Kanboard\Model\TaskFile; use Symfony\Component\EventDispatcher\EventSubscriberInterface; -class NotificationSubscriber extends \Kanboard\Core\Base implements EventSubscriberInterface +class NotificationSubscriber extends BaseSubscriber implements EventSubscriberInterface { public static function getSubscribedEvents() { return array( - Task::EVENT_CREATE => array('execute', 0), - Task::EVENT_UPDATE => array('execute', 0), - Task::EVENT_CLOSE => array('execute', 0), - Task::EVENT_OPEN => array('execute', 0), - Task::EVENT_MOVE_COLUMN => array('execute', 0), - Task::EVENT_MOVE_POSITION => array('execute', 0), - Task::EVENT_MOVE_SWIMLANE => array('execute', 0), - Task::EVENT_ASSIGNEE_CHANGE => array('execute', 0), - Subtask::EVENT_CREATE => array('execute', 0), - Subtask::EVENT_UPDATE => array('execute', 0), - Comment::EVENT_CREATE => array('execute', 0), - Comment::EVENT_UPDATE => array('execute', 0), - File::EVENT_CREATE => array('execute', 0), + Task::EVENT_USER_MENTION => 'handleEvent', + Task::EVENT_CREATE => 'handleEvent', + Task::EVENT_UPDATE => 'handleEvent', + Task::EVENT_CLOSE => 'handleEvent', + Task::EVENT_OPEN => 'handleEvent', + Task::EVENT_MOVE_COLUMN => 'handleEvent', + Task::EVENT_MOVE_POSITION => 'handleEvent', + Task::EVENT_MOVE_SWIMLANE => 'handleEvent', + Task::EVENT_ASSIGNEE_CHANGE => 'handleEvent', + Subtask::EVENT_CREATE => 'handleEvent', + Subtask::EVENT_UPDATE => 'handleEvent', + Comment::EVENT_CREATE => 'handleEvent', + Comment::EVENT_UPDATE => 'handleEvent', + Comment::EVENT_USER_MENTION => 'handleEvent', + TaskFile::EVENT_CREATE => 'handleEvent', ); } - public function execute(GenericEvent $event, $event_name) + public function handleEvent(GenericEvent $event, $event_name) { - $event_data = $this->getEventData($event); + if (! $this->isExecuted($event_name)) { + $this->logger->debug('Subscriber executed: '.__METHOD__); + $event_data = $this->getEventData($event); - if (! empty($event_data)) { - $this->userNotification->sendNotifications($event_name, $event_data); - $this->projectNotification->sendNotifications($event_data['task']['project_id'], $event_name, $event_data); + if (! empty($event_data)) { + if (! empty($event['mention'])) { + $this->userNotification->sendUserNotification($event['mention'], $event_name, $event_data); + } else { + $this->userNotification->sendNotifications($event_name, $event_data); + $this->projectNotification->sendNotifications($event_data['task']['project_id'], $event_name, $event_data); + } + } } } diff --git a/app/Subscriber/ProjectDailySummarySubscriber.php b/app/Subscriber/ProjectDailySummarySubscriber.php index bfa6cd42..44138f43 100644 --- a/app/Subscriber/ProjectDailySummarySubscriber.php +++ b/app/Subscriber/ProjectDailySummarySubscriber.php @@ -6,22 +6,23 @@ use Kanboard\Event\TaskEvent; use Kanboard\Model\Task; use Symfony\Component\EventDispatcher\EventSubscriberInterface; -class ProjectDailySummarySubscriber extends \Kanboard\Core\Base implements EventSubscriberInterface +class ProjectDailySummarySubscriber extends BaseSubscriber implements EventSubscriberInterface { public static function getSubscribedEvents() { return array( - Task::EVENT_CREATE => array('execute', 0), - Task::EVENT_UPDATE => array('execute', 0), - Task::EVENT_CLOSE => array('execute', 0), - Task::EVENT_OPEN => array('execute', 0), - Task::EVENT_MOVE_COLUMN => array('execute', 0), + Task::EVENT_CREATE_UPDATE => 'execute', + Task::EVENT_CLOSE => 'execute', + Task::EVENT_OPEN => 'execute', + Task::EVENT_MOVE_COLUMN => 'execute', + Task::EVENT_MOVE_SWIMLANE => 'execute', ); } public function execute(TaskEvent $event) { - if (isset($event['project_id'])) { + if (isset($event['project_id']) && !$this->isExecuted()) { + $this->logger->debug('Subscriber executed: '.__METHOD__); $this->projectDailyColumnStats->updateTotals($event['project_id'], date('Y-m-d')); $this->projectDailyStats->updateTotals($event['project_id'], date('Y-m-d')); } diff --git a/app/Subscriber/ProjectModificationDateSubscriber.php b/app/Subscriber/ProjectModificationDateSubscriber.php index 1f99840d..62804a84 100644 --- a/app/Subscriber/ProjectModificationDateSubscriber.php +++ b/app/Subscriber/ProjectModificationDateSubscriber.php @@ -6,25 +6,26 @@ use Kanboard\Event\GenericEvent; use Kanboard\Model\Task; use Symfony\Component\EventDispatcher\EventSubscriberInterface; -class ProjectModificationDateSubscriber extends \Kanboard\Core\Base implements EventSubscriberInterface +class ProjectModificationDateSubscriber extends BaseSubscriber implements EventSubscriberInterface { public static function getSubscribedEvents() { return array( - Task::EVENT_CREATE_UPDATE => array('execute', 0), - Task::EVENT_CLOSE => array('execute', 0), - Task::EVENT_OPEN => array('execute', 0), - Task::EVENT_MOVE_SWIMLANE => array('execute', 0), - Task::EVENT_MOVE_COLUMN => array('execute', 0), - Task::EVENT_MOVE_POSITION => array('execute', 0), - Task::EVENT_MOVE_PROJECT => array('execute', 0), - Task::EVENT_ASSIGNEE_CHANGE => array('execute', 0), + Task::EVENT_CREATE_UPDATE => 'execute', + Task::EVENT_CLOSE => 'execute', + Task::EVENT_OPEN => 'execute', + Task::EVENT_MOVE_SWIMLANE => 'execute', + Task::EVENT_MOVE_COLUMN => 'execute', + Task::EVENT_MOVE_POSITION => 'execute', + Task::EVENT_MOVE_PROJECT => 'execute', + Task::EVENT_ASSIGNEE_CHANGE => 'execute', ); } public function execute(GenericEvent $event) { - if (isset($event['project_id'])) { + if (isset($event['project_id']) && !$this->isExecuted()) { + $this->logger->debug('Subscriber executed: '.__METHOD__); $this->project->updateModificationDate($event['project_id']); } } diff --git a/app/Subscriber/RecurringTaskSubscriber.php b/app/Subscriber/RecurringTaskSubscriber.php index b03ffcf8..09a5665a 100644 --- a/app/Subscriber/RecurringTaskSubscriber.php +++ b/app/Subscriber/RecurringTaskSubscriber.php @@ -6,22 +6,24 @@ use Kanboard\Event\TaskEvent; use Kanboard\Model\Task; use Symfony\Component\EventDispatcher\EventSubscriberInterface; -class RecurringTaskSubscriber extends \Kanboard\Core\Base implements EventSubscriberInterface +class RecurringTaskSubscriber extends BaseSubscriber implements EventSubscriberInterface { public static function getSubscribedEvents() { return array( - Task::EVENT_MOVE_COLUMN => array('onMove', 0), - Task::EVENT_CLOSE => array('onClose', 0), + Task::EVENT_MOVE_COLUMN => 'onMove', + Task::EVENT_CLOSE => 'onClose', ); } public function onMove(TaskEvent $event) { + $this->logger->debug('Subscriber executed: '.__METHOD__); + if ($event['recurrence_status'] == Task::RECURRING_STATUS_PENDING) { - if ($event['recurrence_trigger'] == Task::RECURRING_TRIGGER_FIRST_COLUMN && $this->board->getFirstColumn($event['project_id']) == $event['src_column_id']) { + if ($event['recurrence_trigger'] == Task::RECURRING_TRIGGER_FIRST_COLUMN && $this->column->getFirstColumnId($event['project_id']) == $event['src_column_id']) { $this->taskDuplication->duplicateRecurringTask($event['task_id']); - } elseif ($event['recurrence_trigger'] == Task::RECURRING_TRIGGER_LAST_COLUMN && $this->board->getLastColumn($event['project_id']) == $event['dst_column_id']) { + } elseif ($event['recurrence_trigger'] == Task::RECURRING_TRIGGER_LAST_COLUMN && $this->column->getLastColumnId($event['project_id']) == $event['dst_column_id']) { $this->taskDuplication->duplicateRecurringTask($event['task_id']); } } @@ -29,6 +31,8 @@ class RecurringTaskSubscriber extends \Kanboard\Core\Base implements EventSubscr public function onClose(TaskEvent $event) { + $this->logger->debug('Subscriber executed: '.__METHOD__); + if ($event['recurrence_status'] == Task::RECURRING_STATUS_PENDING && $event['recurrence_trigger'] == Task::RECURRING_TRIGGER_CLOSE) { $this->taskDuplication->duplicateRecurringTask($event['task_id']); } diff --git a/app/Subscriber/SubtaskTimeTrackingSubscriber.php b/app/Subscriber/SubtaskTimeTrackingSubscriber.php index b5e0354d..c0852bc8 100644 --- a/app/Subscriber/SubtaskTimeTrackingSubscriber.php +++ b/app/Subscriber/SubtaskTimeTrackingSubscriber.php @@ -6,13 +6,13 @@ use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Kanboard\Model\Subtask; use Kanboard\Event\SubtaskEvent; -class SubtaskTimeTrackingSubscriber extends \Kanboard\Core\Base implements EventSubscriberInterface +class SubtaskTimeTrackingSubscriber extends BaseSubscriber implements EventSubscriberInterface { public static function getSubscribedEvents() { return array( - Subtask::EVENT_CREATE => array('updateTaskTime', 0), - Subtask::EVENT_DELETE => array('updateTaskTime', 0), + Subtask::EVENT_CREATE => 'updateTaskTime', + Subtask::EVENT_DELETE => 'updateTaskTime', Subtask::EVENT_UPDATE => array( array('logStartEnd', 10), array('updateTaskTime', 0), @@ -23,6 +23,7 @@ class SubtaskTimeTrackingSubscriber extends \Kanboard\Core\Base implements Event public function updateTaskTime(SubtaskEvent $event) { if (isset($event['task_id'])) { + $this->logger->debug('Subscriber executed: '.__METHOD__); $this->subtaskTimeTracking->updateTaskTimeTracking($event['task_id']); } } @@ -30,6 +31,7 @@ class SubtaskTimeTrackingSubscriber extends \Kanboard\Core\Base implements Event public function logStartEnd(SubtaskEvent $event) { if (isset($event['status']) && $this->config->get('subtask_time_tracking') == 1) { + $this->logger->debug('Subscriber executed: '.__METHOD__); $subtask = $this->subtask->getById($event['id']); if (empty($subtask['user_id'])) { diff --git a/app/Subscriber/TaskMovedDateSubscriber.php b/app/Subscriber/TaskMovedDateSubscriber.php deleted file mode 100644 index 9857f4b3..00000000 --- a/app/Subscriber/TaskMovedDateSubscriber.php +++ /dev/null @@ -1,25 +0,0 @@ -<?php - -namespace Kanboard\Subscriber; - -use Kanboard\Event\TaskEvent; -use Kanboard\Model\Task; -use Symfony\Component\EventDispatcher\EventSubscriberInterface; - -class TaskMovedDateSubscriber extends \Kanboard\Core\Base implements EventSubscriberInterface -{ - public static function getSubscribedEvents() - { - return array( - Task::EVENT_MOVE_COLUMN => array('execute', 0), - Task::EVENT_MOVE_SWIMLANE => array('execute', 0), - ); - } - - public function execute(TaskEvent $event) - { - if (isset($event['task_id'])) { - $this->container['db']->table(Task::TABLE)->eq('id', $event['task_id'])->update(array('date_moved' => time())); - } - } -} diff --git a/app/Subscriber/TransitionSubscriber.php b/app/Subscriber/TransitionSubscriber.php index 35352dc7..bd537484 100644 --- a/app/Subscriber/TransitionSubscriber.php +++ b/app/Subscriber/TransitionSubscriber.php @@ -6,17 +6,19 @@ use Kanboard\Event\TaskEvent; use Kanboard\Model\Task; use Symfony\Component\EventDispatcher\EventSubscriberInterface; -class TransitionSubscriber extends \Kanboard\Core\Base implements EventSubscriberInterface +class TransitionSubscriber extends BaseSubscriber implements EventSubscriberInterface { public static function getSubscribedEvents() { return array( - Task::EVENT_MOVE_COLUMN => array('execute', 0), + Task::EVENT_MOVE_COLUMN => 'execute', ); } public function execute(TaskEvent $event) { + $this->logger->debug('Subscriber executed: '.__METHOD__); + $user_id = $this->userSession->getId(); if (! empty($user_id)) { |