Skip to content

Commit 17595af

Browse files
authored
Merge pull request #3286 from nextcloud/enh/UserMapper
Redesign UserMapper and Acl
2 parents 664503a + 3b9e7df commit 17595af

File tree

148 files changed

+1855
-1451
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

148 files changed

+1855
-1451
lines changed

appinfo/info.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<name>Polls</name>
55
<summary>A polls app, similar to Doodle/Dudle with the possibility to restrict access.</summary>
66
<description>A polls app, similar to Doodle/Dudle with the possibility to restrict access (members, certain groups/users, hidden and public).</description>
7-
<version>6.1.0-beta5</version>
7+
<version>6.1.0-rc2</version>
88
<licence>agpl</licence>
99
<author>Vinzenz Rosenkranz</author>
1010
<author>René Gieling</author>

appinfo/routes.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959

6060
['name' => 'page#index', 'url' => '/', 'verb' => 'GET'],
6161
['name' => 'page#index', 'url' => '/not-found', 'verb' => 'GET', 'postfix' => 'notfound'],
62-
['name' => 'page#index', 'url' => '/list/{category}', 'verb' => 'GET', 'postfix' => 'list', 'defaults' => array('category' => 'relevant')],
62+
['name' => 'page#index', 'url' => '/list/{category}', 'verb' => 'GET', 'postfix' => 'list', 'defaults' => ['category' => 'relevant']],
6363
['name' => 'page#index', 'url' => '/combo', 'verb' => 'GET', 'postfix' => 'combo'],
6464
['name' => 'page#vote', 'url' => '/vote/{id}', 'verb' => 'GET'],
6565

@@ -135,7 +135,7 @@
135135
['name' => 'preferences#get_calendars', 'url' => '/calendars', 'verb' => 'GET'],
136136

137137
// REST-API calls
138-
['name' => 'base_api#preflighted_cors', 'url' => '/api/v1.0/{path}', 'verb' => 'OPTIONS', 'requirements' => array('path' => '.+')],
138+
['name' => 'base_api#preflighted_cors', 'url' => '/api/v1.0/{path}', 'verb' => 'OPTIONS', 'requirements' => ['path' => '.+']],
139139
['name' => 'poll_api#list', 'url' => '/api/v1.0/polls', 'verb' => 'GET'],
140140
['name' => 'poll_api#transfer_polls', 'url' => '/api/v1.0/polls/transfer/{sourceUser}/{destinationUser}', 'verb' => 'PUT'],
141141
['name' => 'poll_api#transfer_poll', 'url' => '/api/v1.0/poll/{pollId}/transfer/{destinationUser}', 'verb' => 'PUT'],

composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
"cs:check": "php-cs-fixer fix --dry-run --diff",
4343
"cs:fix": "php-cs-fixer fix",
4444
"psalm": "psalm --no-diff",
45-
"psalm:fix": "psalm --alter --issues=MissingReturnType,InvalidReturnType,InvalidNullableReturnType,MismatchingDocblockParamType,MismatchingDocblockReturnType,MissingParamType,InvalidFalsableReturnType",
45+
"psalm:fix": "psalm --alter --php-version=8.0 --issues=MissingReturnType,InvalidReturnType,InvalidNullableReturnType,MismatchingDocblockParamType,MismatchingDocblockReturnType,MissingParamType,InvalidFalsableReturnType",
4646
"psalm:info": "psalm --no-diff --show-info=true",
4747
"psalm:baseline": "psalm --set-baseline=psalm-baseline.xml",
4848
"psalm:baseline:update": "psalm --update-baseline"

composer.lock

+7-7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/Activity/PollChanges.php

+3
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@
2929
use OCP\IL10N;
3030
use OCP\IURLGenerator;
3131

