Skip to content

Commit

Permalink
Modernize contacts menu
Browse files Browse the repository at this point in the history
Signed-off-by: Thomas Citharel <tcit@tcit.fr>
  • Loading branch information
tcitworld committed Mar 31, 2022
1 parent f548548 commit 0b468a1
Show file tree
Hide file tree
Showing 20 changed files with 270 additions and 448 deletions.
8 changes: 0 additions & 8 deletions build/psalm-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2850,14 +2850,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) {
$contact = $this->manager->findOne($this->userSession->getUser(), $shareType, $shareWith);

if ($contact) {
Expand Down
18 changes: 6 additions & 12 deletions lib/private/Contacts/ContactsMenu/ActionProviderStore.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,22 +31,16 @@
use OC\App\AppManager;
use OC\Contacts\ContactsMenu\Providers\EMailProvider;
use OC\Contacts\ContactsMenu\Providers\ProfileProvider;
use OCP\AppFramework\QueryException;
use OCP\Contacts\ContactsMenu\IProvider;
use OCP\IServerContainer;
use OCP\IUser;
use Psr\Container\ContainerExceptionInterface;
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,8 +61,8 @@ public function getProviders(IUser $user): array {

foreach ($allClasses as $class) {
try {
$providers[] = $this->serverContainer->query($class);
} catch (QueryException $ex) {
$providers[] = $this->serverContainer->get($class);
} catch (ContainerExceptionInterface $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
52 changes: 14 additions & 38 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 @@ -309,7 +285,7 @@ public function findOne(IUser $user, $shareType, $shareWith) {
* @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

0 comments on commit 0b468a1

Please sign in to comment.