Skip to content
This repository was archived by the owner on Jul 13, 2023. It is now read-only.

Commit 96016fd

Browse files
committed
Draft outline of the app
0 parents  commit 96016fd

9 files changed

+299
-0
lines changed

.php_cs.dist

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
require_once './vendor/autoload.php';
6+
7+
use Nextcloud\CodingStandard\Config;
8+
9+
$config = new Config();
10+
$config
11+
->getFinder()
12+
->notPath('build')
13+
->notPath('l10n')
14+
->notPath('src')
15+
->notPath('vendor')
16+
->notPath('lib/Vendor')
17+
->in(__DIR__);
18+
return $config;

appinfo/info.xml

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?xml version="1.0"?>
2+
<info xmlns:xsi= "http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:noNamespaceSchemaLocation="https://apps.nextcloud.com/schema/apps/info.xsd">
4+
<id>nmcloud_oidc</id>
5+
<name>NextMagentaCloud OpenID Connect user management util</name>
6+
<summary>Utility app for NextMagentaCloud to create OpenID connect users</summary>
7+
<description>This utility app supports NextMagentaCloud migration to create OpenID users with file content before actual first login.</description>
8+
<version>0.0.1</version>
9+
<licence>agpl</licence>
10+
<author>Bernd Rederlechner</author>
11+
<namespace>NextMagentaCloudOIDC</namespace>
12+
<types>
13+
<authentication/>
14+
</types>
15+
<category>integration</category>
16+
<category>social</category>
17+
<website>https://devops.telekom.de/nextmagentacloud/nmcloud_oidc</website>
18+
<bugs>https://jira.devops.telekom.de/projects/NMCLOUD/issues</bugs>
19+
<repository>https://devops.telekom.de/nextmagentacloud/nmcloud_oidc</repository>
20+
<dependencies>
21+
<nextcloud min-version="21" max-version="21"/>
22+
</dependencies>
23+
<!--settings>
24+
<admin>OCA\UserOIDC\Settings\AdminSettings</admin>
25+
<admin-section>OCA\UserOIDC\Settings\Section</admin-section>
26+
</settings-->
27+
</info>

