inform sender if card was not created.

pull/16/head
Alex Puiu 2022-02-08 13:34:16 +02:00
rodzic 698c513b8b
commit 8d42b8c6d3
4 zmienionych plików z 44 dodań i 22 usunięć

Wyświetl plik

@ -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: <code>bot@ncserver.com</code> * In this tutorial email address for Deck Bot will be: <code>bot@ncserver.com</code>
## 1) Assign Deck Bot to the board. ## 1) Assign Deck Bot to the board.
Deck Bot must be assigned and must have edit permission inside the board.
## 2) Mail subject & content ## 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". 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. You can do this in two ways.

Wyświetl plik

@ -79,8 +79,7 @@ if ($emails)
$newcard = new DeckClass(); $newcard = new DeckClass();
$response = $newcard->addCard($data, $mailSender, $board); $response = $newcard->addCard($data, $mailSender, $board);
$mailSender->userId .= "@{$overview->from[0]->host}"; $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);
}
} }
?> ?>

Wyświetl plik

@ -49,6 +49,9 @@ class DeckClass {
$boards = $this->apiCall("GET", NC_SERVER . "/index.php/apps/deck/api/v1.0/boards"); $boards = $this->apiCall("GET", NC_SERVER . "/index.php/apps/deck/api/v1.0/boards");
foreach($boards as $board) { foreach($boards as $board) {
if(strtolower($board->title) == strtolower($boardFromMail)) { if(strtolower($board->title) == strtolower($boardFromMail)) {
if(!$this->checkBotPermissions($board)) {
return false;
}
$boardId = $board->id; $boardId = $board->id;
$boardName = $board->title; $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"); $stacks = $this->apiCall("GET", NC_SERVER . "/index.php/apps/deck/api/v1.0/boards/$boardId/stacks");
foreach($stacks as $stack) foreach($stacks as $stack)
(strtolower($stack->title) == strtolower($stackFromMail)) ? $stackId = $stack->id : $stackId = $stacks[0]->id; (strtolower($stack->title) == strtolower($stackFromMail)) ? $stackId = $stack->id : $stackId = $stacks[0]->id;
} else {
return false;
} }
$boardStack = new stdClass(); $boardStack = new stdClass();
@ -71,20 +76,23 @@ class DeckClass {
public function addCard($data, $user, $board = null) { public function addCard($data, $user, $board = null) {
$params = $this->getParameters($data->title, $board); $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($params) {
if(ASSIGN_SENDER) $this->assignUser($card, $user); $data->title = $params->newTitle;
if($data->attachments) $this->addAttachments($card, $data->attachments); $card = $this->apiCall("POST", NC_SERVER . "/index.php/apps/deck/api/v1.0/boards/{$params->board}/stacks/{$params->stack}/cards", $data);
$card->boardTitle = $params->boardTitle; $card->board = $params->board;
} else { $card->stack = $params->stack;
return false;
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 false;
return $card;
} }
private function addAttachments($card, $attachments) { 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;
}
} }
?> ?>

Wyświetl plik

@ -30,7 +30,7 @@ class MailClass {
return imap_headerinfo($this->inbox, $email); return imap_headerinfo($this->inbox, $email);
} }
public function reply($sender, $response) { public function reply($sender, $response = null) {
$serverName = parse_url(NC_SERVER); $serverName = parse_url(NC_SERVER);
$headers = array( $headers = array(
@ -39,14 +39,19 @@ class MailClass {
'Content-Type' => 'text/html' 'Content-Type' => 'text/html'
); );
if($response) {
$body = "<h1>You created a new issue on board {$response->boardTitle}.</h1><p>Check out this <a href=\"" . NC_SERVER . "/index.php/apps/deck/#/board/{$response->board}/card/{$response->id}" . "\">link</a> to see your newly created card.</p>";
$subject = 'An issue has been reported!';
} else {
$body = "<h1>There was a problem creating your new card.</h1><p>Make sure you set up the board correctly.</p>";
$subject = "Your issue has not been reported!";
}
$message = "<html>"; $message = "<html>";
$message .= "<head><title>You created a new issue on board {$response->boardTitle}.</title></head>"; $message .= "<head><title>Mail2Deck response</title></head>";
$message .= "<body>"; $message .= "<body>$body</body>";
$message .= "<h1>You created a new issue on board {$response->boardTitle}.</h1>";
$message .= "<p>Check out this <a href=\"" . NC_SERVER . "/index.php/apps/deck/#/board/{$response->board}/card/{$response->id}" . "\">link</a> to see your newly created card.</p>";
$message .= "</body>";
$message .= "</html>"; $message .= "</html>";
mail($sender, 'An issue has been reported!', $message, $headers); mail($sender, $subject, $message, $headers);
} }
} }