Add helper name attribute in matrix room state

This commit is contained in:
Ben 2021-10-10 19:49:36 +02:00
parent f13c054aef
commit 2107a6f8e6
Signed by: ben
GPG key ID: 0F54A7ED232D3319
3 changed files with 23 additions and 14 deletions

View file

@ -51,14 +51,12 @@ class TicketApiController extends ApiController
return new DataResponse($this->service->create($title, $content, $this->userId)); return new DataResponse($this->service->create($title, $content, $this->userId));
} }
/** /**
* @NoAdminRequired * @NoAdminRequired
*/ */
public function update(): DataResponse public function update(int $id): DataResponse
{ {
return new DataResponse($this->service->assign(44,$this->userId)); return new DataResponse($this->service->assign($id, $this->userId));
} }
public function destroy(int $id): DataResponse public function destroy(int $id): DataResponse

View file

@ -14,9 +14,13 @@ use OCA\UPschooling\Exceptions\RoomNotFoundException;
use OCA\UPschooling\Exceptions\TicketNotFoundException; use OCA\UPschooling\Exceptions\TicketNotFoundException;
use OCP\AppFramework\Db\DoesNotExistException; use OCP\AppFramework\Db\DoesNotExistException;
use OCP\AppFramework\Db\MultipleObjectsReturnedException; use OCP\AppFramework\Db\MultipleObjectsReturnedException;
use OCP\IUserManager;
class TicketService { class TicketService {
/** @var IUserManager $userManager */
private $userManager;
/** @var MatrixService */ /** @var MatrixService */
private $matrix; private $matrix;
@ -26,7 +30,13 @@ class TicketService {
/** @var UserMapper */ /** @var UserMapper */
private $userMapper; private $userMapper;
public function __construct(MatrixService $matrix, TicketMapper $ticketMapper, UserMapper $userMapper) { public function __construct(
IUserManager $userManager,
MatrixService $matrix,
TicketMapper $ticketMapper,
UserMapper $userMapper
) {
$this->userManager = $userManager;
$this->matrix = $matrix; $this->matrix = $matrix;
$this->ticketMapper = $ticketMapper; $this->ticketMapper = $ticketMapper;
$this->userMapper = $userMapper; $this->userMapper = $userMapper;
@ -72,14 +82,14 @@ class TicketService {
return $this->resolveTicket($this->ticketMapper->insert($ticket)); return $this->resolveTicket($this->ticketMapper->insert($ticket));
} }
public function assign($id, $userId): array{ public function assign($id, $userId): array{
$matrixUser = $this->getOrCreateUser($userId); $matrixUser = $this->getOrCreateUser($userId);
$ticket = $this->ticketMapper->findTicket($id); $ticket = $this->ticketMapper->findTicket($id);
$roomID = $ticket->getMatrixRoom(); $roomID = $ticket->getMatrixRoom();
$helperName = $this->userManager->get($userId)->getDisplayName();
$this->matrix->setProperty($roomID, "upschooling.ticket", array( $this->matrix->setProperty($roomID, "upschooling.ticket", array(
"matrixHelperUser" => $matrixUser->getMatrixUser() "matrixHelperUser" => $matrixUser->getMatrixUser(),
"matrixHelperName" => $helperName,
)); ));
$ticket->setMatrixHelperUser($matrixUser->getMatrixUser()); $ticket->setMatrixHelperUser($matrixUser->getMatrixUser());
return $this->resolveTicket($this->ticketMapper->update($ticket)); return $this->resolveTicket($this->ticketMapper->update($ticket));
@ -107,14 +117,15 @@ class TicketService {
$description = array_get($matrixTicketContent, "description", ""); $description = array_get($matrixTicketContent, "description", "");
$lastModified = $this->matrix->getLastEventDate($ticket->getMatrixRoom()); $lastModified = $this->matrix->getLastEventDate($ticket->getMatrixRoom());
$matrixHelperUser = array_get($matrixTicketContent, "matrixHelperUser", "nicht zugewiesen"); $matrixHelperUser = array_get($matrixTicketContent, "matrixHelperUser", "nicht zugewiesen");
$expirationDate = array_get($matrixTicketContent, "expiration date", ""); $matrixHelperName = array_get($matrixTicketContent, "matrixHelperName", $matrixHelperUser);
$expirationDate = array_get($matrixTicketContent, "expirationDate", "");
return array( return array(
'ticketId' => $ticketId, 'ticketId' => $ticketId,
'status' => $ticket->getStatus(), 'status' => $ticket->getStatus(),
'lastModified' => $lastModified, 'lastModified' => $lastModified,
'title' => $title, 'title' => $title,
'description' => $description, 'description' => $description,
'matrixHelperUser' => $matrixHelperUser, 'matrixHelperName' => $matrixHelperName,
'expirationDate' => $expirationDate 'expirationDate' => $expirationDate
); );
} catch (MatrixException | RoomNotFoundException $e) { } catch (MatrixException | RoomNotFoundException $e) {

View file

@ -36,7 +36,7 @@ class NoteApiControllerTest extends TestCase
$this->equalTo($this->userId)) $this->equalTo($this->userId))
->will($this->returnValue($note)); ->will($this->returnValue($note));
$result = $this->controller->update(3, 'title', 'content'); $result = $this->controller->update(3);
$this->assertEquals($note, $result->getData()); $this->assertEquals($note, $result->getData());
} }
@ -49,7 +49,7 @@ class NoteApiControllerTest extends TestCase
->method('update') ->method('update')
->will($this->throwException(new NoteNotFound())); ->will($this->throwException(new NoteNotFound()));
$result = $this->controller->update(3, 'title', 'content'); $result = $this->controller->update(3);
$this->assertEquals(Http::STATUS_NOT_FOUND, $result->getStatus()); $this->assertEquals(Http::STATUS_NOT_FOUND, $result->getStatus());
} }