diff --git a/lib/Controller/GroupController.php b/lib/Controller/GroupController.php index 1e1235d..ed3d441 100644 --- a/lib/Controller/GroupController.php +++ b/lib/Controller/GroupController.php @@ -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; diff --git a/lib/Db/GroupPermission.php b/lib/Db/GroupPermission.php new file mode 100644 index 0000000..fd9c16a --- /dev/null +++ b/lib/Db/GroupPermission.php @@ -0,0 +1,24 @@ +addType('id','integer'); + } + + public function jsonSerialize() { + return [ + 'id' => $this->id, + 'gid' => $this->gid, + 'permissions' => $this->permissions, + ]; + } +} \ No newline at end of file diff --git a/lib/Db/GroupPermissionMapper.php b/lib/Db/GroupPermissionMapper.php new file mode 100644 index 0000000..e69a9ca --- /dev/null +++ b/lib/Db/GroupPermissionMapper.php @@ -0,0 +1,44 @@ +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); + } +} \ No newline at end of file diff --git a/lib/Migration/Version000001Date20210521125400.php b/lib/Migration/Version000001Date20210521125400.php index 45dab41..5c52954 100644 --- a/lib/Migration/Version000001Date20210521125400.php +++ b/lib/Migration/Version000001Date20210521125400.php @@ -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; diff --git a/lib/Service/GroupPermissionService.php b/lib/Service/GroupPermissionService.php new file mode 100644 index 0000000..5a44261 --- /dev/null +++ b/lib/Service/GroupPermissionService.php @@ -0,0 +1,63 @@ +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); + } + } + + +} \ No newline at end of file diff --git a/src/App.vue b/src/App.vue index 8ce0d84..e0a709f 100644 --- a/src/App.vue +++ b/src/App.vue @@ -7,7 +7,6 @@ - diff --git a/src/views/GroupManagement.vue b/src/views/GroupManagement.vue index 2edef86..711cb0f 100644 --- a/src/views/GroupManagement.vue +++ b/src/views/GroupManagement.vue @@ -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)