Skip to content

Commit

Permalink
Add user-status app
Browse files Browse the repository at this point in the history
Signed-off-by: Georg Ehrke <developer@georgehrke.com>
  • Loading branch information
georgehrke committed Jun 3, 2020
1 parent b9d17cf commit fb878f5
Show file tree
Hide file tree
Showing 25 changed files with 1,880 additions and 0 deletions.
31 changes: 31 additions & 0 deletions apps/user_status/appinfo/app.php
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();
18 changes: 18 additions & 0 deletions apps/user_status/appinfo/info.xml
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>
36 changes: 36 additions & 0 deletions apps/user_status/appinfo/routes.php
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'],
],
];
56 changes: 56 additions & 0 deletions apps/user_status/img/app.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
74 changes: 74 additions & 0 deletions apps/user_status/lib/AppInfo/Application.php
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);
}
}
41 changes: 41 additions & 0 deletions apps/user_status/lib/Capabilities.php
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,
]
];
}
}
77 changes: 77 additions & 0 deletions apps/user_status/lib/Controller/StatusesController.php
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);
}
}
Loading

0 comments on commit fb878f5

Please sign in to comment.