Browse Source

Merge pull request #32620 from nextcloud/bugfix/noid/reset-status-on-clearAt

Also reset the status on clearAt
pull/32537/head
Joas Schilling 3 years ago
committed by GitHub
parent
commit
57c686e124
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      apps/user_status/lib/BackgroundJob/ClearOldStatusesBackgroundJob.php
  2. 4
      apps/user_status/lib/Controller/UserStatusController.php
  3. 8
      apps/user_status/lib/Db/UserStatusMapper.php
  4. 7
      apps/user_status/lib/Service/StatusService.php
  5. 2
      apps/user_status/src/components/ClearAtSelect.vue
  6. 2
      apps/user_status/tests/Unit/BackgroundJob/ClearOldStatusesBackgroundJobTest.php
  7. 3
      apps/user_status/tests/Unit/Controller/UserStatusControllerTest.php
  8. 17
      apps/user_status/tests/Unit/Db/UserStatusMapperTest.php
  9. 4
      dist/user-status-modal-8299.js
  10. 2
      dist/user-status-modal-8299.js.map
  11. 4
      dist/user_status-menu.js
  12. 2
      dist/user_status-menu.js.map

2
apps/user_status/lib/BackgroundJob/ClearOldStatusesBackgroundJob.php

@ -61,7 +61,7 @@ class ClearOldStatusesBackgroundJob extends TimedJob {
protected function run($argument) {
$now = $this->time->getTime();
$this->mapper->clearMessagesOlderThan($now);
$this->mapper->clearOlderThanClearAt($now);
$this->mapper->clearStatusesOlderThan($now - StatusService::INVALIDATE_STATUS_THRESHOLD, $now);
}
}

4
apps/user_status/lib/Controller/UserStatusController.php

