Skip to content

Commit 66ad22f

Browse files
skjnldsvPytal
authored andcommitted
[WHIP] Added Profile action API
Signed-off-by: John Molakvoæ <skjnldsv@users.noreply.github.com>
1 parent 73a8074 commit 66ad22f

7 files changed

Lines changed: 295 additions & 6 deletions

File tree

core/Controller/ProfileController.php

Lines changed: 63 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,57 +27,84 @@
2727

2828
namespace OC\Core\Controller;
2929

30-
30+
use EmailAction;
3131
use OCP\Accounts\IAccountManager;
3232
use OCP\AppFramework\Http\TemplateResponse;
3333
use OCP\AppFramework\Services\IInitialState;
3434
use OCP\IL10N;
3535
use OCP\IRequest;
3636
use OCP\IUserSession;
3737
use OCP\UserStatus\IManager;
38-
use OCP\UserStatus\IUserStatus;
3938
use OCP\Accounts\IAccount;
4039
use OCP\Accounts\IAccountProperty;
4140
use OCP\App\IAppManager;
41+
use OCP\IUserManager;
42+
use OCP\Profile\IActionManager;
4243

4344
class ProfileController extends \OCP\AppFramework\Controller {
4445

4546
/** @var IL10N */
4647
private $l10n;
48+
4749
/** @var IUserSession */
4850
private $userSession;
51+
52+
/** @var IUserManager */
53+
private $userManager;
54+
4955
/** @var IAccountManager */
5056
private $accountManager;
57+
5158
/** @var IInitialState */
5259
private $initialStateService;
60+
5361
/** @var IAppManager */
5462
private $appManager;
5563

64+
/** @var IManager */
65+
private $userStatusManager;
66+
67+
/** @var IActionManager */
68+
// private $actionManager;
69+
5670
public function __construct(
5771
$appName,
5872
IRequest $request,
5973
IL10N $l10n,
6074
IUserSession $userSession,
75+
IUserManager $userManager,
6176
IAccountManager $accountManager,
6277
IInitialState $initialStateService,
63-
IAppManager $appManager
78+
IAppManager $appManager,
79+
IManager $userStatusManager,
80+
// IActionManager $actionManager
6481
) {
6582
parent::__construct($appName, $request);
6683
$this->l10n = $l10n;
6784
$this->userSession = $userSession;
85+
$this->userManager = $userManager;
6886
$this->accountManager = $accountManager;
6987
$this->initialStateService = $initialStateService;
7088
$this->appManager = $appManager;
89+
$this->userStatusManager = $userStatusManager;
90+
// $this->actionManager = $actionManager;
7191
}
7292

93+
public const PROPERTY_ACTIONS = [
94+
IAccountManager::PROPERTY_EMAIL,
95+
IAccountManager::PROPERTY_PHONE,
96+
IAccountManager::PROPERTY_WEBSITE,
97+
IAccountManager::PROPERTY_TWITTER,
98+
];
99+
73100
/**
74101
* @NoCSRFRequired
75102
* @UseSession
76103
* FIXME Public page annotation blocks the user session somehow
77104
*/
78105
public function index(string $userId = null): TemplateResponse {
79106
$isLoggedIn = $this->userSession->isLoggedIn();
80-
$account = $this->accountManager->getAccount(\OC::$server->getUserManager()->get($userId));
107+
$account = $this->accountManager->getAccount($this->userManager->get($userId));
81108

82109
$profileEnabled = filter_var(
83110
$account->getProperty(IAccountManager::PROPERTY_PROFILE_ENABLED)->getValue(),
@@ -95,8 +122,7 @@ public function index(string $userId = null): TemplateResponse {
95122
);
96123
}
97124

98-
$status = \OC::$server->get(IManager::class);
99-
$status = $status->getUserStatuses([$userId]);
125+
$status = $this->userStatusManager->getUserStatuses([$userId]);
100126
$status = array_pop($status);
101127

102128
if ($status) {
@@ -158,4 +184,35 @@ function (IAccountProperty $property) {
158184

159185
return $profileParameters;
160186
}
187+
188+
protected function initActions(IAccount $account) {
189+
foreach(self::PROPERTY_ACTIONS as $property) {
190+
$scope = $account->getProperty($property)->getScope();
191+
$value = $account->getProperty($property)->getValue();
192+
193+
// TODO: handle talk verification
194+
if ($scope === IAccountManager::SCOPE_PRIVATE) {
195+
return;
196+
}
197+
198+
// User is not logged in, we don't display the action
199+
if ($scope === IAccountManager::SCOPE_LOCAL && !$this->userSession->isLoggedIn()) {
200+
return;
201+
}
202+
203+
// TODO: handle federation verification
204+
if ($scope === IAccountManager::SCOPE_FEDERATED && false) {
205+
return;
206+
}
207+
208+
switch ($property) {
209+
case IAccountManager::PROPERTY_EMAIL:
210+
// $this->actionManager->registerAction(new EmailAction($value));
211+
break;
212+
213+
default:
214+
break;
215+
}
216+
}
217+
}
161218
}

lib/composer/composer/autoload_classmap.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -456,6 +456,8 @@
456456
'OCP\\Preview\\IProvider' => $baseDir . '/lib/public/Preview/IProvider.php',
457457
'OCP\\Preview\\IProviderV2' => $baseDir . '/lib/public/Preview/IProviderV2.php',
458458
'OCP\\Preview\\IVersionedPreviewFile' => $baseDir . '/lib/public/Preview/IVersionedPreviewFile.php',
459+
'OCP\\Profile\\IActionManager' => $baseDir . '/lib/public/Profile/IActionManager.php',
460+
'OCP\\Profile\\IProfileAction' => $baseDir . '/lib/public/Profile/IProfileAction.php',
459461
'OCP\\Remote\\Api\\IApiCollection' => $baseDir . '/lib/public/Remote/Api/IApiCollection.php',
460462
'OCP\\Remote\\Api\\IApiFactory' => $baseDir . '/lib/public/Remote/Api/IApiFactory.php',
461463
'OCP\\Remote\\Api\\ICapabilitiesApi' => $baseDir . '/lib/public/Remote/Api/ICapabilitiesApi.php',
@@ -915,6 +917,7 @@
915917
'OC\\Core\\Controller\\OCJSController' => $baseDir . '/core/Controller/OCJSController.php',
916918
'OC\\Core\\Controller\\OCSController' => $baseDir . '/core/Controller/OCSController.php',
917919
'OC\\Core\\Controller\\PreviewController' => $baseDir . '/core/Controller/PreviewController.php',
920+
'OC\\Core\\Controller\\ProfileController' => $baseDir . '/core/Controller/ProfileController.php',
918921
'OC\\Core\\Controller\\RecommendedAppsController' => $baseDir . '/core/Controller/RecommendedAppsController.php',
919922
'OC\\Core\\Controller\\SearchController' => $baseDir . '/core/Controller/SearchController.php',
920923
'OC\\Core\\Controller\\SetupController' => $baseDir . '/core/Controller/SetupController.php',

lib/composer/composer/autoload_static.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -485,6 +485,8 @@ class ComposerStaticInit53792487c5a8370acc0b06b1a864ff4c
485485
'OCP\\Preview\\IProvider' => __DIR__ . '/../../..' . '/lib/public/Preview/IProvider.php',
486486
'OCP\\Preview\\IProviderV2' => __DIR__ . '/../../..' . '/lib/public/Preview/IProviderV2.php',
487487
'OCP\\Preview\\IVersionedPreviewFile' => __DIR__ . '/../../..' . '/lib/public/Preview/IVersionedPreviewFile.php',
488+
'OCP\\Profile\\IActionManager' => __DIR__ . '/../../..' . '/lib/public/Profile/IActionManager.php',
489+
'OCP\\Profile\\IProfileAction' => __DIR__ . '/../../..' . '/lib/public/Profile/IProfileAction.php',
488490
'OCP\\Remote\\Api\\IApiCollection' => __DIR__ . '/../../..' . '/lib/public/Remote/Api/IApiCollection.php',
489491
'OCP\\Remote\\Api\\IApiFactory' => __DIR__ . '/../../..' . '/lib/public/Remote/Api/IApiFactory.php',
490492
'OCP\\Remote\\Api\\ICapabilitiesApi' => __DIR__ . '/../../..' . '/lib/public/Remote/Api/ICapabilitiesApi.php',
@@ -944,6 +946,7 @@ class ComposerStaticInit53792487c5a8370acc0b06b1a864ff4c
944946
'OC\\Core\\Controller\\OCJSController' => __DIR__ . '/../../..' . '/core/Controller/OCJSController.php',
945947
'OC\\Core\\Controller\\OCSController' => __DIR__ . '/../../..' . '/core/Controller/OCSController.php',
946948
'OC\\Core\\Controller\\PreviewController' => __DIR__ . '/../../..' . '/core/Controller/PreviewController.php',
949+
'OC\\Core\\Controller\\ProfileController' => __DIR__ . '/../../..' . '/core/Controller/ProfileController.php',
947950
'OC\\Core\\Controller\\RecommendedAppsController' => __DIR__ . '/../../..' . '/core/Controller/RecommendedAppsController.php',
948951
'OC\\Core\\Controller\\SearchController' => __DIR__ . '/../../..' . '/core/Controller/SearchController.php',
949952
'OC\\Core\\Controller\\SetupController' => __DIR__ . '/../../..' . '/core/Controller/SetupController.php',
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?php
2+
/**
3+
* @copyright Copyright (c) 2021 John Molakvoæ <skjnldsv@protonmail.com>
4+
*
5+
* @author John Molakvoæ <skjnldsv@protonmail.com>
6+
*
7+
* @license GNU AGPL version 3 or any later version
8+
*
9+
* This program is free software: you can redistribute it and/or modify
10+
* it under the terms of the GNU Affero General Public License as
11+
* published by the Free Software Foundation, either version 3 of the
12+
* License, or (at your option) any later version.
13+
*
14+
* This program is distributed in the hope that it will be useful,
15+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17+
* GNU Affero General Public License for more details.
18+
*
19+
* You should have received a copy of the GNU Affero General Public License
20+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
21+
*
22+
*/
23+
24+
use OCP\Profile\IActionManager;
25+
use OCP\Profile\IProfileAction;
26+
27+
/**
28+
* @since 23
29+
*/
30+
class ActionManager implements IActionManager {
31+
32+
public function __construct() {}
33+
34+
/** @var array */
35+
protected $actions = [];
36+
37+
/**
38+
* @inheritDoc
39+
*/
40+
public function registerAction(IProfileAction $action) {
41+
$this->actions[] = $action;
42+
}
43+
44+
/**
45+
* @inheritDoc
46+
*/
47+
public function getActions(): array {
48+
return $this->actions;
49+
}
50+
}
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
<?php
2+
3+
use OCP\IL10N;
4+
use OCP\IURLGenerator;
5+
use OCP\Profile\IProfileAction;
6+
7+
/**
8+
* @copyright Copyright (c) 2021 John Molakvoæ <skjnldsv@protonmail.com>
9+
*
10+
* @author John Molakvoæ <skjnldsv@protonmail.com>
11+
*
12+
* @license GNU AGPL version 3 or any later version
13+
*
14+
* This program is free software: you can redistribute it and/or modify
15+
* it under the terms of the GNU Affero General Public License as
16+
* published by the Free Software Foundation, either version 3 of the
17+
* License, or (at your option) any later version.
18+
*
19+
* This program is distributed in the hope that it will be useful,
20+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
21+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22+
* GNU Affero General Public License for more details.
23+
*
24+
* You should have received a copy of the GNU Affero General Public License
25+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
26+
*
27+
*/
28+
29+
class EmailAction implements IProfileAction {
30+
31+
/** @var string */
32+
private $value;
33+
34+
/** @var IL10N */
35+
private $l10n;
36+
37+
/** @var IUrlGenerator */
38+
private $urlGenerator;
39+
40+
/**
41+
* Personal Section constructor.
42+
*
43+
* @param string $appName
44+
* @param IURLGenerator $urlGenerator
45+
* @param IL10N $l10n
46+
*/
47+
public function __construct(string $value,
48+
IL10N $l10n,
49+
IURLGenerator $urlGenerator) {
50+
$this->value = $value;
51+
$this->l10n = $l10n;
52+
$this->urlGenerator = $urlGenerator;
53+
}
54+
55+
public function getTitle(): string {
56+
return $this->l10n->t('Mail %s', [$this->value]);
57+
}
58+
59+
public function getPriority(): int {
60+
return 20;
61+
}
62+
63+
public function getIcon(): string {
64+
return 'icon-mail';
65+
}
66+
67+
public function getTarget(): string {
68+
return 'mailto:' . $this->value;
69+
}
70+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php
2+
/**
3+
* @copyright Copyright (c) 2021 John Molakvoæ <skjnldsv@protonmail.com>
4+
*
5+
* @author John Molakvoæ <skjnldsv@protonmail.com>
6+
*
7+
* @license GNU AGPL version 3 or any later version
8+
*
9+
* This program is free software: you can redistribute it and/or modify
10+
* it under the terms of the GNU Affero General Public License as
11+
* published by the Free Software Foundation, either version 3 of the
12+
* License, or (at your option) any later version.
13+
*
14+
* This program is distributed in the hope that it will be useful,
15+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17+
* GNU Affero General Public License for more details.
18+
*
19+
* You should have received a copy of the GNU Affero General Public License
20+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
21+
*
22+
*/
23+
namespace OCP\Profile;
24+
25+
/**
26+
* @since 23
27+
*/
28+
interface IActionManager {
29+
30+
/**
31+
* Register a new action for the user profile page
32+
*
33+
* @since 23
34+
*/
35+
public function registerAction(IProfileAction $action);
36+
37+
/**
38+
* Returns the list of all registered profile actions
39+
*
40+
* @since 23
41+
*/
42+
public function getActions(): array;
43+
}

0 commit comments

Comments
 (0)