Esempio n. 1
0
 /**
  * @param $type
  * @param $message
  * @return null
  */
 public function send($type, $message)
 {
     if (false === $this->isFiltered($type)) {
         $options = ['in_logger' => true];
         $this->slackFacade->multiSendMessage($this->channels, '```' . substr($message, 0, 3000) . '```', $options);
     }
 }
Esempio n. 2
0
 /**
  * @param $recipientsString
  * @return array
  */
 public function parseRecipients($recipientsString)
 {
     $recipients = preg_split('/\\s*,\\s*/', $recipientsString);
     $recipientIds = [];
     if (0 === count($recipients)) {
         return $recipientIds;
     }
     foreach ($recipients as $recipient) {
         if ($recipient !== null) {
             $recipientIds[] = $this->slackFacade->getRecipientIdByName($recipient);
         }
     }
     return $recipientIds;
 }
Esempio n. 3
0
 /**
  * @param RequestDto $dto
  * @param $commandHandler
  * @return bool
  */
 protected function checkAccess(RequestDto $dto, CommandHandlerInterface $commandHandler)
 {
     /** @var Config $config */
     $config = Registry::get('container')['config'];
     $acl = $commandHandler->getAcl();
     if (CommandHandlerInterface::ACL_ANY === $acl) {
         return true;
     } elseif (CommandHandlerInterface::ACL_ADMIN === $acl) {
         $currentUser = $dto->getUser();
         $currentUserName = $this->slackFacade->getUserNameById($currentUser);
         $admins = $config->getEntry('acl.admins') ?: [];
         if (0 === count($admins)) {
             return false;
         }
         return in_array($currentUserName, $admins);
     } else {
         if (!is_array($acl)) {
             throw new \RuntimeException('Wrong ACL format: array expected');
         }
         $currentUser = $dto->getUser();
         $aclUsers = [];
         foreach ($acl as $aclItem) {
             $aclUsers = array_merge($aclUsers, $this->slackFacade->getRecipientUsersIds($aclItem));
         }
         $aclUsers = array_unique($aclUsers);
         return in_array($currentUser, $aclUsers);
     }
 }
 /** @test */
 public function shouldNotGetRecipientUsersIdsForArrayEntityName()
 {
     $slackApiMock = \Mockery::mock('\\slackbot\\models\\SlackApi');
     $slackFacade = new SlackFacade($slackApiMock);
     $result = $slackFacade->getRecipientUsersIds(['@user', '#general']);
     $this->assertEquals([], $result);
 }