appinfo/routes.php

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
/**
5+
* @copyright Copyright (c) 2020, Roeland Jago Douma <roeland@famdouma.nl>
6+
*
7+
* @author Bernd Rederlechner <bernd.rederlechner@t-systems.com>
8+
*
9+
* @license GNU AGPL version 3 or any later version
10+
*
11+
* This program is free software: you can redistribute it and/or modify
12+
* it under the terms of the GNU Affero General Public License as
13+
* published by the Free Software Foundation, either version 3 of the
14+
* License, or (at your option) any later version.
15+
*
16+
* This program is distributed in the hope that it will be useful,
17+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
18+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19+
* GNU Affero General Public License for more details.
20+
*
21+
* You should have received a copy of the GNU Affero General Public License
22+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
23+
*
24+
*/
25+
26+
return [
27+
return [
28+
'resources' => [
29+
'nmcuser' => ['url' => '/nmcuser']
30+
],
31+
'routes' => [
32+
'token' =>
33+
]
34+
];

lib/Controller/ApiControllerTrait.php

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
3+
namespace OCA\NextMagentaCloud\User\Controller;
4+
5+
use Closure;
6+
7+
use OCP\AppFramework\Http;
8+
use OCP\AppFramework\Http\DataResponse;
9+
10+
use OCA\NotesTutorial\Service\NotFoundException;
11+
12+
13+
trait ApiControllerTrait {
14+
15+
protected function handleNotFound (Closure $callback) {
16+
try {
17+
return new DataResponse($callback());
18+
} catch(NotFoundException $e) {
19+
$message = ['message' => $e->getMessage()];
20+
return new DataResponse($message, Http::STATUS_NOT_FOUND);
21+
}
22+
}
23+
24+
protected function handleException ($e) {
25+
if ($e instanceof DoesNotExistException ||
26+
$e instanceof MultipleObjectsReturnedException) {
27+
throw new NotFoundException($e->getMessage());
28+
} else {
29+
throw $e;
30+
}
31+
}
32+
33+
34+
}
+86
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
<?php
2+
namespace OCA\NextMagentaCloud\User\Controller;
3+
4+
use OCP\IRequest;
5+
use OCP\AppFramework\Http\DataResponse;
6+
use OCP\AppFramework\ApiController;
7+
8+
use OCA\NmcUserOidc\Service\NmcUserService;
9+
10+
class NmcUserApiController extends ApiController {
11+
use ApiControllerTrait;
12+
13+
private $service;
14+
private $userId;
15+
16+
public function __construct($appName,
17+
IRequest $request,
18+
NmcUserService $service, $userId){
19+
parent::__construct($appName, $request);
20+
$this->service = $service;
21+
$this->userId = $userId;
22+
}
23+
24+
/**
25+
* @CORS
26+
* @NoCSRFRequired
27+
* @NoAdminRequired
28+
*/
29+
public function index() {
30+
return new DataResponse($this->service->findAll($this->userId));
31+
}
32+
33+
/**
34+
* @CORS
35+
* @NoCSRFRequired
36+
* @NoAdminRequired
37+
*
38+
* @param int $id
39+
*/
40+
public function show($id) {
41+
return $this->handleNotFound(function () use ($id) {
42+
return $this->service->find($id, $this->userId);
43+
});
44+
}
45+
46+
/**
47+
* @CORS
48+
* @NoCSRFRequired
49+
* @NoAdminRequired
50+
*
51+
* @param string $title
52+
* @param string $content
53+
*/
54+
public function create($title, $content) {
55+
return $this->service->create($title, $content, $this->userId);
56+
}
57+
58+
/**
59+
* @CORS
60+
* @NoCSRFRequired
61+
* @NoAdminRequired
62+
*
63+
* @param int $id
64+
* @param string $title
65+
* @param string $content
66+
*/
67+
public function update($id, $title, $content) {
68+
return $this->handleNotFound(function () use ($id, $title, $content) {
69+
return $this->service->update($id, $title, $content, $this->userId);
70+
});
71+
}
72+
73+
/**
74+
* @CORS
75+
* @NoCSRFRequired
76+
* @NoAdminRequired
77+
*
78+
* @param int $id
79+
*/
80+
public function destroy($id) {
81+
return $this->handleNotFound(function () use ($id) {
82+
return $this->service->delete($id, $this->userId);
83+
});
84+
}
85+
86+
}

lib/Service/NmcUserService.php

+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
<?php
2+
namespace OCA\NextMagentaCloud\User\Service;
3+
4+
use Exception;
5+
6+
use OCP\Accounts\IAccountManager;
7+
use OCP\Accounts\IAccount;
8+
9+
class NmcUserService {
10+
11+
private $acountManager;
12+
13+
public function __construct(NoteMapper $mapper){
14+
$this->mapper = $mapper;
15+
}
16+
17+
public function findAll(string $userId) {
18+
return $this->mapper->findAll($userId);
19+
}
20+
21+
22+
public function find(int $id, string $userId) {
23+
try {
24+
$acc = $this->accountMgr->getAccount($userId);
25+
26+
// in order to be able to plug in different storage backends like files
27+
// for instance it is a good idea to turn storage related exceptions
28+
// into service related exceptions so controllers and service users
29+
// have to deal with only one type of exception
30+
} catch(Exception $e) {
31+
$this->handleException($e);
32+
}
33+
}
34+
35+
public function create(string $title, string $content, string $userId) {
36+
$note = new Note();
37+
$note->setTitle($title);
38+
$note->setContent($content);
39+
$note->setUserId($userId);
40+
return $this->mapper->insert($note);
41+
}
42+
43+
public function update(int $id, string $title, string $content, string $userId) {
44+
try {
45+
$note = $this->mapper->find($id, $userId);
46+
$note->setTitle($title);
47+
$note->setContent($content);
48+
return $this->mapper->update($note);
49+
} catch(Exception $e) {
50+
$this->handleException($e);
51+
}
52+
}
53+
54+
public function delete(int $id, string $userId) {
55+
try {
56+
$note = $this->mapper->find($id, $userId);
57+
$this->mapper->delete($note);
58+
return $note;
59+
} catch(Exception $e) {
60+
$this->handleException($e);
61+
}
62+
}
63+
64+
}

lib/Service/NotFoundException.php

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?php
2+
namespace namespace OCA\NextMagentaCloud\User\Service;
3+
4+
class NotFoundException extends ServiceException {}

lib/Service/ServiceException.php

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?php
2+
namespace namespace OCA\NextMagentaCloud\User\Service;
3+
4+
use Exception;
5+
6+
class ServiceException extends Exception {}

stylelint.config.js

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
module.exports = {
2+
extends: 'stylelint-config-recommended-scss',
3+
rules: {
4+
indentation: 'tab',
5+
'selector-type-no-unknown': null,
6+
'number-leading-zero': null,
7+
'rule-empty-line-before': [
8+
'always',
9+
{
10+
ignore: ['after-comment', 'inside-block']
11+
}
12+
],
13+
'declaration-empty-line-before': [
14+
'never',
15+
{
16+
ignore: ['after-declaration']
17+
}
18+
],
19+
'comment-empty-line-before': null,
20+
'selector-type-case': null,
21+
'selector-list-comma-newline-after': null,
22+
'no-descending-specificity': null,
23+
'string-quotes': 'single'
24+
},
25+
plugins: ['stylelint-scss']
26+
}

0 commit comments

Comments
 (0)