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));
}
/**
* @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

View file

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

View file

@ -36,7 +36,7 @@ class NoteApiControllerTest extends TestCase
$this->equalTo($this->userId))
->will($this->returnValue($note));
$result = $this->controller->update(3, 'title', 'content');
$result = $this->controller->update(3);
$this->assertEquals($note, $result->getData());
}
@ -49,7 +49,7 @@ class NoteApiControllerTest extends TestCase
->method('update')
->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());
}