Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: DI userId instead of userSession #2293

Merged
merged 2 commits into from
Aug 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 7 additions & 10 deletions lib/Activity/ActivityManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,23 +29,20 @@
use OCP\Activity\IManager;
use OCP\IGroupManager;
use OCP\IUser;
use OCP\IUserSession;
use OCP\Share\IShare;

use Psr\Log\LoggerInterface;

class ActivityManager {
private IUser $currentUser;

public function __construct(
protected string $appName,
private ?string $userId,
private IManager $manager,
private IGroupManager $groupManager,
private LoggerInterface $logger,
private IUserSession $userSession,
private CirclesService $circlesService,
) {
$this->currentUser = $userSession->getUser();
}

/**
Expand All @@ -58,9 +55,9 @@ public function publishNewShare(Form $form, string $shareeId) {
$event->setApp($this->appName)
->setType(ActivityConstants::TYPE_NEWSHARE)
->setAffectedUser($shareeId)
->setAuthor($this->currentUser->getUID())
->setAuthor($this->userId)
->setSubject(ActivityConstants::SUBJECT_NEWSHARE, [
'userId' => $this->currentUser->getUID(),
'userId' => $this->userId,
'formTitle' => $form->getTitle(),
'formHash' => $form->getHash()
])
Expand All @@ -82,9 +79,9 @@ public function publishNewGroupShare(Form $form, string $groupId) {
$event->setApp($this->appName)
->setType(ActivityConstants::TYPE_NEWSHARE)
->setAffectedUser($user->getUID())
->setAuthor($this->currentUser->getUID())
->setAuthor($this->userId)
->setSubject(ActivityConstants::SUBJECT_NEWGROUPSHARE, [
'userId' => $this->currentUser->getUID(),
'userId' => $this->userId,
'groupId' => $groupId,
'formTitle' => $form->getTitle(),
'formHash' => $form->getHash()
Expand All @@ -109,9 +106,9 @@ public function publishNewCircleShare(Form $form, string $circleId) {
$event->setApp($this->appName)
->setType(ActivityConstants::TYPE_NEWSHARE)
->setAffectedUser($user)
->setAuthor($this->currentUser->getUID())
->setAuthor($this->userId)
->setSubject(ActivityConstants::SUBJECT_NEWCIRCLESHARE, [
'userId' => $this->currentUser->getUID(),
'userId' => $this->userId,
'circleId' => $circleId,
'formTitle' => $form->getTitle(),
'formHash' => $form->getHash()
Expand Down
6 changes: 5 additions & 1 deletion lib/Service/ConfigService.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
use Psr\Log\LoggerInterface;

class ConfigService {
private IUser $currentUser;
private ?IUser $currentUser;

public function __construct(
protected string $appName,
Expand Down Expand Up @@ -107,6 +107,10 @@
* @return bool
*/
public function canCreateForms(): bool {
if ($this->currentUser === null) {
return false;

Check warning on line 111 in lib/Service/ConfigService.php

View check run for this annotation

Codecov / codecov/patch

lib/Service/ConfigService.php#L111

Added line #L111 was not covered by tests
}

// Restriction active or not
if (!$this->getRestrictCreation()) {
return true;
Expand Down
12 changes: 1 addition & 11 deletions tests/Unit/Activity/ActivityManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
use OCP\IGroup;
use OCP\IGroupManager;
use OCP\IUser;
use OCP\IUserSession;
use OCP\Share\IShare;
use PHPUnit\Framework\MockObject\MockObject;
use Psr\Log\LoggerInterface;
Expand Down Expand Up @@ -61,17 +60,8 @@ public function setUp(): void {
$this->groupManager = $this->createMock(IGroupManager::class);
$this->logger = $this->getMockBuilder('Psr\Log\LoggerInterface')->getMock();
$this->circlesService = $this->createMock(CirclesService::class);
$userSession = $this->createMock(IUserSession::class);

$user = $this->createMock(IUser::class);
$user->expects($this->any())
->method('getUID')
->willReturn('currentUser');
$userSession->expects($this->once())
->method('getUser')
->willReturn($user);

$this->activityManager = new ActivityManager('forms', $this->manager, $this->groupManager, $this->logger, $userSession, $this->circlesService);
$this->activityManager = new ActivityManager('forms', 'currentUser', $this->manager, $this->groupManager, $this->logger, $this->circlesService);
}

public function testPublishNewShare() {
Expand Down
2 changes: 1 addition & 1 deletion tests/Unit/Service/SubmissionServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ public function setUp(): void {
$this->questionMapper,
$this->submissionMapper,
$this->answerMapper,
$this->uploadedFileMapper,
$this->storage,
$this->config,
$this->l10n,
Expand All @@ -148,7 +149,6 @@ public function setUp(): void {
$this->tempManager,
$this->formsService,
$this->urlGenerator,
$this->uploadedFileMapper,
);
}

Expand Down
Loading