Änderungen an Datensatz und Vorbereitungen für Reg
This commit is contained in:
parent
9cbd03ce17
commit
dfd79d1048
|
|
@ -5,7 +5,7 @@
|
|||
<name>Agency</name>
|
||||
<summary>App for managing Agency of DA</summary>
|
||||
<description><![CDATA[test]]></description>
|
||||
<version>0.0.1</version>
|
||||
<version>0.0.2</version>
|
||||
<licence></licence>
|
||||
<namespace>Agency</namespace>
|
||||
<category>tools</category>
|
||||
|
|
|
|||
|
|
@ -6,5 +6,6 @@ return [
|
|||
'routes' => [
|
||||
['name' => 'page#index', 'url' => '/', 'verb' => 'GET'],
|
||||
['name' => 'agency#getagencyidbyuser', 'url' => '/getagencyidbyuser', 'verb' => 'GET'],
|
||||
['name' => 'test#filetest', 'url' => '/filetest', 'verb' => 'GET'],
|
||||
]
|
||||
];
|
||||
|
|
|
|||
|
|
@ -0,0 +1,24 @@
|
|||
<?php
|
||||
namespace OCA\Agency\Agency;
|
||||
|
||||
use OCP\IDBConnection;
|
||||
use OCA\Agency\Db\AgencyMapper;
|
||||
use OCA\Agency\Service\AgencyService;
|
||||
|
||||
class AgencyManager {
|
||||
|
||||
protected $agencyMapper;
|
||||
protected $db;
|
||||
|
||||
public function __construct(IDBConnection $db) {
|
||||
$this->appName = $appName;
|
||||
$this->agencyMapper = new AgencyMapper($db);
|
||||
}
|
||||
|
||||
public function createAgencyOnReg(string $agencygid, string $agencydirid, string $standarddirid){
|
||||
|
||||
$agencyService = new AgencyService($this->agencyMapper);
|
||||
return $agencyService->create(null, null, null, null, null, null, null, $agencygid, $agencydirid, $standarddirid);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -10,23 +10,20 @@ use OCP\AppFramework\Http\JSONResponse;
|
|||
use OCP\AppFramework\Controller;
|
||||
|
||||
use OCA\Agency\Service\AgencyService;
|
||||
use OCA\Agency\Service\AgencyUserService;
|
||||
|
||||
class AgencyController extends Controller {
|
||||
|
||||
protected $userManager;
|
||||
private $service;
|
||||
private $agencyuserservice;
|
||||
private $Id;
|
||||
protected $userSession;
|
||||
protected $request;
|
||||
|
||||
use Errors;
|
||||
|
||||
public function __construct(string $AppName, IRequest $request, IUserSession $userSession, AgencyService $service, AgencyUserService $agencyuserservice){
|
||||
public function __construct(string $AppName, IRequest $request, IUserSession $userSession, AgencyService $service){
|
||||
parent::__construct($AppName, $request);
|
||||
$this->service = $service;
|
||||
$this->agencyuserservice = $agencyuserservice;
|
||||
$this->userSession = $userSession;
|
||||
$this->request = $request;
|
||||
}
|
||||
|
|
@ -38,16 +35,6 @@ class AgencyController extends Controller {
|
|||
return new DataResponse($this->service->findAll($this->Id));
|
||||
}
|
||||
|
||||
/**
|
||||
* @NoAdminRequired
|
||||
* @NoCSRFRequired
|
||||
*/
|
||||
public function getagencyidbyuser() {
|
||||
$user = $this->userSession->getUser()->getUid();
|
||||
$params = $this->agencyuserservice->getAgencyIdByUserUid($user);
|
||||
return new JSONResponse($params);
|
||||
}
|
||||
|
||||
/**
|
||||
* @NoAdminRequired
|
||||
* @NoCSRFRequired
|
||||
|
|
@ -63,11 +50,20 @@ class AgencyController extends Controller {
|
|||
/**
|
||||
* @NoAdminRequired
|
||||
*
|
||||
* @param string $title
|
||||
* @param string $content
|
||||
* @param string $name
|
||||
* @param string $inhaber
|
||||
* @param string $street
|
||||
* @param string $plz
|
||||
* @param string $city
|
||||
* @param string $agencymail
|
||||
* @param string $phone
|
||||
* @param string $agencygid
|
||||
* @param string $agencydirid
|
||||
* @param string $standarddirid
|
||||
*
|
||||
*/
|
||||
public function create(string $name, string $inhaber, string $street, string $plz, string $city, string $agencymail, string $phone) {
|
||||
return $this->service->create($name, $inhaber, $street, $plz, $city, $agencymail, $phone);
|
||||
public function create(string $name = null, string $inhaber = null, string $street = null, string $plz = null, string $city = null, string $agencymail = null, string $phone = null, string $agencygid, string $agencydirid, string $standarddirid) {
|
||||
return $this->service->create($name, $inhaber, $street, $plz, $city, $agencymail, $phone, $agencygid, $agencydirid, $standarddirid);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -80,13 +76,7 @@ class AgencyController extends Controller {
|
|||
public function update(int $id, string $name, string $inhaber, string $street, string $plz, string $city, string $agencymail, string $phone) {
|
||||
return $this->handleNotFound(function () use ($id, $name, $inhaber, $street, $plz, $city, $agencymail, $phone) {
|
||||
# TODO: ABfrage machen!
|
||||
if($this->agencyuserservice->checkAgencyIdUserId($this->userSession->getUser()->getUid(), $id)){
|
||||
return $this->service->update($id, $name, $inhaber, $street, $plz, $city, $agencymail, $phone);
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,36 @@
|
|||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace OCA\Agency\Controller;
|
||||
|
||||
use OCP\IRequest;
|
||||
use OCP\AppFramework\Http\TemplateResponse;
|
||||
use OCP\AppFramework\Controller;
|
||||
use OCP\Util;
|
||||
use OCP\AppFramework\Http\JSONResponse;
|
||||
use OCP\AppFramework\Http\DataResponse;
|
||||
|
||||
use OCA\Agency\Agency\AgencyManager;
|
||||
use OCP\IDBConnection;
|
||||
|
||||
class TestController extends Controller {
|
||||
|
||||
protected $appName;
|
||||
protected $agencyManager;
|
||||
|
||||
public function __construct($appName, IRequest $request, IDBConnection $db) {
|
||||
parent::__construct($appName, $request);
|
||||
$this->appName = $appName;
|
||||
$this->agencyManager = new AgencyManager($db);
|
||||
}
|
||||
|
||||
/**
|
||||
* @NoAdminRequired
|
||||
* @NoCSRFRequired
|
||||
*/
|
||||
public function filetest() {
|
||||
# TODO: Diese Erstellung hier portieren, damit bei neuem User auch eine neue Agentur mit den Infos zur GruppenID und den Ordner-IDs für Standards und Dateien erstellt wird
|
||||
return $this->agencyManager->createAgencyOnReg("0","0","0");
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -14,6 +14,9 @@ class Agency extends Entity implements JsonSerializable {
|
|||
protected $city;
|
||||
protected $agencymail;
|
||||
protected $phone;
|
||||
protected $agencygid;
|
||||
protected $agencydirid;
|
||||
protected $standarddirid;
|
||||
|
||||
public function __construct() {
|
||||
$this->addType('id','integer');
|
||||
|
|
@ -29,6 +32,9 @@ class Agency extends Entity implements JsonSerializable {
|
|||
'city' => $this->city,
|
||||
'agencymail' => $this->agencymail,
|
||||
'phone' => $this->phone,
|
||||
'agencygid' => $this->agencygid,
|
||||
'agencydirid' => $this->agencydirid,
|
||||
'standarddirid' => $this->standarddirid,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
@ -1,24 +0,0 @@
|
|||
<?php
|
||||
namespace OCA\Agency\Db;
|
||||
|
||||
use JsonSerializable;
|
||||
|
||||
use OCP\AppFramework\Db\Entity;
|
||||
|
||||
class AgencyUser extends Entity implements JsonSerializable {
|
||||
|
||||
protected $agency;
|
||||
protected $user;
|
||||
|
||||
public function __construct() {
|
||||
$this->addType('id','integer');
|
||||
}
|
||||
|
||||
public function jsonSerialize() {
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'agency' => $this->agency,
|
||||
'user' => $this->user,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
@ -1,34 +0,0 @@
|
|||
<?php
|
||||
namespace OCA\Agency\Db;
|
||||
|
||||
use OCP\IDBConnection;
|
||||
use OCP\AppFramework\Db\QBMapper;
|
||||
use OCP\DB\QueryBuilder\IQueryBuilder;
|
||||
|
||||
class AgencyUserMapper extends QBMapper {
|
||||
|
||||
public function __construct(IDBConnection $db) {
|
||||
parent::__construct($db, 'agency_user', AgencyUser::class);
|
||||
}
|
||||
|
||||
public function find(int $id) {
|
||||
$qb = $this->db->getQueryBuilder();
|
||||
|
||||
$qb->select('*')
|
||||
->from($this->getTableName())
|
||||
->where(
|
||||
$qb->expr()->eq('id', $qb->createNamedParameter($id))
|
||||
);
|
||||
return $this->findEntity($qb);
|
||||
}
|
||||
|
||||
public function getAgencyIdByUserUid(string $useruid) {
|
||||
$qb = $this->db->getQueryBuilder();
|
||||
$qb->select('*')
|
||||
->from($this->getTableName())
|
||||
->where(
|
||||
$qb->expr()->eq('user', $qb->createNamedParameter($useruid))
|
||||
);
|
||||
return $this->findEntity($qb);
|
||||
}
|
||||
}
|
||||
|
|
@ -37,7 +37,7 @@ class AgencyService {
|
|||
}
|
||||
|
||||
//Create an Agency
|
||||
public function create(string $name, string $inhaber, string $street, string $plz, string $city, string $agencymail, string $phone) {
|
||||
public function create(string $name = null, string $inhaber = null, string $street = null, string $plz = null, string $city = null, string $agencymail = null, string $phone = null, string $agencygid, string $agencydirid, string $standarddirid) {
|
||||
$agency = new Agency();
|
||||
$agency->setName($name);
|
||||
$agency->setInhaber($inhaber);
|
||||
|
|
@ -46,6 +46,9 @@ class AgencyService {
|
|||
$agency->setCity($city);
|
||||
$agency->setAgencymail($agencymail);
|
||||
$agency->setPhone($phone);
|
||||
$agency->setAgencygid($agencygid);
|
||||
$agency->setAgencydirid($agencydirid);
|
||||
$agency->setStandarddirid($standarddirid);
|
||||
return $this->mapper->insert($agency);
|
||||
}
|
||||
//Update an Agency
|
||||
|
|
|
|||
|
|
@ -1,53 +0,0 @@
|
|||
<?php
|
||||
namespace OCA\Agency\Service;
|
||||
|
||||
use Exception;
|
||||
|
||||
use OCP\AppFramework\Db\DoesNotExistException;
|
||||
use OCP\AppFramework\Db\MultipleObjectsReturnedException;
|
||||
|
||||
use OCA\Agency\Db\AgencyUser;
|
||||
use OCA\Agency\Db\AgencyUserMapper;
|
||||
|
||||
|
||||
class AgencyUserService {
|
||||
|
||||
private $mapper;
|
||||
|
||||
public function __construct(AgencyUserMapper $mapper){
|
||||
$this->mapper = $mapper;
|
||||
}
|
||||
|
||||
private function handleException ($e) {
|
||||
if ($e instanceof DoesNotExistException ||
|
||||
$e instanceof MultipleObjectsReturnedException) {
|
||||
throw new NotFoundException($e->getMessage());
|
||||
} else {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
//Find an Agency-User
|
||||
public function find(int $id) {
|
||||
try {
|
||||
return $this->mapper->find($id);
|
||||
} catch(Exception $e) {
|
||||
$this->handleException($e);
|
||||
}
|
||||
}
|
||||
|
||||
//Find an Agency-User
|
||||
public function getAgencyIdByUserUid(string $useruid) {
|
||||
try {
|
||||
return $this->mapper->getAgencyIdByUserUid($useruid);
|
||||
} catch(Exception $e) {
|
||||
$this->handleException($e);
|
||||
}
|
||||
}
|
||||
|
||||
//Checks, if a given User is in given Agency. Use for secure reason to make save, that agencydata is only changed by user which belongs to that agency.
|
||||
public function checkAgencyIdUserId(string $useruid, int $agencyid){
|
||||
# TODO: Hier einmal prüfen, dass der eingeloggte Nutzer auch zur angefragten Agentur passt!
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
@ -7,6 +7,9 @@
|
|||
<AppNavigationItem to="/groupmanagement"
|
||||
title="Gruppenverwaltung"
|
||||
icon="icon-category-customization" />
|
||||
<AppNavigationItem to="/testing"
|
||||
title="Tests"
|
||||
icon="icon-category-customization" />
|
||||
</template>
|
||||
</AppNavigation>
|
||||
</template>
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
import AgencyData from '../views/AgencyData'
|
||||
import Testing from '../views/Testing'
|
||||
import GroupManagement from '../views/GroupManagement'
|
||||
|
||||
export default [
|
||||
|
|
@ -12,4 +13,9 @@ export default [
|
|||
name: 'groupmanagemenet',
|
||||
component: GroupManagement,
|
||||
},
|
||||
{
|
||||
path: '/testing',
|
||||
name: 'testing',
|
||||
component: Testing,
|
||||
},
|
||||
]
|
||||
|
|
|
|||
|
|
@ -0,0 +1,37 @@
|
|||
<template>
|
||||
<Content app-name="Testing">
|
||||
<b-container class="bv-example-row">
|
||||
<h3>Allgemeine Tests für den ganzen stuff</h3>
|
||||
</b-container>
|
||||
<button @click="action">
|
||||
Action
|
||||
</button>
|
||||
</Content>
|
||||
</template>
|
||||
<script>
|
||||
import Content from '@nextcloud/vue/dist/Components/Content'
|
||||
import { generateUrl } from '@nextcloud/router'
|
||||
const axios = require('axios').default
|
||||
// import '@braid/vue-formulate/themes/snow/snow.scss'
|
||||
// import { generateUrl } from '@nextcloud/router'
|
||||
// const axios = require('axios').default
|
||||
|
||||
export default ({
|
||||
name: 'Testing',
|
||||
components: {
|
||||
Content,
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
action() {
|
||||
axios.get(generateUrl('/apps/agency/filetest')).then(function(resp) {
|
||||
console.log(resp)
|
||||
})
|
||||
|
||||
},
|
||||
},
|
||||
})
|
||||
</script>
|
||||
Loading…
Reference in New Issue