Skip to content

Commit

Permalink
Merge branch 'bug/oauth-instance-name-decoding-39956' of github.com:b…
Browse files Browse the repository at this point in the history
…yt3sage/server into bug/oauth-instance-name-decoding-39956
  • Loading branch information
byt3sage committed Dec 13, 2024
2 parents 4cd8a48 + ce6e450 commit 7a9eb28
Show file tree
Hide file tree
Showing 526 changed files with 2,113 additions and 1,365 deletions.
1 change: 1 addition & 0 deletions apps/dashboard/lib/Controller/DashboardController.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ public function index(): TemplateResponse {
$this->initialState->provideInitialState('layout', $this->service->getLayout());
$this->initialState->provideInitialState('appStoreEnabled', $this->config->getSystemValueBool('appstoreenabled', true));
$this->initialState->provideInitialState('firstRun', $this->config->getUserValue($this->userId, 'dashboard', 'firstRun', '1') === '1');
$this->initialState->provideInitialState('birthdate', $this->service->getBirthdate());
$this->config->setUserValue($this->userId, 'dashboard', 'firstRun', '0');

$response = new TemplateResponse('dashboard', 'index', [
Expand Down
26 changes: 26 additions & 0 deletions apps/dashboard/lib/Service/DashboardService.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,17 @@
namespace OCA\Dashboard\Service;

use JsonException;
use OCP\Accounts\IAccountManager;
use OCP\Accounts\PropertyDoesNotExistException;
use OCP\IConfig;
use OCP\IUserManager;

class DashboardService {
public function __construct(
private IConfig $config,
private ?string $userId,
private IUserManager $userManager,
private IAccountManager $accountManager,
) {

}
Expand Down Expand Up @@ -42,4 +47,25 @@ public function getStatuses() {
return array_values(array_filter(explode(',', $configStatuses), fn (string $value) => $value !== ''));
}
}

public function getBirthdate(): string {
if ($this->userId === null) {
return '';
}

$user = $this->userManager->get($this->userId);
if ($user === null) {
return '';
}

$account = $this->accountManager->getAccount($user);

try {
$birthdate = $account->getProperty(IAccountManager::PROPERTY_BIRTHDATE);
} catch (PropertyDoesNotExistException) {
return '';
}

return $birthdate->getValue();
}
}
13 changes: 12 additions & 1 deletion apps/dashboard/src/DashboardApp.vue
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ import ApiDashboardWidget from './components/ApiDashboardWidget.vue'

const panels = loadState('dashboard', 'panels')
const firstRun = loadState('dashboard', 'firstRun')
const birthdate = new Date(loadState('dashboard', 'birthdate'))

const statusInfo = {
weather: {
Expand Down Expand Up @@ -194,15 +195,21 @@ export default {
apiWidgets: [],
apiWidgetItems: {},
loadingItems: true,
birthdate,
}
},
computed: {
greeting() {
const time = this.timer.getHours()
const isBirthday = this.birthdate instanceof Date
&& this.birthdate.getMonth() === this.timer.getMonth()
&& this.birthdate.getDate() === this.timer.getDate()

// Determine part of the day
let partOfDay
if (time >= 22 || time < 5) {
if (isBirthday) {
partOfDay = 'birthday'
} else if (time >= 22 || time < 5) {
partOfDay = 'night'
} else if (time >= 18) {
partOfDay = 'evening'
Expand Down Expand Up @@ -231,6 +238,10 @@ export default {
generic: t('dashboard', 'Hello'),
withName: t('dashboard', 'Hello, {name}', { name: this.displayName }, undefined, { escape: false }),
},
birthday: {
generic: t('dashboard', 'Happy birthday 🥳🤩🎂🎉'),
withName: t('dashboard', 'Happy birthday, {name} 🥳🤩🎂🎉', { name: this.displayName }, undefined, { escape: false }),
},
}

// Figure out which greeting to show
Expand Down
100 changes: 100 additions & 0 deletions apps/dashboard/tests/DashboardServiceTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
<?php

declare(strict_types=1);

/**
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

namespace OCA\Dashboard\Tests;

use OC\Accounts\Account;
use OCA\Dashboard\Service\DashboardService;
use OCP\Accounts\IAccountManager;
use OCP\IConfig;
use OCP\IUser;
use OCP\IUserManager;
use PHPUnit\Framework\MockObject\MockObject;
use Test\TestCase;

class DashboardServiceTest extends TestCase {

private IConfig&MockObject $config;
private IUserManager&MockObject $userManager;
private IAccountManager&MockObject $accountManager;
private DashboardService $service;

protected function setUp(): void {
parent::setUp();

$this->config = $this->createMock(IConfig::class);
$this->userManager = $this->createMock(IUserManager::class);
$this->accountManager = $this->createMock(IAccountManager::class);

$this->service = new DashboardService(
$this->config,
'alice',
$this->userManager,
$this->accountManager,
);
}

public function testGetBirthdate() {
$user = $this->createMock(IUser::class);
$this->userManager->method('get')
->willReturn($user);

$account = new Account($user);
$account->setProperty(
IAccountManager::PROPERTY_BIRTHDATE,
'2024-12-10T00:00:00.000Z',
IAccountManager::SCOPE_LOCAL,
IAccountManager::VERIFIED,
);

$this->accountManager->method('getAccount')
->willReturn($account);

$birthdate = $this->service->getBirthdate();

$this->assertEquals('2024-12-10T00:00:00.000Z', $birthdate);
}

public function testGetBirthdatePropertyDoesNotExist() {
$user = $this->createMock(IUser::class);
$this->userManager->method('get')
->willReturn($user);

$account = new Account($user);
$this->accountManager->method('getAccount')
->willReturn($account);

$birthdate = $this->service->getBirthdate();

$this->assertEquals('', $birthdate);
}

public function testGetBirthdateUserNotFound() {
$this->userManager->method('get')
->willReturn(null);

$birthdate = $this->service->getBirthdate();

$this->assertEquals('', $birthdate);
}

public function testGetBirthdateNoUserId() {
$service = new DashboardService(
$this->config,
null,
$this->userManager,
$this->accountManager,
);

$birthdate = $service->getBirthdate();

$this->assertEquals('', $birthdate);
}

}
2 changes: 1 addition & 1 deletion apps/dav/lib/Connector/Sabre/ServerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ public function createServer(string $baseUri,
));

if ($this->userSession->isLoggedIn()) {
$server->addPlugin(new TagsPlugin($objectTree, $this->tagManager));
$server->addPlugin(new TagsPlugin($objectTree, $this->tagManager, $this->eventDispatcher, $this->userSession));
$server->addPlugin(new SharesPlugin(
$objectTree,
$this->userSession,
Expand Down
6 changes: 5 additions & 1 deletion apps/dav/lib/Connector/Sabre/TagsPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,10 @@
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*
*/
use OCP\EventDispatcher\IEventDispatcher;
use OCP\ITagManager;
use OCP\ITags;
use OCP\IUserSession;
use Sabre\DAV\PropFind;
use Sabre\DAV\PropPatch;

Expand Down Expand Up @@ -67,6 +69,8 @@ class TagsPlugin extends \Sabre\DAV\ServerPlugin {
public function __construct(
private \Sabre\DAV\Tree $tree,
private ITagManager $tagManager,
private IEventDispatcher $eventDispatcher,
private IUserSession $userSession,
) {
$this->tagger = null;
$this->cachedTags = [];
Expand Down Expand Up @@ -251,7 +255,7 @@ public function handleUpdateProperties($path, PropPatch $propPatch) {
return true;
});

$propPatch->handle(self::FAVORITE_PROPERTYNAME, function ($favState) use ($node) {
$propPatch->handle(self::FAVORITE_PROPERTYNAME, function ($favState) use ($node, $path) {
if ((int)$favState === 1 || $favState === 'true') {
$this->getTagger()->tagAs($node->getId(), self::TAG_FAVORITE);
} else {
Expand Down
2 changes: 1 addition & 1 deletion apps/dav/lib/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ public function __construct(
}
$this->server->addPlugin(
new TagsPlugin(
$this->server->tree, \OC::$server->getTagManager()
$this->server->tree, \OC::$server->getTagManager(), \OC::$server->get(IEventDispatcher::class), \OC::$server->get(IUserSession::class)
)
);

Expand Down
28 changes: 27 additions & 1 deletion apps/dav/tests/unit/Connector/Sabre/TagsPluginTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,11 @@
use OCA\DAV\Connector\Sabre\TagList;
use OCA\DAV\Connector\Sabre\TagsPlugin;
use OCA\DAV\Upload\UploadFile;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\ITagManager;
use OCP\ITags;
use OCP\IUser;
use OCP\IUserSession;
use Sabre\DAV\Tree;

class TagsPluginTest extends \Test\TestCase {
Expand Down Expand Up @@ -42,6 +45,16 @@ class TagsPluginTest extends \Test\TestCase {
*/
private $tagger;

/**
* @var IEventDispatcher
*/
private $eventDispatcher;

/**
* @var IUserSession
*/
private $userSession;

/**
* @var TagsPlugin
*/
Expand All @@ -59,11 +72,24 @@ protected function setUp(): void {
$this->tagManager = $this->getMockBuilder(ITagManager::class)
->disableOriginalConstructor()
->getMock();

$this->eventDispatcher = $this->getMockBuilder(IEventDispatcher::class)
->disableOriginalConstructor()
->getMock();
$user = $this->createMock(IUser::class);
/**
* @var IUserSession
*/
$this->userSession = $this->createMock(IUserSession::class);
$this->userSession->expects($this->any())
->method('getUser')
->withAnyParameters()
->willReturn($user);
$this->tagManager->expects($this->any())
->method('load')
->with('files')
->willReturn($this->tagger);
$this->plugin = new TagsPlugin($this->tree, $this->tagManager);
$this->plugin = new TagsPlugin($this->tree, $this->tagManager, $this->eventDispatcher, $this->userSession);
$this->plugin->initialize($this->server);
}

Expand Down
2 changes: 2 additions & 0 deletions apps/files/composer/composer/autoload_classmap.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@
'OCA\\Files\\Helper' => $baseDir . '/../lib/Helper.php',
'OCA\\Files\\Listener\\LoadSearchPluginsListener' => $baseDir . '/../lib/Listener/LoadSearchPluginsListener.php',
'OCA\\Files\\Listener\\LoadSidebarListener' => $baseDir . '/../lib/Listener/LoadSidebarListener.php',
'OCA\\Files\\Listener\\NodeAddedToFavoriteListener' => $baseDir . '/../lib/Listener/NodeAddedToFavoriteListener.php',
'OCA\\Files\\Listener\\NodeRemovedFromFavoriteListener' => $baseDir . '/../lib/Listener/NodeRemovedFromFavoriteListener.php',
'OCA\\Files\\Listener\\RenderReferenceEventListener' => $baseDir . '/../lib/Listener/RenderReferenceEventListener.php',
'OCA\\Files\\Listener\\SyncLivePhotosListener' => $baseDir . '/../lib/Listener/SyncLivePhotosListener.php',
'OCA\\Files\\Migration\\Version11301Date20191205150729' => $baseDir . '/../lib/Migration/Version11301Date20191205150729.php',
Expand Down
2 changes: 2 additions & 0 deletions apps/files/composer/composer/autoload_static.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ class ComposerStaticInitFiles
'OCA\\Files\\Helper' => __DIR__ . '/..' . '/../lib/Helper.php',
'OCA\\Files\\Listener\\LoadSearchPluginsListener' => __DIR__ . '/..' . '/../lib/Listener/LoadSearchPluginsListener.php',
'OCA\\Files\\Listener\\LoadSidebarListener' => __DIR__ . '/..' . '/../lib/Listener/LoadSidebarListener.php',
'OCA\\Files\\Listener\\NodeAddedToFavoriteListener' => __DIR__ . '/..' . '/../lib/Listener/NodeAddedToFavoriteListener.php',
'OCA\\Files\\Listener\\NodeRemovedFromFavoriteListener' => __DIR__ . '/..' . '/../lib/Listener/NodeRemovedFromFavoriteListener.php',
'OCA\\Files\\Listener\\RenderReferenceEventListener' => __DIR__ . '/..' . '/../lib/Listener/RenderReferenceEventListener.php',
'OCA\\Files\\Listener\\SyncLivePhotosListener' => __DIR__ . '/..' . '/../lib/Listener/SyncLivePhotosListener.php',
'OCA\\Files\\Migration\\Version11301Date20191205150729' => __DIR__ . '/..' . '/../lib/Migration/Version11301Date20191205150729.php',
Expand Down
7 changes: 7 additions & 0 deletions apps/files/l10n/zh_CN.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ OC.L10N.register(
"\"{displayName}\" batch action executed successfully" : "批量操作“{displayName}”运行成功",
"{count} selected" : "已选中 {count}",
"List of files and folders." : "文件与文件夹列表。",
"You don’t have permission to upload or create files here." : "您无权在此处上传或创建文件。",
"You have used your space quota and cannot upload files anymore." : "您的剩余空间配额不足以继续上传文件。",
"Column headers with buttons are sortable." : "带有按钮的列标题可进行排序。",
"This list is not fully rendered for performance reasons. The files will be rendered as you navigate through the list." : "出于性能考虑,此列表未完全呈现。文件将在您浏览列表时呈现。",
"File not found" : "文件未找到",
Expand Down Expand Up @@ -264,6 +266,11 @@ OC.L10N.register(
"Files moved successfully" : "移动文件成功",
"Conflicts resolution skipped" : "已跳过冲突解决",
"Upload cancelled" : "已取消上传",
"Adding the file extension \"{new}\" may render the file unreadable." : "添加文件扩展名 \"{new}\" 可能会导致文件无法读取。",
"Removing the file extension \"{old}\" may render the file unreadable." : "删除文件扩展名 \"{old}\" 可能会导致文件无法读取。",
"Changing the file extension from \"{old}\" to \"{new}\" may render the file unreadable." : "将文件扩展名从 \"{old}\" 更改为 \"{new}\" 可能会导致文件无法读取。",
"Change file extension" : "更改文件扩展名",
"Remove extension" : "删除扩展",
"This operation is forbidden" : "该操作被禁止",
"This directory is unavailable, please check the logs or contact the administrator" : "此目录不可用,请检查日志或联系管理员",
"Storage is temporarily not available" : "存储空间暂时不可用",
Expand Down
7 changes: 7 additions & 0 deletions apps/files/l10n/zh_CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@
"\"{displayName}\" batch action executed successfully" : "批量操作“{displayName}”运行成功",
"{count} selected" : "已选中 {count}",
"List of files and folders." : "文件与文件夹列表。",
"You don’t have permission to upload or create files here." : "您无权在此处上传或创建文件。",
"You have used your space quota and cannot upload files anymore." : "您的剩余空间配额不足以继续上传文件。",
"Column headers with buttons are sortable." : "带有按钮的列标题可进行排序。",
"This list is not fully rendered for performance reasons. The files will be rendered as you navigate through the list." : "出于性能考虑,此列表未完全呈现。文件将在您浏览列表时呈现。",
"File not found" : "文件未找到",
Expand Down Expand Up @@ -262,6 +264,11 @@
"Files moved successfully" : "移动文件成功",
"Conflicts resolution skipped" : "已跳过冲突解决",
"Upload cancelled" : "已取消上传",
"Adding the file extension \"{new}\" may render the file unreadable." : "添加文件扩展名 \"{new}\" 可能会导致文件无法读取。",
"Removing the file extension \"{old}\" may render the file unreadable." : "删除文件扩展名 \"{old}\" 可能会导致文件无法读取。",
"Changing the file extension from \"{old}\" to \"{new}\" may render the file unreadable." : "将文件扩展名从 \"{old}\" 更改为 \"{new}\" 可能会导致文件无法读取。",
"Change file extension" : "更改文件扩展名",
"Remove extension" : "删除扩展",
"This operation is forbidden" : "该操作被禁止",
"This directory is unavailable, please check the logs or contact the administrator" : "此目录不可用,请检查日志或联系管理员",
"Storage is temporarily not available" : "存储空间暂时不可用",
Expand Down
9 changes: 6 additions & 3 deletions apps/files/lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
use OCA\Files\Event\LoadSidebar;
use OCA\Files\Listener\LoadSearchPluginsListener;
use OCA\Files\Listener\LoadSidebarListener;
use OCA\Files\Listener\NodeAddedToFavoriteListener;
use OCA\Files\Listener\NodeRemovedFromFavoriteListener;
use OCA\Files\Listener\RenderReferenceEventListener;
use OCA\Files\Listener\SyncLivePhotosListener;
use OCA\Files\Notification\Notifier;
Expand All @@ -33,12 +35,13 @@
use OCP\AppFramework\Bootstrap\IRegistrationContext;
use OCP\Collaboration\Reference\RenderReferenceEvent;
use OCP\Collaboration\Resources\IProviderManager;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\Files\Cache\CacheEntryRemovedEvent;
use OCP\Files\Events\Node\BeforeNodeCopiedEvent;
use OCP\Files\Events\Node\BeforeNodeDeletedEvent;
use OCP\Files\Events\Node\BeforeNodeRenamedEvent;
use OCP\Files\Events\Node\NodeCopiedEvent;
use OCP\Files\Events\NodeAddedToFavorite;
use OCP\Files\Events\NodeRemovedFromFavorite;
use OCP\Files\IRootFolder;
use OCP\IConfig;
use OCP\IL10N;
Expand Down Expand Up @@ -96,7 +99,6 @@ public function register(IRegistrationContext $context): void {
$c->get(IActivityManager::class),
$c->get(ITagManager::class)->load(self::APP_ID),
$server->getUserFolder(),
$c->get(IEventDispatcher::class),
);
});

Expand All @@ -116,7 +118,8 @@ public function register(IRegistrationContext $context): void {
$context->registerEventListener(BeforeNodeCopiedEvent::class, SyncLivePhotosListener::class);
$context->registerEventListener(NodeCopiedEvent::class, SyncLivePhotosListener::class);
$context->registerEventListener(LoadSearchPlugins::class, LoadSearchPluginsListener::class);

$context->registerEventListener(NodeAddedToFavorite::class, NodeAddedToFavoriteListener::class);
$context->registerEventListener(NodeRemovedFromFavorite::class, NodeRemovedFromFavoriteListener::class);
$context->registerSearchProvider(FilesSearchProvider::class);

$context->registerNotifierService(Notifier::class);
Expand Down
Loading

0 comments on commit 7a9eb28

Please sign in to comment.