-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Georg Ehrke <developer@georgehrke.com>
- Loading branch information
1 parent
b9d17cf
commit fb878f5
Showing
25 changed files
with
1,880 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* @copyright Copyright (c) 2020, Georg Ehrke | ||
* | ||
* @author Georg Ehrke <oc.list@georgehrke.com> | ||
* | ||
* @license AGPL-3.0 | ||
* | ||
* This code is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License, version 3, | ||
* as published by the Free Software Foundation. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License, version 3, | ||
* along with this program. If not, see <http://www.gnu.org/licenses/> | ||
* | ||
*/ | ||
|
||
use OCA\UserStatus\AppInfo\Application; | ||
|
||
/** @var Application $app */ | ||
$app = \OC::$server->query(Application::class); | ||
$app->registerCapabilities(); | ||
$app->registerEvents(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?xml version="1.0"?> | ||
<info xmlns:xsi= "http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:noNamespaceSchemaLocation="https://apps.nextcloud.com/schema/apps/info.xsd"> | ||
<id>user_status</id> | ||
<name>User Status</name> | ||
<summary>User Status</summary> | ||
<description><![CDATA[User Status]]></description> | ||
<version>0.0.1</version> | ||
<licence>agpl</licence> | ||
<author mail="oc.list@georgehrke.com" >Georg Ehrke</author> | ||
<namespace>UserStatus</namespace> | ||
<default_enable/> | ||
<category>social</category> | ||
<bugs>https://github.com/nextcloud/server</bugs> | ||
<dependencies> | ||
<nextcloud min-version="20" max-version="20"/> | ||
</dependencies> | ||
</info> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* @copyright Copyright (c) 2020, Georg Ehrke | ||
* | ||
* @author Georg Ehrke <oc.list@georgehrke.com> | ||
* | ||
* @license AGPL-3.0 | ||
* | ||
* This code is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License, version 3, | ||
* as published by the Free Software Foundation. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License, version 3, | ||
* along with this program. If not, see <http://www.gnu.org/licenses/> | ||
* | ||
*/ | ||
|
||
return [ | ||
'ocs' => [ | ||
// Routes for querying statuses | ||
['name' => 'Statuses#findAll', 'url' => '/api/v1/statuses', 'verb' => 'GET'], | ||
['name' => 'Statuses#find', 'url' => '/api/v1/statuses/{userId}', 'verb' => 'GET'], | ||
// Routes for manipulating your own status | ||
['name' => 'UserStatus#getStatus', 'url' => '/api/v1/user_status', 'verb' => 'GET'], | ||
['name' => 'UserStatus#setStatus', 'url' => '/api/v1/user_status', 'verb' => 'PUT'], | ||
['name' => 'UserStatus#learStatus', 'url' => '/api/v1/user_status', 'verb' => 'DELETE'], | ||
], | ||
]; |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* @copyright Copyright (c) 2020, Georg Ehrke | ||
* | ||
* @author Georg Ehrke <oc.list@georgehrke.com> | ||
* | ||
* @license AGPL-3.0 | ||
* | ||
* This code is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License, version 3, | ||
* as published by the Free Software Foundation. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License, version 3, | ||
* along with this program. If not, see <http://www.gnu.org/licenses/> | ||
* | ||
*/ | ||
|
||
namespace OCA\UserStatus\AppInfo; | ||
|
||
use OCA\UserStatus\Capabilities; | ||
use OCA\UserStatus\Listener\UserDeletedListener; | ||
use OCP\AppFramework\App; | ||
use OCP\EventDispatcher\IEventDispatcher; | ||
use OCP\User\Events\UserDeletedEvent; | ||
|
||
/** | ||
* Class Application | ||
* | ||
* @package OCA\UserStatus\AppInfo | ||
*/ | ||
class Application extends App { | ||
|
||
/** @var string */ | ||
public const APP_ID = 'user_status'; | ||
|
||
/** | ||
* Application constructor. | ||
* | ||
* @param array $urlParams | ||
*/ | ||
public function __construct(array $urlParams = []) { | ||
parent::__construct(self::APP_ID, $urlParams); | ||
} | ||
|
||
/** | ||
* Registers capabilities that will be exposed | ||
* via the OCS API endpoint | ||
*/ | ||
public function registerCapabilities(): void { | ||
$this->getContainer() | ||
->registerCapability(Capabilities::class); | ||
} | ||
|
||
/** | ||
* Registers a listener for the user-delete event | ||
* to automatically delete a user's status on | ||
* account deletion | ||
*/ | ||
public function registerEvents(): void { | ||
/** @var IEventDispatcher $dispatcher */ | ||
$dispatcher = $this->getContainer() | ||
->query(IEventDispatcher::class); | ||
|
||
$dispatcher->addServiceListener(UserDeletedEvent::class, UserDeletedListener::class); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* @copyright Copyright (c) 2020, Georg Ehrke | ||
* | ||
* @author Georg Ehrke <oc.list@georgehrke.com> | ||
* | ||
* @license AGPL-3.0 | ||
* | ||
* This code is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License, version 3, | ||
* as published by the Free Software Foundation. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License, version 3, | ||
* along with this program. If not, see <http://www.gnu.org/licenses/> | ||
* | ||
*/ | ||
namespace OCA\UserStatus; | ||
|
||
use OCP\Capabilities\ICapability; | ||
|
||
class Capabilities implements ICapability { | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
public function getCapabilities() { | ||
return [ | ||
'user_status' => [ | ||
'enabled' => true, | ||
] | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* @copyright Copyright (c) 2020, Georg Ehrke | ||
* | ||
* @author Georg Ehrke <oc.list@georgehrke.com> | ||
* | ||
* @license AGPL-3.0 | ||
* | ||
* This code is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License, version 3, | ||
* as published by the Free Software Foundation. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License, version 3, | ||
* along with this program. If not, see <http://www.gnu.org/licenses/> | ||
* | ||
*/ | ||
|
||
namespace OCA\UserStatus\Controller; | ||
|
||
use OCA\UserStatus\Service\StatusService; | ||
use OCP\AppFramework\Db\DoesNotExistException; | ||
use OCP\AppFramework\Http\DataResponse; | ||
use OCP\AppFramework\OCS\OCSNotFoundException; | ||
use OCP\AppFramework\OCSController; | ||
use OCP\IRequest; | ||
|
||
class StatusesController extends OCSController { | ||
|
||
/** @var StatusService */ | ||
private $service; | ||
|
||
/** | ||
* StatusesController constructor. | ||
* | ||
* @param string $appName | ||
* @param IRequest $request | ||
* @param StatusService $service | ||
*/ | ||
public function __construct(string $appName, | ||
IRequest $request, | ||
StatusService $service) { | ||
parent::__construct($appName, $request); | ||
$this->service = $service; | ||
} | ||
|
||
/** | ||
* @param int|null $limit | ||
* @param int|null $offset | ||
* @return DataResponse | ||
*/ | ||
public function findAll(?int $limit=null, ?int $offset=null): DataResponse { | ||
return new DataResponse($this->service->findAll($limit, $offset)); | ||
} | ||
|
||
/** | ||
* @param string $userId | ||
* @return DataResponse | ||
* @throws OCSNotFoundException | ||
*/ | ||
public function find(string $userId): DataResponse { | ||
try { | ||
$userStatus = $this->service->findByUserId($userId); | ||
} catch (DoesNotExistException $ex) { | ||
throw new OCSNotFoundException('No status for the requested userId'); | ||
} | ||
|
||
return new DataResponse($userStatus); | ||
} | ||
} |
Oops, something went wrong.