Skip to content

Commit

Permalink
Merge pull request #2293 from nextcloud/fix/activity-manager
Browse files Browse the repository at this point in the history
fix: DI `userId` instead of `userSession`
  • Loading branch information
Chartman123 authored Aug 21, 2024
2 parents c33366e + 2906b76 commit 7864e8d
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 23 deletions.
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 @@ private function formatGroupsForMultiselect(array $groups): array {
* @return bool
*/
public function canCreateForms(): bool {
if ($this->currentUser === null) {
return false;
}

// 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

0 comments on commit 7864e8d

Please sign in to comment.