32+
/**
33+
* @psalm-suppress UnusedClass
34+
*/
3235
class PollChanges implements IFilter {
3336
public function __construct(
3437
protected IL10N $l10n,

lib/AppInfo/Application.php

+3
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,9 @@
7373
use OCP\Group\Events\GroupDeletedEvent;
7474
use OCP\User\Events\UserDeletedEvent;
7575

76+
/**
77+
* @psalm-api
78+
*/
7679
class Application extends App implements IBootstrap {
7780
/** @var string */
7881
public const APP_ID = AppConstants::APP_ID;

lib/Command/Db/CleanMigrations.php

+3
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@
3030
use OCA\Polls\Db\TableManager;
3131
use OCP\IDBConnection;
3232

33+
/**
34+
* @psalm-api
35+
*/
3336
class CleanMigrations extends Command {
3437
protected string $name = parent::NAME_PREFIX . 'db:clean-migrations';
3538
protected string $description = 'Remove old migrations entries from Nextcloud\'s migration table';

lib/Command/Db/CreateIndices.php

+3
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@
3030
use OCA\Polls\Db\IndexManager;
3131
use OCP\IDBConnection;
3232

33+
/**
34+
* @psalm-api
35+
*/
3336
class CreateIndices extends Command {
3437
protected string $name = parent::NAME_PREFIX . 'index:create';
3538
protected string $description = 'Add all indices and foreign key constraints';

lib/Command/Db/Purge.php

+3
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@
2929
use OCA\Polls\Db\TableManager;
3030
use OCP\IDBConnection;
3131

32+
/**
33+
* @psalm-api
34+
*/
3235
class Purge extends Command {
3336
protected string $name = parent::NAME_PREFIX . 'db:purge';
3437
protected string $description = 'Remove all polls related tables and records';

lib/Command/Db/Rebuild.php

+3
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@
3131
use OCA\Polls\Command\Command;
3232
use OCP\IDBConnection;
3333

34+
/**
35+
* @psalm-api
36+
*/
3437
class Rebuild extends Command {
3538
protected string $name = parent::NAME_PREFIX . 'db:rebuild';
3639
protected string $description = 'Rebuilds poll\'s table structure';

lib/Command/Db/RemoveIndices.php

+3
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@
3030
use OCA\Polls\Db\IndexManager;
3131
use OCP\IDBConnection;
3232

33+
/**
34+
* @psalm-api
35+
*/
3336
class RemoveIndices extends Command {
3437
protected string $name = parent::NAME_PREFIX . 'index:remove';
3538
protected string $description = 'Remove all indices and foreign key constraints';

lib/Command/Db/ResetWatch.php

+3
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@
3333
use OCA\Polls\Migration\TableSchema;
3434
use OCP\IDBConnection;
3535

36+
/**
37+
* @psalm-api
38+
*/
3639
class ResetWatch extends Command {
3740
protected string $name = parent::NAME_PREFIX . 'db:reset-watch';
3841
protected string $description = 'Resets the Watch table';

lib/Command/Poll/TransferOwnership.php

+3
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@
3535
use Symfony\Component\Console\Output\OutputInterface;
3636
use Symfony\Component\Console\Question\ConfirmationQuestion;
3737

38+
/**
39+
* @psalm-api
40+
*/
3841
class TransferOwnership extends Command {
3942
public function __construct(
4043
private IUserManager $userManager,

lib/Command/Share/Add.php

+3
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@
3939
use Symfony\Component\Console\Input\InputOption;
4040
use Symfony\Component\Console\Output\OutputInterface;
4141

42+
/**
43+
* @psalm-api
44+
*/
4245
class Add extends Base {
4346
use TShareCommand;
4447

lib/Command/Share/Remove.php

+3
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@
4040
use Symfony\Component\Console\Input\InputOption;
4141
use Symfony\Component\Console\Output\OutputInterface;
4242

43+
/**
44+
* @psalm-api
45+
*/
4346
class Remove extends Base {
4447
use TShareCommand;
4548

lib/Controller/AdminController.php

+7-4
Original file line numberDiff line numberDiff line change
@@ -26,27 +26,30 @@
2626
namespace OCA\Polls\Controller;
2727

2828
use OCA\Polls\AppConstants;
29+
use OCA\Polls\Db\UserMapper;
2930
use OCA\Polls\Service\PollService;
3031
use OCP\AppFramework\Http\Attribute\NoCSRFRequired;
3132
use OCP\AppFramework\Http\JSONResponse;
3233
use OCP\AppFramework\Http\TemplateResponse;
3334
use OCP\Collaboration\Resources\LoadAdditionalScriptsEvent;
3435
use OCP\EventDispatcher\IEventDispatcher;
3536
use OCP\IRequest;
36-
use OCP\ISession;
3737
use OCP\IURLGenerator;
3838
use OCP\Util;
3939

40+
/**
41+
* @psalm-api
42+
*/
4043
class AdminController extends BaseController {
4144
public function __construct(
4245
string $appName,
4346
IRequest $request,
44-
ISession $session,
4547
private IURLGenerator $urlGenerator,
4648
private PollService $pollService,
4749
private IEventDispatcher $eventDispatcher,
50+
private UserMapper $userMapper,
4851
) {
49-
parent::__construct($appName, $request, $session);
52+
parent::__construct($appName, $request);
5053
}
5154

5255
#[NoCSRFRequired]
@@ -67,7 +70,7 @@ public function list(): JSONResponse {
6770
* Get list of polls for administrative purposes
6871
*/
6972
public function takeover(int $pollId): JSONResponse {
70-
return $this->response(fn () => $this->pollService->takeover($pollId));
73+
return $this->response(fn () => $this->pollService->takeover($pollId, $this->userMapper->getCurrentUser()));
7174
}
7275

7376
/**

lib/Controller/BaseApiController.php

+3
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@
3434
use OCP\AppFramework\Http\JSONResponse;
3535
use OCP\IRequest;
3636

37+
/**
38+
* @psalm-api
39+
*/
3740
class BaseApiController extends ApiController {
3841
public function __construct(
3942
string $appName,

lib/Controller/BaseController.php

+3-11
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
namespace OCA\Polls\Controller;
2727

2828
use Closure;
29-
use OCA\Polls\AppConstants;
3029
use OCA\Polls\Exceptions\Exception;
3130
use OCA\Polls\Exceptions\NoUpdatesException;
3231
use OCP\AppFramework\Controller;
@@ -35,13 +34,14 @@
3534
use OCP\AppFramework\Http\Attribute\NoAdminRequired;
3635
use OCP\AppFramework\Http\JSONResponse;
3736
use OCP\IRequest;
38-
use OCP\ISession;
3937

38+
/**
39+
* @psalm-api
40+
*/
4041
class BaseController extends Controller {
4142
public function __construct(
4243
string $appName,
4344
IRequest $request,
44-
protected ISession $session,
4545
) {
4646
parent::__construct($appName, $request);
4747
}
@@ -51,8 +51,6 @@ public function __construct(
5151
*/
5252
#[NoAdminRequired]
5353
protected function response(Closure $callback): JSONResponse {
54-
$this->session->remove(AppConstants::SESSION_KEY_SHARE_TOKEN);
55-
5654
try {
5755
return new JSONResponse($callback(), Http::STATUS_OK);
5856
} catch (Exception $e) {
@@ -65,8 +63,6 @@ protected function response(Closure $callback): JSONResponse {
6563
*/
6664
#[NoAdminRequired]
6765
protected function responseLong(Closure $callback): JSONResponse {
68-
$this->session->remove(AppConstants::SESSION_KEY_SHARE_TOKEN);
69-
7066
try {
7167
return new JSONResponse($callback(), Http::STATUS_OK);
7268
} catch (NoUpdatesException $e) {
@@ -79,8 +75,6 @@ protected function responseLong(Closure $callback): JSONResponse {
7975
*/
8076
#[NoAdminRequired]
8177
protected function responseCreate(Closure $callback): JSONResponse {
82-
$this->session->remove(AppConstants::SESSION_KEY_SHARE_TOKEN);
83-
8478
try {
8579
return new JSONResponse($callback(), Http::STATUS_CREATED);
8680
} catch (Exception $e) {
@@ -93,8 +87,6 @@ protected function responseCreate(Closure $callback): JSONResponse {
9387
*/
9488
#[NoAdminRequired]
9589
protected function responseDeleteTolerant(Closure $callback): JSONResponse {
96-
$this->session->remove(AppConstants::SESSION_KEY_SHARE_TOKEN);
97-
9890
try {
9991
return new JSONResponse($callback(), Http::STATUS_OK);
10092
} catch (DoesNotExistException $e) {

lib/Controller/BasePublicController.php

+14-3
Original file line numberDiff line numberDiff line change
@@ -29,18 +29,23 @@
2929
use OCA\Polls\AppConstants;
3030
use OCA\Polls\Exceptions\Exception;
3131
use OCA\Polls\Exceptions\NoUpdatesException;
32+
use OCA\Polls\Model\Acl;
3233
use OCP\AppFramework\Controller;
3334
use OCP\AppFramework\Http;
3435
use OCP\AppFramework\Http\Attribute\NoAdminRequired;
3536
use OCP\AppFramework\Http\JSONResponse;
3637
use OCP\IRequest;
3738
use OCP\ISession;
3839

40+
/**
41+
* @psalm-api
42+
*/
3943
class BasePublicController extends Controller {
4044
public function __construct(
4145
string $appName,
4246
IRequest $request,
4347
protected ISession $session,
48+
protected Acl $acl,
4449
) {
4550
parent::__construct($appName, $request);
4651
}
@@ -50,7 +55,7 @@ public function __construct(
5055
*/
5156
#[NoAdminRequired]
5257
protected function response(Closure $callback, string $token): JSONResponse {
53-
$this->session->set(AppConstants::SESSION_KEY_SHARE_TOKEN, $token);
58+
$this->updateSessionToken($token);
5459

5560
try {
5661
return new JSONResponse($callback(), Http::STATUS_OK);
@@ -64,7 +69,7 @@ protected function response(Closure $callback, string $token): JSONResponse {
6469
*/
6570
#[NoAdminRequired]
6671
protected function responseLong(Closure $callback, string $token): JSONResponse {
67-
$this->session->set(AppConstants::SESSION_KEY_SHARE_TOKEN, $token);
72+
$this->updateSessionToken($token);
6873

6974
try {
7075
return new JSONResponse($callback(), Http::STATUS_OK);
@@ -77,12 +82,18 @@ protected function responseLong(Closure $callback, string $token): JSONResponse
7782
*/
7883
#[NoAdminRequired]
7984
protected function responseCreate(Closure $callback, string $token): JSONResponse {
80-
$this->session->set(AppConstants::SESSION_KEY_SHARE_TOKEN, $token);
85+
$this->updateSessionToken($token);
8186

8287
try {
8388
return new JSONResponse($callback(), Http::STATUS_CREATED);
8489
} catch (Exception $e) {
8590
return new JSONResponse(['message' => $e->getMessage()], $e->getStatus());
8691
}
8792
}
93+
94+
private function updateSessionToken(string $token): void {
95+
if ($token !== $this->session->get(AppConstants::SESSION_KEY_SHARE_TOKEN)) {
96+
$this->session->set(AppConstants::SESSION_KEY_SHARE_TOKEN, $token);
97+
}
98+
}
8899
}

0 commit comments

Comments
 (0)