diff --git a/README.md b/README.md index dcce1bb..2e340d4 100644 --- a/README.md +++ b/README.md @@ -7,6 +7,8 @@ Follow the above steps to add a new card from email. * In this tutorial email address for Deck Bot will be: bot@ncserver.com ## 1) Assign Deck Bot to the board. +Deck Bot must be assigned and must have edit permission inside the board. + ## 2) Mail subject & content Let's assume you want to add a card with title "Update website logo" on board "Website" and stack "To do". You can do this in two ways. diff --git a/index.php b/index.php index 5c75eab..c2defc8 100644 --- a/index.php +++ b/index.php @@ -79,8 +79,7 @@ if ($emails) $newcard = new DeckClass(); $response = $newcard->addCard($data, $mailSender, $board); $mailSender->userId .= "@{$overview->from[0]->host}"; - if($response && ASSIGN_SENDER) { - $inbox->reply($mailSender->userId, $response); - } + + ($response) ? $inbox->reply($mailSender->userId, $response) : $inbox->reply($mailSender->userId); } ?> diff --git a/lib/DeckClass.php b/lib/DeckClass.php index 6d38f6a..6b148cd 100644 --- a/lib/DeckClass.php +++ b/lib/DeckClass.php @@ -49,6 +49,9 @@ class DeckClass { $boards = $this->apiCall("GET", NC_SERVER . "/index.php/apps/deck/api/v1.0/boards"); foreach($boards as $board) { if(strtolower($board->title) == strtolower($boardFromMail)) { + if(!$this->checkBotPermissions($board)) { + return false; + } $boardId = $board->id; $boardName = $board->title; } @@ -58,6 +61,8 @@ class DeckClass { $stacks = $this->apiCall("GET", NC_SERVER . "/index.php/apps/deck/api/v1.0/boards/$boardId/stacks"); foreach($stacks as $stack) (strtolower($stack->title) == strtolower($stackFromMail)) ? $stackId = $stack->id : $stackId = $stacks[0]->id; + } else { + return false; } $boardStack = new stdClass(); @@ -71,20 +76,23 @@ class DeckClass { public function addCard($data, $user, $board = null) { $params = $this->getParameters($data->title, $board); - $data->title = $params->newTitle; - $card = $this->apiCall("POST", NC_SERVER . "/index.php/apps/deck/api/v1.0/boards/{$params->board}/stacks/{$params->stack}/cards", $data); - $card->board = $params->board; - $card->stack = $params->stack; - if($this->responseCode == 200) { - if(ASSIGN_SENDER) $this->assignUser($card, $user); - if($data->attachments) $this->addAttachments($card, $data->attachments); - $card->boardTitle = $params->boardTitle; - } else { - return false; + if($params) { + $data->title = $params->newTitle; + $card = $this->apiCall("POST", NC_SERVER . "/index.php/apps/deck/api/v1.0/boards/{$params->board}/stacks/{$params->stack}/cards", $data); + $card->board = $params->board; + $card->stack = $params->stack; + + if($this->responseCode == 200) { + if(ASSIGN_SENDER) $this->assignUser($card, $user); + if($data->attachments) $this->addAttachments($card, $data->attachments); + $card->boardTitle = $params->boardTitle; + } else { + return false; + } + return $card; } - - return $card; + return false; } private function addAttachments($card, $attachments) { @@ -111,5 +119,13 @@ class DeckClass { } } } + + private function checkBotPermissions($board) { + foreach($board->acl as $acl) + if($acl->participant->uid == NC_USER && $acl->permissionEdit) + return true; + + return false; + } } ?> diff --git a/lib/MailClass.php b/lib/MailClass.php index 562fc3a..98e11e6 100644 --- a/lib/MailClass.php +++ b/lib/MailClass.php @@ -30,7 +30,7 @@ class MailClass { return imap_headerinfo($this->inbox, $email); } - public function reply($sender, $response) { + public function reply($sender, $response = null) { $serverName = parse_url(NC_SERVER); $headers = array( @@ -39,14 +39,19 @@ class MailClass { 'Content-Type' => 'text/html' ); + if($response) { + $body = "

You created a new issue on board {$response->boardTitle}.

Check out this board}/card/{$response->id}" . "\">link to see your newly created card.

"; + $subject = 'An issue has been reported!'; + } else { + $body = "

There was a problem creating your new card.

Make sure you set up the board correctly.

"; + $subject = "Your issue has not been reported!"; + } + $message = ""; - $message .= "You created a new issue on board {$response->boardTitle}."; - $message .= ""; - $message .= "

You created a new issue on board {$response->boardTitle}.

"; - $message .= "

Check out this board}/card/{$response->id}" . "\">link to see your newly created card.

"; - $message .= ""; + $message .= "Mail2Deck response"; + $message .= "$body"; $message .= ""; - mail($sender, 'An issue has been reported!', $message, $headers); + mail($sender, $subject, $message, $headers); } }