@ -135,7 +135,7 @@ class UserStatusController extends OCSController {
* @NoAdminRequired
*
* @param string|null $statusIcon
* @param string $message
* @param string|null $message
* @param int|null $clearAt
* @return DataResponse
* @throws OCSBadRequestException
@ -144,7 +144,7 @@ class UserStatusController extends OCSController {
?string $message,
?int $clearAt): DataResponse {
try {
if ($message !== null && $message !== '') {
if (($message !== null && $message !== '') || ($clearAt !== null && $clearAt !== 0)) {
$status = $this->service->setCustomMessage($this->userId, $statusIcon, $message, $clearAt);
} else {
$this->service->clearMessage($this->userId);

8
apps/user_status/lib/Db/UserStatusMapper.php

@ -145,13 +145,9 @@ class UserStatusMapper extends QBMapper {
*
* @param int $timestamp
*/
public function clearMessagesOlderThan(int $timestamp): void {
public function clearOlderThanClearAt(int $timestamp): void {
$qb = $this->db->getQueryBuilder();
$qb->update($this->tableName)
->set('message_id', $qb->createNamedParameter(null))
->set('custom_icon', $qb->createNamedParameter(null))
->set('custom_message', $qb->createNamedParameter(null))
->set('clear_at', $qb->createNamedParameter(null))
$qb->delete($this->tableName)
->where($qb->expr()->isNotNull('clear_at'))
->andWhere($qb->expr()->lte('clear_at', $qb->createNamedParameter($timestamp, IQueryBuilder::PARAM_INT)));

7
apps/user_status/lib/Service/StatusService.php

@ -302,7 +302,7 @@ class StatusService {
/**
* @param string $userId
* @param string|null $statusIcon
* @param string $message
* @param string|null $message
* @param int|null $clearAt
* @return UserStatus
* @throws InvalidClearAtException
@ -311,7 +311,7 @@ class StatusService {
*/
public function setCustomMessage(string $userId,
?string $statusIcon,
string $message,
?string $message,
?int $clearAt): UserStatus {
try {
$userStatus = $this->mapper->findByUserId($userId);
@ -328,7 +328,7 @@ class StatusService {
throw new InvalidStatusIconException('Status-Icon is longer than one character');
}
// Check for maximum length of custom message
if (\mb_strlen($message) > self::MAXIMUM_MESSAGE_LENGTH) {
if ($message !== null && \mb_strlen($message) > self::MAXIMUM_MESSAGE_LENGTH) {
throw new StatusMessageTooLongException('Message is longer than supported length of ' . self::MAXIMUM_MESSAGE_LENGTH . ' characters');
}
// Check that clearAt is in the future
@ -432,6 +432,7 @@ class StatusService {
$this->cleanStatus($status);
}
if ($clearAt !== null && $clearAt < $this->timeFactory->getTime()) {
$this->cleanStatus($status);
$this->cleanStatusMessage($status);
}
if ($status->getMessageId() !== null) {

2
apps/user_status/src/components/ClearAtSelect.vue

@ -22,7 +22,7 @@
<template>
<div class="clear-at-select">
<span class="clear-at-select__label">
{{ $t('user_status', 'Clear status message after') }}
{{ $t('user_status', 'Clear status after') }}
</span>
<Multiselect label="label"
:value="option"

2
apps/user_status/tests/Unit/BackgroundJob/ClearOldStatusesBackgroundJobTest.php

@ -53,7 +53,7 @@ class ClearOldStatusesBackgroundJobTest extends TestCase {
public function testRun() {
$this->mapper->expects($this->once())
->method('clearMessagesOlderThan')
->method('clearOlderThanClearAt')
->with(1337);
$this->mapper->expects($this->once())
->method('clearStatusesOlderThan')

3
apps/user_status/tests/Unit/Controller/UserStatusControllerTest.php

@ -315,7 +315,8 @@ class UserStatusControllerTest extends TestCase {
public function setCustomMessageDataProvider(): array {
return [
['👨🏽‍💻', 'Busy developing the status feature', 500, true, false, null, false, null],
['👨🏽‍💻', '', 500, true, false, null, false, null, true],
['👨🏽‍💻', '', 500, true, false, null, false, null, false],
['👨🏽‍💻', '', 0, true, false, null, false, null, true],
['👨🏽‍💻', 'Busy developing the status feature', 500, false, true, new InvalidClearAtException('Original exception message'), true,
'New user-status for "john.doe" was rejected due to an invalid clearAt value "500"'],
['👨🏽‍💻', 'Busy developing the status feature', 500, false, true, new InvalidStatusIconException('Original exception message'), true,

17
apps/user_status/tests/Unit/Db/UserStatusMapperTest.php

@ -28,6 +28,7 @@ namespace OCA\UserStatus\Tests\Db;
use OCA\UserStatus\Db\UserStatus;
use OCA\UserStatus\Db\UserStatusMapper;
use OCP\AppFramework\Db\DoesNotExistException;
use OCP\DB\Exception;
use Test\TestCase;
@ -204,22 +205,16 @@ class UserStatusMapperTest extends TestCase {
];
}
public function testClearMessagesOlderThan(): void {
public function testClearOlderThanClearAt(): void {
$this->insertSampleStatuses();
$this->mapper->clearMessagesOlderThan(55000);
$this->mapper->clearOlderThanClearAt(55000);
$allStatuses = $this->mapper->findAll();
$this->assertCount(3, $allStatuses);
$this->assertCount(2, $allStatuses);
$user1Status = $this->mapper->findByUserId('user1');
$this->assertEquals('user1', $user1Status->getUserId());
$this->assertEquals('dnd', $user1Status->getStatus());
$this->assertEquals(5000, $user1Status->getStatusTimestamp());
$this->assertEquals(true, $user1Status->getIsUserDefined());
$this->assertEquals(null, $user1Status->getCustomIcon());
$this->assertEquals(null, $user1Status->getCustomMessage());
$this->assertEquals(null, $user1Status->getClearAt());
$this->expectException(DoesNotExistException::class);
$this->mapper->findByUserId('user1');
}
private function insertSampleStatuses(): void {

4
dist/user-status-modal-8299.js
File diff suppressed because it is too large
View File

2
dist/user-status-modal-8299.js.map
File diff suppressed because it is too large
View File

4
dist/user_status-menu.js
File diff suppressed because it is too large
View File

2
dist/user_status-menu.js.map
File diff suppressed because it is too large
View File

Loading…
Cancel
Save