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

Use marker interface to identify user objects. #3478

Merged
merged 4 commits into from Mar 7, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
32 changes: 4 additions & 28 deletions module/VuFind/src/VuFind/AjaxHandler/AbstractIlsAndUserAction.php
Expand Up @@ -48,44 +48,20 @@ abstract class AbstractIlsAndUserAction extends AbstractBase implements Translat
{
use \VuFind\I18n\Translator\TranslatorAwareTrait;

/**
* ILS connection
*
* @var Connection
*/
protected $ils;

/**
* ILS authenticator
*
* @var ILSAuthenticator
*/
protected $ilsAuthenticator;

/**
* Logged in user (or false)
*
* @var User|bool
*/
protected $user;

/**
* Constructor
*
* @param SessionSettings $ss Session settings
* @param Connection $ils ILS connection
* @param ILSAuthenticator $ilsAuthenticator ILS authenticator
* @param User|bool $user Logged in user (or false)
* @param ?User $user Logged in user (or null)
*/
public function __construct(
SessionSettings $ss,
Connection $ils,
ILSAuthenticator $ilsAuthenticator,
$user
protected Connection $ils,
protected ILSAuthenticator $ilsAuthenticator,
protected ?User $user
) {
$this->sessionSettings = $ss;
$this->ils = $ils;
$this->ilsAuthenticator = $ilsAuthenticator;
$this->user = $user;
}
}
22 changes: 3 additions & 19 deletions module/VuFind/src/VuFind/AjaxHandler/AbstractRelaisAction.php
Expand Up @@ -47,34 +47,18 @@ abstract class AbstractRelaisAction extends AbstractBase implements TranslatorAw
{
use \VuFind\I18n\Translator\TranslatorAwareTrait;

/**
* Relais connector
*
* @var Relais
*/
protected $relais;

/**
* Logged-in user (or null if none)
*
* @var User
*/
protected $user;

/**
* Constructor
*
* @param SessionSettings $ss Session settings
* @param Relais $relais Relais connector
* @param User $user Logged in user (or null if none)
* @param ?User $user Logged in user (or null if none)
*/
public function __construct(
SessionSettings $ss,
Relais $relais,
User $user = null
protected Relais $relais,
protected ?User $user
) {
$this->sessionSettings = $ss;
$this->relais = $relais;
$this->user = $user;
}
}
Expand Up @@ -69,11 +69,10 @@ public function __invoke(
if (!empty($options)) {
throw new \Exception('Unexpected options passed to factory.');
}
$user = $container->get(\VuFind\Auth\Manager::class)->getUserObject();
return new $requestedName(
$container->get(\VuFind\Session\Settings::class),
$container->get(\VuFind\Connection\Relais::class),
$user ?: null
$container->get(\VuFind\Auth\Manager::class)->getUserObject()
);
}
}
74 changes: 13 additions & 61 deletions module/VuFind/src/VuFind/AjaxHandler/CommentRecord.php
Expand Up @@ -52,72 +52,24 @@ class CommentRecord extends AbstractBase implements TranslatorAwareInterface
{
use \VuFind\I18n\Translator\TranslatorAwareTrait;

/**
* Resource database table
*
* @var Resource
*/
protected $table;

/**
* Captcha controller plugin
*
* @var Captcha
*/
protected $captcha;

/**
* Logged in user (or false)
*
* @var User|bool
*/
protected $user;

/**
* Are comments enabled?
*
* @var bool
*/
protected $enabled;

/**
* Record loader
*
* @var RecordLoader
*/
protected $recordLoader;

/**
* Account capabilities helper
*
* @var AccountCapabilities
*/
protected $accountCapabilities;

/**
* Constructor
*
* @param Resource $table Resource database table
* @param Captcha $captcha Captcha controller plugin
* @param User|bool $user Logged in user (or false)
* @param bool $enabled Are comments enabled?
* @param RecordLoader $loader Record loader
* @param AccountCapabilities $ac Account capabilities helper
* @param Resource $table Resource database table
* @param Captcha $captcha Captcha controller plugin
* @param ?User $user Logged in user (or null)
* @param bool $enabled Are comments enabled?
* @param RecordLoader $recordLoader Record loader
* @param AccountCapabilities $accountCapabilities Account capabilities helper
*/
public function __construct(
Resource $table,
Captcha $captcha,
$user,
$enabled,
RecordLoader $loader,
AccountCapabilities $ac
protected Resource $table,
protected Captcha $captcha,
protected ?User $user,
protected bool $enabled,
protected RecordLoader $recordLoader,
protected AccountCapabilities $accountCapabilities
) {
$this->table = $table;
$this->captcha = $captcha;
$this->user = $user;
$this->enabled = $enabled;
$this->recordLoader = $loader;
$this->accountCapabilities = $ac;
}

/**
Expand Down Expand Up @@ -152,7 +104,7 @@ public function handleRequest(Params $params)
);
}

if ($this->user === false) {
if (!$this->user) {
return $this->formatResponse(
$this->translate('You must be logged in first'),
self::STATUS_HTTP_NEED_AUTH
Expand Down
34 changes: 5 additions & 29 deletions module/VuFind/src/VuFind/AjaxHandler/DeleteRecordComment.php
Expand Up @@ -47,39 +47,15 @@ class DeleteRecordComment extends AbstractBase implements TranslatorAwareInterfa
{
use \VuFind\I18n\Translator\TranslatorAwareTrait;

/**
* Comments database table
*
* @var Comments
*/
protected $table;

/**
* Logged in user (or false)
*
* @var User|bool
*/
protected $user;

/**
* Are comments enabled?
*
* @var bool
*/
protected $enabled;

/**
* Constructor
*
* @param Comments $table Comments database table
* @param User|bool $user Logged in user (or false)
* @param bool $enabled Are comments enabled?
* @param Comments $table Comments database table
* @param ?User $user Logged in user (or null)
* @param bool $enabled Are comments enabled?
*/
public function __construct(Comments $table, $user, $enabled = true)
public function __construct(protected Comments $table, protected ?User $user, protected $enabled = true)
{
$this->table = $table;
$this->user = $user;
$this->enabled = $enabled;
}

/**
Expand All @@ -99,7 +75,7 @@ public function handleRequest(Params $params)
);
}

if ($this->user === false) {
if (!$this->user) {
return $this->formatResponse(
$this->translate('You must be logged in first'),
self::STATUS_HTTP_NEED_AUTH
Expand Down
28 changes: 2 additions & 26 deletions module/VuFind/src/VuFind/AjaxHandler/GetRecordTags.php
Expand Up @@ -45,39 +45,15 @@
*/
class GetRecordTags extends AbstractBase
{
/**
* Tags database table
*
* @var Tags
*/
protected $table;

/**
* Logged in user (or false)
*
* @var User|bool
*/
protected $user;

/**
* View renderer
*
* @var RendererInterface
*/
protected $renderer;

/**
* Constructor
*
* @param Tags $table Tags table
* @param User|bool $user Logged in user (or false)
* @param ?User $user Logged in user (or null)
* @param RendererInterface $renderer View renderer
*/
public function __construct(Tags $table, $user, RendererInterface $renderer)
public function __construct(protected Tags $table, protected ?User $user, protected RendererInterface $renderer)
{
$this->table = $table;
$this->user = $user;
$this->renderer = $renderer;
}

/**
Expand Down
20 changes: 2 additions & 18 deletions module/VuFind/src/VuFind/AjaxHandler/GetSaveStatuses.php
Expand Up @@ -53,32 +53,16 @@ class GetSaveStatuses extends AbstractBase implements TranslatorAwareInterface
{
use \VuFind\I18n\Translator\TranslatorAwareTrait;

/**
* Logged in user (or false)
*
* @var User|bool
*/
protected $user;

/**
* URL helper
*
* @var Url
*/
protected $urlHelper;

/**
* Constructor
*
* @param SessionSettings $ss Session settings
* @param User|bool $user Logged in user (or false)
* @param ?User $user Logged in user (or null)
* @param Url $urlHelper URL helper
*/
public function __construct(SessionSettings $ss, $user, Url $urlHelper)
public function __construct(SessionSettings $ss, protected ?User $user, protected Url $urlHelper)
{
$this->sessionSettings = $ss;
$this->user = $user;
$this->urlHelper = $urlHelper;
}

/**
Expand Down
Expand Up @@ -74,7 +74,7 @@ public function __invoke(
$container->get(\VuFind\Search\Results\PluginManager::class),
$container->get('ViewRenderer'),
$container->get(\VuFind\Record\Loader::class),
$container->get(\VuFind\Auth\Manager::class)->getUserObject() ?: null,
$container->get(\VuFind\Auth\Manager::class)->getUserObject(),
$container->get(\Laminas\Session\SessionManager::class)->getId(),
$container->get(\VuFind\Search\SearchNormalizer::class),
$container->get(\VuFind\Db\Table\PluginManager::class)->get(\VuFind\Db\Table\Search::class),
Expand Down
2 changes: 1 addition & 1 deletion module/VuFind/src/VuFind/AjaxHandler/RelaisInfo.php
Expand Up @@ -53,7 +53,7 @@ public function handleRequest(Params $params)
{
$this->disableSessionWrites(); // avoid session write timing bug
$oclcNumber = $params->fromQuery('oclcNumber');
$lin = $this->user['cat_username'] ?? null;
$lin = $this->user ? $this->user['cat_username'] : null;

// Authenticate
$authResponse = $this->relais->authenticatePatron($lin, true);
Expand Down
2 changes: 1 addition & 1 deletion module/VuFind/src/VuFind/AjaxHandler/RelaisOrder.php
Expand Up @@ -54,7 +54,7 @@ public function handleRequest(Params $params)
$this->disableSessionWrites(); // avoid session write timing bug
$oclcNumber = $params->fromQuery('oclcNumber');

$lin = $this->user['cat_username'] ?? null;
$lin = $this->user ? $this->user['cat_username'] : null;

// Authenticate
$authorizationId = $this->relais->authenticatePatron($lin);
Expand Down
32 changes: 4 additions & 28 deletions module/VuFind/src/VuFind/AjaxHandler/TagRecord.php
Expand Up @@ -50,39 +50,15 @@ class TagRecord extends AbstractBase implements TranslatorAwareInterface
{
use \VuFind\I18n\Translator\TranslatorAwareTrait;

/**
* Record loader
*
* @var Loader
*/
protected $loader;

/**
* Tag parser
*
* @var Tags
*/
protected $tagParser;

/**
* Logged in user (or false)
*
* @var User|bool
*/
protected $user;

/**
* Constructor
*
* @param Loader $loader Record loader
* @param Tags $parser Tag parser
* @param User|bool $user Logged in user (or false)
* @param Loader $loader Record loader
* @param Tags $tagParser Tag parser
* @param ?User $user Logged in user (or null)
*/
public function __construct(Loader $loader, Tags $parser, $user)
public function __construct(protected Loader $loader, protected Tags $tagParser, protected ?User $user)
{
$this->loader = $loader;
$this->tagParser = $parser;
$this->user = $user;
}

/**
Expand Down