Gruppenpermissions
This commit is contained in:
parent
4a98164268
commit
a34e8f0e88
|
|
@ -9,6 +9,7 @@ use OCP\AppFramework\Http\DataResponse;
|
|||
use OCP\AppFramework\Controller;
|
||||
|
||||
use OCA\Agency\Service\GroupService;
|
||||
use OCA\Agency\Service\GroupPermissionService;
|
||||
use OCA\Agency\Agency\AgencyManager;
|
||||
|
||||
|
||||
|
|
@ -20,14 +21,16 @@ class GroupController extends Controller {
|
|||
protected $agencymanager;
|
||||
protected $userSession;
|
||||
protected $groupManager;
|
||||
protected $grouppermissionservice;
|
||||
use Errors;
|
||||
|
||||
public function __construct(string $AppName, IRequest $request,
|
||||
GroupService $service, AgencyManager $agencymanager, IGroupManager $groupManager){
|
||||
GroupService $service, GroupPermissionService $grouppermissionservice, AgencyManager $agencymanager, IGroupManager $groupManager){
|
||||
parent::__construct($AppName, $request);
|
||||
$this->service = $service;
|
||||
$this->agencymanager = $agencymanager;
|
||||
$this->groupManager = $groupManager;
|
||||
$this->grouppermissionservice = $grouppermissionservice;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -81,6 +84,8 @@ class GroupController extends Controller {
|
|||
|
||||
$newGroup = $this->groupManager->createGroup($newGroupId);
|
||||
$newGroup->setDisplayName($groupname);
|
||||
//Create the grouppermission-element
|
||||
$this->grouppermissionservice->create($newGroupId);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
@ -104,7 +109,8 @@ class GroupController extends Controller {
|
|||
# If user is in the same Agency, then delete
|
||||
# TODO: Hier noch einbauen, dass die Rechte geprüft werden!
|
||||
if(str_contains($todel->getGID(), $searchGroupId)) {
|
||||
$todel->delete();
|
||||
# TODO: Hier das löschen der GroupPermission mit verwalten, wenn eine Gruppe gelöscht wird!
|
||||
// $todel->delete();
|
||||
$result = true;
|
||||
}
|
||||
return $result;
|
||||
|
|
|
|||
|
|
@ -0,0 +1,24 @@
|
|||
<?php
|
||||
namespace OCA\Agency\Db;
|
||||
|
||||
use JsonSerializable;
|
||||
|
||||
use OCP\AppFramework\Db\Entity;
|
||||
|
||||
class GroupPermission extends Entity implements JsonSerializable {
|
||||
|
||||
protected $gid;
|
||||
protected $permissions;
|
||||
|
||||
public function __construct() {
|
||||
$this->addType('id','integer');
|
||||
}
|
||||
|
||||
public function jsonSerialize() {
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'gid' => $this->gid,
|
||||
'permissions' => $this->permissions,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,44 @@
|
|||
<?php
|
||||
namespace OCA\Agency\Db;
|
||||
|
||||
use OCP\IDBConnection;
|
||||
use OCP\AppFramework\Db\QBMapper;
|
||||
|
||||
class GroupPermissionMapper extends QBMapper {
|
||||
|
||||
public function __construct(IDBConnection $db) {
|
||||
parent::__construct($db, 'grouppermission', GroupPermission::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 findbygid(string $gid) {
|
||||
$qb = $this->db->getQueryBuilder();
|
||||
|
||||
$qb->select('*')
|
||||
->from($this->getTableName())
|
||||
->where(
|
||||
$qb->expr()->eq('gid', $qb->createNamedParameter($gid))
|
||||
);
|
||||
|
||||
return $this->findEntity($qb);
|
||||
}
|
||||
|
||||
public function remove(int $id) {
|
||||
$db = $this->db->getQueryBuilder();
|
||||
$db->delete($this->getTableName())
|
||||
->where($db->expr()->eq('id', $query->createNamedParameter($id)));
|
||||
|
||||
return $this->findEntity($qb);
|
||||
}
|
||||
}
|
||||
|
|
@ -79,6 +79,28 @@
|
|||
'length' => 200
|
||||
]);
|
||||
|
||||
$table->setPrimaryKey(['id']);
|
||||
}
|
||||
|
||||
if (!$schema->hasTable('grouppermission')) {
|
||||
$table = $schema->createTable('grouppermission');
|
||||
|
||||
$table->addColumn('id', 'integer', [
|
||||
'autoincrement' => true,
|
||||
'notnull' => true,
|
||||
]);
|
||||
|
||||
$table->addColumn('gid', 'string', [
|
||||
'notnull' => false,
|
||||
'length' => 500
|
||||
]);
|
||||
|
||||
$table->addColumn('permissions', 'string', [
|
||||
'notnull' => false,
|
||||
'length' => 10000
|
||||
]);
|
||||
|
||||
|
||||
$table->setPrimaryKey(['id']);
|
||||
}
|
||||
return $schema;
|
||||
|
|
|
|||
|
|
@ -0,0 +1,63 @@
|
|||
<?php
|
||||
namespace OCA\Agency\Service;
|
||||
|
||||
use Exception;
|
||||
|
||||
use OCP\AppFramework\Db\DoesNotExistException;
|
||||
use OCP\AppFramework\Db\MultipleObjectsReturnedException;
|
||||
|
||||
use OCA\Agency\Db\GroupPermission;
|
||||
use OCA\Agency\Db\GroupPermissionMapper;
|
||||
|
||||
|
||||
class GroupPermissionService {
|
||||
|
||||
private $mapper;
|
||||
|
||||
public function __construct(GroupPermissionMapper $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
|
||||
public function find(int $id) {
|
||||
try {
|
||||
return $this->mapper->find($id);
|
||||
} catch(Exception $e) {
|
||||
$this->handleException($e);
|
||||
}
|
||||
}
|
||||
|
||||
//Create an Agency
|
||||
public function create(string $gid, string $permission = "") {
|
||||
$grouppermission = new GroupPermission();
|
||||
$grouppermission->setGid($gid);
|
||||
return $this->mapper->insert($grouppermission);
|
||||
}
|
||||
|
||||
public function findbygid(string $gid){
|
||||
try {
|
||||
return $this->mapper->findbygid($gid);
|
||||
} catch(Exception $e) {
|
||||
$this->handleException($e);
|
||||
}
|
||||
}
|
||||
|
||||
public function remove(int $id){
|
||||
try {
|
||||
return $this->mapper->remove($id);
|
||||
} catch(Exception $e) {
|
||||
$this->handleException($e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -7,7 +7,6 @@
|
|||
</AppContent>
|
||||
</Content>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import Content from '@nextcloud/vue/dist/Components/Content'
|
||||
import AppNavigation from './components/Navigation'
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@
|
|||
accordion="groupaccordion"
|
||||
role="tabpanel">
|
||||
<b-card-body>
|
||||
<Permission :groupid="group.gid" />
|
||||
The GroupId is {{ group.gid }} <br>
|
||||
<span v-if="group.isDefault">Ist default</span>
|
||||
<span v-else>Nicht default</span>
|
||||
|
|
@ -30,10 +31,12 @@
|
|||
<script>
|
||||
import { generateUrl } from '@nextcloud/router'
|
||||
import axios from '@nextcloud/axios'
|
||||
import Permission from './Permission'
|
||||
|
||||
export default {
|
||||
name: 'Group',
|
||||
components: {
|
||||
Permission,
|
||||
},
|
||||
// Properties of Group-Elements
|
||||
props: {
|
||||
|
|
@ -60,6 +63,7 @@ export default {
|
|||
async delGroupFinal(id) {
|
||||
const r = await axios.get(generateUrl('/apps/agency/delagencygroup/' + this.group.gid))
|
||||
console.log(r)
|
||||
// TODO: Hier eine Mitteilung einbauen, damit der User weiß, was abging
|
||||
this.$emit('updateGroupData')
|
||||
},
|
||||
delGroup(id) {
|
||||
|
|
|
|||
|
|
@ -0,0 +1,26 @@
|
|||
<template>
|
||||
<p>
|
||||
Ich bin eine Permission {{ groupid }}
|
||||
</p>
|
||||
</template>
|
||||
<script>
|
||||
|
||||
export default {
|
||||
name: 'Permission',
|
||||
components: {
|
||||
},
|
||||
// Properties of Group-Elements
|
||||
props: {
|
||||
groupid: {
|
||||
type: String,
|
||||
default: '',
|
||||
},
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
},
|
||||
}
|
||||
</script>
|
||||
|
|
@ -66,7 +66,6 @@ export default ({
|
|||
const groupResponse = await axios.get(generateUrl('/apps/agency/getagencygroups'))
|
||||
this.groups = groupResponse.data
|
||||
this.isLoading = true
|
||||
console.log('Some reload happen...')
|
||||
},
|
||||
async submitHandler(data) {
|
||||
const response = await axios.put(generateUrl('/apps/agency/addagencygroup'), data)
|
||||
|
|
|
|||
Loading…
Reference in New Issue