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

Modernize contacts menu backend #31662

Merged
merged 1 commit into from
May 13, 2022
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
8 changes: 0 additions & 8 deletions build/psalm-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2818,14 +2818,6 @@
<code>$this-&gt;application</code>
</UndefinedThisPropertyFetch>
</file>
<file src="lib/private/Contacts/ContactsMenu/Manager.php">
<InvalidNullableReturnType occurrences="1">
<code>IEntry</code>
</InvalidNullableReturnType>
<NullableReturnStatement occurrences="1">
<code>$entry</code>
</NullableReturnStatement>
</file>
<file src="lib/private/ContactsManager.php">
<InvalidNullableReturnType occurrences="3">
<code>IAddressBook</code>
Expand Down
23 changes: 7 additions & 16 deletions core/Controller/ContactsMenuController.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
*/
namespace OC\Core\Controller;

use Exception;
use OC\Contacts\ContactsMenu\Manager;
use OCP\AppFramework\Controller;
use OCP\AppFramework\Http;
Expand All @@ -32,18 +33,9 @@
use OCP\IUserSession;

class ContactsMenuController extends Controller {
private Manager $manager;
private IUserSession $userSession;

/** @var Manager */
private $manager;

/** @var IUserSession */
private $userSession;

/**
* @param IRequest $request
* @param IUserSession $userSession
* @param Manager $manager
*/
public function __construct(IRequest $request, IUserSession $userSession, Manager $manager) {
parent::__construct('core', $request);
$this->userSession = $userSession;
Expand All @@ -53,21 +45,20 @@ public function __construct(IRequest $request, IUserSession $userSession, Manage
/**
* @NoAdminRequired
*
* @param string|null filter
* @return \JsonSerializable[]
* @throws Exception
*/
public function index($filter = null) {
public function index(?string $filter = null): array {
return $this->manager->getEntries($this->userSession->getUser(), $filter);
}

/**
* @NoAdminRequired
*
* @param integer $shareType
* @param string $shareWith
* @return JSONResponse|\JsonSerializable
* @throws Exception
*/
public function findOne($shareType, $shareWith) {
public function findOne(int $shareType, string $shareWith) {
tcitworld marked this conversation as resolved.
Show resolved Hide resolved
$contact = $this->manager->findOne($this->userSession->getUser(), $shareType, $shareWith);

if ($contact) {
Expand Down
14 changes: 4 additions & 10 deletions lib/private/Contacts/ContactsMenu/ActionProviderStore.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,9 @@
use Psr\Log\LoggerInterface;

class ActionProviderStore {

/** @var IServerContainer */
private $serverContainer;

/** @var AppManager */
private $appManager;

/** @var LoggerInterface */
private $logger;
private IServerContainer $serverContainer;
private AppManager $appManager;
private LoggerInterface $logger;

public function __construct(IServerContainer $serverContainer, AppManager $appManager, LoggerInterface $logger) {
$this->serverContainer = $serverContainer;
Expand All @@ -67,7 +61,7 @@ public function getProviders(IUser $user): array {

foreach ($allClasses as $class) {
try {
$providers[] = $this->serverContainer->query($class);
$providers[] = $this->serverContainer->get($class);
} catch (QueryException $ex) {
$this->logger->error(
'Could not load contacts menu action provider ' . $class,
Expand Down
54 changes: 12 additions & 42 deletions lib/private/Contacts/ContactsMenu/Actions/LinkAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,81 +25,51 @@
use OCP\Contacts\ContactsMenu\ILinkAction;

class LinkAction implements ILinkAction {

/** @var string */
private $icon;

/** @var string */
private $name;

/** @var string */
private $href;

/** @var int */
private $priority = 10;

/** @var string */
private $appId;
private string $icon = '';
private string $name = '';
private string $href = '';
private int $priority = 10;
private string $appId = '';

/**
* @param string $icon absolute URI to an icon
*/
public function setIcon($icon) {
public function setIcon(string $icon) {
$this->icon = $icon;
}

/**
* @param string $name
*/
public function setName($name) {
public function setName(string $name) {
$this->name = $name;
}

/**
* @return string
*/
public function getName() {
public function getName(): string {
return $this->name;
}

/**
* @param int $priority
*/
public function setPriority($priority) {
public function setPriority(int $priority) {
$this->priority = $priority;
}

/**
* @return int
*/
public function getPriority() {
public function getPriority(): int {
return $this->priority;
}

/**
* @param string $href
*/
public function setHref($href) {
public function setHref(string $href) {
$this->href = $href;
}

/**
* @return string
*/
public function getHref() {
public function getHref(): string {
return $this->href;
}

/**
* @param string $appId
* @since 23.0.0
*/
public function setAppId(string $appId) {
$this->appId = $appId;
}

/**
* @return string
* @since 23.0.0
*/
public function getAppId(): string {
Expand Down
56 changes: 14 additions & 42 deletions lib/private/Contacts/ContactsMenu/ContactsStore.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,30 +44,14 @@
use OCP\L10N\IFactory as IL10NFactory;

class ContactsStore implements IContactsStore {

/** @var IManager */
private $contactsManager;

/** @var IConfig */
private $config;

/** @var ProfileManager */
private $profileManager;

/** @var IUserManager */
private $userManager;

/** @var IURLGenerator */
private $urlGenerator;

/** @var IGroupManager */
private $groupManager;

/** @var KnownUserService */
private $knownUserService;

/** @var IL10NFactory */
private $l10nFactory;
private IManager $contactsManager;
private IConfig $config;
private ProfileManager $profileManager;
private IUserManager $userManager;
private IURLGenerator $urlGenerator;
private IGroupManager $groupManager;
private KnownUserService $knownUserService;
private IL10NFactory $l10nFactory;

public function __construct(
IManager $contactsManager,
Expand All @@ -90,11 +74,9 @@ public function __construct(
}

/**
* @param IUser $user
* @param string|null $filter
* @return IEntry[]
*/
public function getContacts(IUser $user, $filter, ?int $limit = null, ?int $offset = null) {
public function getContacts(IUser $user, ?string $filter, ?int $limit = null, ?int $offset = null): array {
$options = [
'enumeration' => $this->config->getAppValue('core', 'shareapi_allow_share_dialog_user_enumeration', 'yes') === 'yes',
'fullmatch' => $this->config->getAppValue('core', 'shareapi_restrict_user_enumeration_full_match', 'yes') === 'yes',
Expand Down Expand Up @@ -152,8 +134,8 @@ public function getContacts(IUser $user, $filter, ?int $limit = null, ?int $offs
private function filterContacts(
IUser $self,
array $entries,
$filter
) {
?string $filter
): array {
$disallowEnumeration = $this->config->getAppValue('core', 'shareapi_allow_share_dialog_user_enumeration', 'yes') !== 'yes';
$restrictEnumerationGroup = $this->config->getAppValue('core', 'shareapi_restrict_user_enumeration_to_group', 'no') === 'yes';
$restrictEnumerationPhone = $this->config->getAppValue('core', 'shareapi_restrict_user_enumeration_to_phone', 'no') === 'yes';
Expand All @@ -168,7 +150,7 @@ private function filterContacts(
$selfGroups = $this->groupManager->getUserGroupIds($self);

if ($excludedGroups) {
$excludedGroups = $this->config->getAppValue('core', 'shareapi_exclude_groups_list', '');
$excludedGroups = $this->config->getAppValue('core', 'shareapi_exclude_groups_list');
$decodedExcludeGroups = json_decode($excludedGroups, true);
$excludeGroupsList = $decodedExcludeGroups ?? [];

Expand Down Expand Up @@ -253,13 +235,7 @@ private function filterContacts(
}));
}

/**
* @param IUser $user
* @param integer $shareType
* @param string $shareWith
* @return IEntry|null
*/
public function findOne(IUser $user, $shareType, $shareWith) {
public function findOne(IUser $user, int $shareType, string $shareWith): ?IEntry {
switch ($shareType) {
case 0:
case 6:
Expand Down Expand Up @@ -305,11 +281,7 @@ public function findOne(IUser $user, $shareType, $shareWith) {
return $match;
}

/**
* @param array $contact
* @return Entry
*/
private function contactArrayToEntry(array $contact) {
private function contactArrayToEntry(array $contact): Entry {
$entry = new Entry();

if (isset($contact['id'])) {
Expand Down
Loading