mirror of
https://github.com/nextcloud/server.git
synced 2026-04-15 22:11:17 -04:00
Merge pull request #39075 from fsamapoor/refactor_lib_private_profile
Refactors lib/private/Profile.
This commit is contained in:
commit
b6927d0fa3
6 changed files with 59 additions and 157 deletions
|
|
@ -33,26 +33,13 @@ use OCP\L10N\IFactory;
|
|||
use OCP\Profile\ILinkAction;
|
||||
|
||||
class EmailAction implements ILinkAction {
|
||||
/** @var string */
|
||||
private $value;
|
||||
|
||||
/** @var IAccountManager */
|
||||
private $accountManager;
|
||||
|
||||
/** @var IFactory */
|
||||
private $l10nFactory;
|
||||
|
||||
/** @var IUrlGenerator */
|
||||
private $urlGenerator;
|
||||
private string $value = '';
|
||||
|
||||
public function __construct(
|
||||
IAccountManager $accountManager,
|
||||
IFactory $l10nFactory,
|
||||
IURLGenerator $urlGenerator
|
||||
private IAccountManager $accountManager,
|
||||
private IFactory $l10nFactory,
|
||||
private IURLGenerator $urlGenerator,
|
||||
) {
|
||||
$this->accountManager = $accountManager;
|
||||
$this->l10nFactory = $l10nFactory;
|
||||
$this->urlGenerator = $urlGenerator;
|
||||
}
|
||||
|
||||
public function preload(IUser $targetUser): void {
|
||||
|
|
|
|||
|
|
@ -34,19 +34,13 @@ use OCP\L10N\IFactory;
|
|||
use OCP\Profile\ILinkAction;
|
||||
|
||||
class FediverseAction implements ILinkAction {
|
||||
private ?string $value = null;
|
||||
private IAccountManager $accountManager;
|
||||
private IFactory $l10nFactory;
|
||||
private IURLGenerator $urlGenerator;
|
||||
private string $value = '';
|
||||
|
||||
public function __construct(
|
||||
IAccountManager $accountManager,
|
||||
IFactory $l10nFactory,
|
||||
IURLGenerator $urlGenerator
|
||||
private IAccountManager $accountManager,
|
||||
private IFactory $l10nFactory,
|
||||
private IURLGenerator $urlGenerator,
|
||||
) {
|
||||
$this->accountManager = $accountManager;
|
||||
$this->l10nFactory = $l10nFactory;
|
||||
$this->urlGenerator = $urlGenerator;
|
||||
}
|
||||
|
||||
public function preload(IUser $targetUser): void {
|
||||
|
|
|
|||
|
|
@ -33,26 +33,13 @@ use OCP\L10N\IFactory;
|
|||
use OCP\Profile\ILinkAction;
|
||||
|
||||
class PhoneAction implements ILinkAction {
|
||||
/** @var string */
|
||||
private $value;
|
||||
|
||||
/** @var IAccountManager */
|
||||
private $accountManager;
|
||||
|
||||
/** @var IFactory */
|
||||
private $l10nFactory;
|
||||
|
||||
/** @var IUrlGenerator */
|
||||
private $urlGenerator;
|
||||
private string $value = '';
|
||||
|
||||
public function __construct(
|
||||
IAccountManager $accountManager,
|
||||
IFactory $l10nFactory,
|
||||
IURLGenerator $urlGenerator
|
||||
private IAccountManager $accountManager,
|
||||
private IFactory $l10nFactory,
|
||||
private IURLGenerator $urlGenerator,
|
||||
) {
|
||||
$this->accountManager = $accountManager;
|
||||
$this->l10nFactory = $l10nFactory;
|
||||
$this->urlGenerator = $urlGenerator;
|
||||
}
|
||||
|
||||
public function preload(IUser $targetUser): void {
|
||||
|
|
|
|||
|
|
@ -34,26 +34,13 @@ use OCP\L10N\IFactory;
|
|||
use OCP\Profile\ILinkAction;
|
||||
|
||||
class TwitterAction implements ILinkAction {
|
||||
/** @var string */
|
||||
private $value;
|
||||
|
||||
/** @var IAccountManager */
|
||||
private $accountManager;
|
||||
|
||||
/** @var IFactory */
|
||||
private $l10nFactory;
|
||||
|
||||
/** @var IUrlGenerator */
|
||||
private $urlGenerator;
|
||||
private string $value = '';
|
||||
|
||||
public function __construct(
|
||||
IAccountManager $accountManager,
|
||||
IFactory $l10nFactory,
|
||||
IURLGenerator $urlGenerator
|
||||
private IAccountManager $accountManager,
|
||||
private IFactory $l10nFactory,
|
||||
private IURLGenerator $urlGenerator,
|
||||
) {
|
||||
$this->accountManager = $accountManager;
|
||||
$this->l10nFactory = $l10nFactory;
|
||||
$this->urlGenerator = $urlGenerator;
|
||||
}
|
||||
|
||||
public function preload(IUser $targetUser): void {
|
||||
|
|
|
|||
|
|
@ -33,26 +33,13 @@ use OCP\L10N\IFactory;
|
|||
use OCP\Profile\ILinkAction;
|
||||
|
||||
class WebsiteAction implements ILinkAction {
|
||||
/** @var string */
|
||||
private $value;
|
||||
|
||||
/** @var IAccountManager */
|
||||
private $accountManager;
|
||||
|
||||
/** @var IFactory */
|
||||
private $l10nFactory;
|
||||
|
||||
/** @var IUrlGenerator */
|
||||
private $urlGenerator;
|
||||
private string $value = '';
|
||||
|
||||
public function __construct(
|
||||
IAccountManager $accountManager,
|
||||
IFactory $l10nFactory,
|
||||
IURLGenerator $urlGenerator
|
||||
private IAccountManager $accountManager,
|
||||
private IFactory $l10nFactory,
|
||||
private IURLGenerator $urlGenerator,
|
||||
) {
|
||||
$this->accountManager = $accountManager;
|
||||
$this->l10nFactory = $l10nFactory;
|
||||
$this->urlGenerator = $urlGenerator;
|
||||
}
|
||||
|
||||
public function preload(IUser $targetUser): void {
|
||||
|
|
|
|||
|
|
@ -50,38 +50,11 @@ use Psr\Container\ContainerInterface;
|
|||
use Psr\Log\LoggerInterface;
|
||||
|
||||
class ProfileManager {
|
||||
/** @var IAccountManager */
|
||||
private $accountManager;
|
||||
|
||||
/** @var IAppManager */
|
||||
private $appManager;
|
||||
|
||||
/** @var IConfig */
|
||||
private $config;
|
||||
|
||||
/** @var ProfileConfigMapper */
|
||||
private $configMapper;
|
||||
|
||||
/** @var ContainerInterface */
|
||||
private $container;
|
||||
|
||||
/** @var KnownUserService */
|
||||
private $knownUserService;
|
||||
|
||||
/** @var IFactory */
|
||||
private $l10nFactory;
|
||||
|
||||
/** @var LoggerInterface */
|
||||
private $logger;
|
||||
|
||||
/** @var Coordinator */
|
||||
private $coordinator;
|
||||
|
||||
/** @var ILinkAction[] */
|
||||
private $actions = [];
|
||||
private array $actions = [];
|
||||
|
||||
/** @var null|ILinkAction[] */
|
||||
private $sortedActions = null;
|
||||
private ?array $sortedActions = null;
|
||||
/** @var CappedMemoryCache<ProfileConfig> */
|
||||
private CappedMemoryCache $configCache;
|
||||
|
||||
|
|
@ -112,25 +85,16 @@ class ProfileManager {
|
|||
];
|
||||
|
||||
public function __construct(
|
||||
IAccountManager $accountManager,
|
||||
IAppManager $appManager,
|
||||
IConfig $config,
|
||||
ProfileConfigMapper $configMapper,
|
||||
ContainerInterface $container,
|
||||
KnownUserService $knownUserService,
|
||||
IFactory $l10nFactory,
|
||||
LoggerInterface $logger,
|
||||
Coordinator $coordinator
|
||||
private IAccountManager $accountManager,
|
||||
private IAppManager $appManager,
|
||||
private IConfig $config,
|
||||
private ProfileConfigMapper $configMapper,
|
||||
private ContainerInterface $container,
|
||||
private KnownUserService $knownUserService,
|
||||
private IFactory $l10nFactory,
|
||||
private LoggerInterface $logger,
|
||||
private Coordinator $coordinator,
|
||||
) {
|
||||
$this->accountManager = $accountManager;
|
||||
$this->appManager = $appManager;
|
||||
$this->config = $config;
|
||||
$this->configMapper = $configMapper;
|
||||
$this->container = $container;
|
||||
$this->knownUserService = $knownUserService;
|
||||
$this->l10nFactory = $l10nFactory;
|
||||
$this->logger = $logger;
|
||||
$this->coordinator = $coordinator;
|
||||
$this->configCache = new CappedMemoryCache();
|
||||
}
|
||||
|
||||
|
|
@ -239,40 +203,36 @@ class ProfileManager {
|
|||
|
||||
$visibility = $this->getProfileConfig($targetUser, $visitingUser)[$paramId]['visibility'];
|
||||
// Handle profile visibility and account property scope
|
||||
switch ($visibility) {
|
||||
case ProfileConfig::VISIBILITY_HIDE:
|
||||
return false;
|
||||
case ProfileConfig::VISIBILITY_SHOW_USERS_ONLY:
|
||||
if (!empty($scope)) {
|
||||
switch ($scope) {
|
||||
case IAccountManager::SCOPE_PRIVATE:
|
||||
return $visitingUser !== null && $this->knownUserService->isKnownToUser($targetUser->getUID(), $visitingUser->getUID());
|
||||
case IAccountManager::SCOPE_LOCAL:
|
||||
case IAccountManager::SCOPE_FEDERATED:
|
||||
case IAccountManager::SCOPE_PUBLISHED:
|
||||
return $visitingUser !== null;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if ($visibility === ProfileConfig::VISIBILITY_SHOW_USERS_ONLY) {
|
||||
if (empty($scope)) {
|
||||
return $visitingUser !== null;
|
||||
case ProfileConfig::VISIBILITY_SHOW:
|
||||
if (!empty($scope)) {
|
||||
switch ($scope) {
|
||||
case IAccountManager::SCOPE_PRIVATE:
|
||||
return $visitingUser !== null && $this->knownUserService->isKnownToUser($targetUser->getUID(), $visitingUser->getUID());
|
||||
case IAccountManager::SCOPE_LOCAL:
|
||||
case IAccountManager::SCOPE_FEDERATED:
|
||||
case IAccountManager::SCOPE_PUBLISHED:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
|
||||
return match ($scope) {
|
||||
IAccountManager::SCOPE_PRIVATE => $visitingUser !== null && $this->knownUserService->isKnownToUser($targetUser->getUID(), $visitingUser->getUID()),
|
||||
IAccountManager::SCOPE_LOCAL,
|
||||
IAccountManager::SCOPE_FEDERATED,
|
||||
IAccountManager::SCOPE_PUBLISHED => $visitingUser !== null,
|
||||
default => false,
|
||||
};
|
||||
}
|
||||
|
||||
if ($visibility === ProfileConfig::VISIBILITY_SHOW) {
|
||||
if (empty($scope)) {
|
||||
return true;
|
||||
};
|
||||
|
||||
return match ($scope) {
|
||||
IAccountManager::SCOPE_PRIVATE => $visitingUser !== null && $this->knownUserService->isKnownToUser($targetUser->getUID(), $visitingUser->getUID()),
|
||||
IAccountManager::SCOPE_LOCAL,
|
||||
IAccountManager::SCOPE_FEDERATED,
|
||||
IAccountManager::SCOPE_PUBLISHED => true,
|
||||
default => false,
|
||||
};
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Reference in a new issue