diff --git a/src/inc/apiv2/common/AbstractBaseAPI.class.php b/src/inc/apiv2/common/AbstractBaseAPI.class.php index 77530725c..99a9121c5 100644 --- a/src/inc/apiv2/common/AbstractBaseAPI.class.php +++ b/src/inc/apiv2/common/AbstractBaseAPI.class.php @@ -111,6 +111,19 @@ final protected function getUser() return $this->user; } + /** + * Available 'expand' parameters on $object + */ + public function getExpandables(): array { + return []; + } + + + /** + * Process $expand on $object + */ + protected function doExpand(object $object, string $expand): mixed { + } /** * Retrieve permissions based on expand section @@ -300,7 +313,7 @@ protected function obj2Array(mixed $obj) /** * Quirck to resolve objects via ManyToMany relation table */ - private function joinQuery(mixed $objFactory, DBA\QueryFilter $qF, DBA\JoinFilter $jF): array + protected function joinQuery(mixed $objFactory, DBA\QueryFilter $qF, DBA\JoinFilter $jF): array { $joined = $objFactory->filter([Factory::FILTER => $qF, Factory::JOIN => $jF]); $objects = $joined[$objFactory->getModelName()]; @@ -313,185 +326,36 @@ private function joinQuery(mixed $objFactory, DBA\QueryFilter $qF, DBA\JoinFilte return $ret; } + /** + * Quirck to resolve objects via ForeignKey relation table + */ + protected function filterQuery(mixed $objFactory, DBA\QueryFilter $qF): array + { + $joined = $objFactory->filter([Factory::FILTER => $qF]); + $objects = $joined[$objFactory->getModelName()]; + + $ret = []; + foreach ($objects as $object) { + array_push($ret, $this->obj2Array($object)); + } + + return $ret; + } + + /** * Expands object items */ protected function object2Array(mixed $object, array $expand) { $item = $this->obj2Array($object); - $features = $this->getFeatures(); - /* TODO Refactor expansions logic to class objects */ foreach ($expand as $NAME) { - switch ($NAME) { - case 'agent': - $obj = Factory::getAgentFactory()->get($item['agentId']); - $item[$NAME] = $this->obj2Array($obj); - break; - case 'agents': - $obj = Factory::getAccessGroupFactory()->get($item['accessGroupId']); - $item[$NAME] = $this->obj2Array($obj); - break; - case 'agentstats': - $qFs = []; - $qFs[] = new QueryFilter(AgentStat::AGENT_ID, $item['agentId'], "="); - $agentstats = Factory::getAgentStatFactory()->filter([Factory::FILTER => $qFs]); - $item[$NAME] = array_map(array($this, 'obj2Array'), $agentstats); - break; - case 'accessGroups': - if (get_class($object) == User::class) { - /* M2M via AccessGroupUser */ - $qF = new QueryFilter(AccessGroupUser::USER_ID, $item['id'], "=", Factory::getAccessGroupUserFactory()); - $jF = new JoinFilter(Factory::getAccessGroupUserFactory(), AccessGroup::ACCESS_GROUP_ID, AccessGroupUser::ACCESS_GROUP_ID); - } else { - /* M2M via AccessGroupAgent */ - $qF = new QueryFilter(AccessGroupAgent::AGENT_ID, $item[Agent::AGENT_ID], "=", Factory::getAccessGroupAgentFactory()); - $jF = new JoinFilter(Factory::getAccessGroupAgentFactory(), AccessGroup::ACCESS_GROUP_ID, AccessGroupAgent::ACCESS_GROUP_ID); - } - $item[$NAME] = $this->joinQuery(Factory::getAccessGroupFactory(), $qF, $jF); - break; - case 'accessGroup': - $obj = Factory::getAccessGroupFactory()->get($item['accessGroupId']); - $item[$NAME] = $this->obj2Array($obj); - break; - case 'assignedAgents': - /* M2M via Assignment */ - $qF = new QueryFilter(Assignment::TASK_ID, $item[Task::TASK_ID], "=", Factory::getAssignmentFactory()); - $jF = new JoinFilter(Factory::getAssignmentFactory(), Agent::AGENT_ID, Assignment::AGENT_ID); - $item[$NAME] = $this->joinQuery(Factory::getAgentFactory(), $qF, $jF); - break; - case 'chunk': - if ($item['chunkId'] === null) { - /* Chunk expansions are optional, hence the chunk object could be null */ - $item[$NAME] = null; - } else { - $obj = Factory::getChunkFactory()->get($item['chunkId']); - $item[$NAME] = $this->obj2Array($obj); - } - break; - case 'configSection': - $obj = Factory::getConfigSectionFactory()->get($item['configSectionId']); - $item[$NAME] = $this->obj2Array($obj); - break; - case 'crackerBinary': - $obj = Factory::getCrackerBinaryFactory()->get($item['crackerBinaryId']); - $item[$NAME] = $this->obj2Array($obj); - break; - case 'crackerBinaryType': - $obj = Factory::getCrackerBinaryTypeFactory()->get($item['crackerBinaryTypeId']); - $item[$NAME] = $this->obj2Array($obj); - break; - case 'crackerVersions': - $qFs = []; - $qFs[] = new QueryFilter(CrackerBinary::CRACKER_BINARY_TYPE_ID, $item['crackerBinaryTypeId'], "="); - $hashes = Factory::getCrackerBinaryFactory()->filter([Factory::FILTER => $qFs]); - $item[$NAME] = array_map(array($this, 'obj2Array'), $hashes); - break; - case 'hashes': - $qFs = []; - $qFs[] = new QueryFilter(Hash::HASHLIST_ID, $item['hashlistId'], "="); - $hashes = Factory::getHashFactory()->filter([Factory::FILTER => $qFs]); - $item[$NAME] = array_map(array($this, 'obj2Array'), $hashes); - break; - case 'hashlist': - if (get_class($object) == Task::class) { - // Tasks are bit of a specialcase, as in the task the hashlist is not directly available. - // To get this information we need to join the task with the Hashlist and the TaskWrapper to get the Hashlist. - $qF = new QueryFilter(TaskWrapper::TASK_WRAPPER_ID, $item['taskWrapperId'], "=", Factory::getTaskWrapperFactory()); - $jF = new JoinFilter(Factory::getTaskWrapperFactory(), Hashlist::HASHLIST_ID, TaskWrapper::HASHLIST_ID); - $joined = Factory::getHashlistFactory()->filter([Factory::FILTER => $qF, Factory::JOIN => $jF]); - // Now cast the database data to an object. - $obj = reset($joined[Factory::getHashlistFactory()->getModelName()]); - } else { - // Used in expanding hashes. - $obj = Factory::getHashListFactory()->get($item['hashlistId']); - } - $item[$NAME] = $this->obj2Array($obj); - break; - case 'hashType': - $obj = Factory::getHashTypeFactory()->get($item['hashTypeId']); - $item[$NAME] = $this->obj2Array($obj); - break; - case 'healthCheck': - $obj = Factory::getHealthCheckFactory()->get($item['healthCheckId']); - $item[$NAME] = $this->obj2Array($obj); - break; - case 'healthCheckAgents': - $qFs = []; - $qFs[] = new QueryFilter(HealthCheck::HEALTH_CHECK_ID, $item['healthCheckId'], "="); - $objs = Factory::getHealthCheckAgentFactory()->filter([Factory::FILTER => $qFs]); - $item[$NAME] = array_map(array($this, 'obj2Array'), $objs); - break; - case 'globalPermissionGroup': - $obj = Factory::getRightGroupFactory()->get($item['globalPermissionGroupId']); - $item[$NAME] = $this->obj2Array($obj); - break; - case 'task': - $obj = Factory::getTaskFactory()->get($item['taskId']); - $item[$NAME] = $this->obj2Array($obj); - break; - case 'tasks': - if (get_class($object) == Hashlist::class) { - $qF = new QueryFilter(TaskWrapper::HASHLIST_ID, $item['hashlistId'], "=", Factory::getTaskWrapperFactory()); - $jF = new JoinFilter(Factory::getTaskWrapperFactory(), Task::TASK_WRAPPER_ID, TaskWrapper::TASK_WRAPPER_ID); - $item[$NAME] = $this->joinQuery(Factory::getTaskFactory(), $qF, $jF); - } else { - $qF = new QueryFilter(TaskWrapper::TASK_WRAPPER_ID, $item[TaskWrapper::TASK_WRAPPER_ID], "=", Factory::getTaskWrapperFactory()); - $jF = new JoinFilter(Factory::getTaskWrapperFactory(), Task::TASK_WRAPPER_ID, TaskWrapper::TASK_WRAPPER_ID); - $item[$NAME] = $this->joinQuery(Factory::getTaskFactory(), $qF, $jF); - } - break; - case 'speeds': - $qFs = []; - $qFs[] = new QueryFilter(Speed::TASK_ID, $item['taskId'], "="); - $objs = Factory::getSpeedFactory()->filter([Factory::FILTER => $qFs]); - $item[$NAME] = array_map(array($this, 'obj2Array'), $objs); - break; - case 'pretaskFiles': - /* M2M via FilePretask */ - $qF = new QueryFilter(FilePretask::PRETASK_ID, $item[Pretask::PRETASK_ID], "=", Factory::getFilePretaskFactory()); - $jF = new JoinFilter(Factory::getFilePretaskFactory(), File::FILE_ID, FilePretask::FILE_ID); - $item[$NAME] = $this->joinQuery(Factory::getFileFactory(), $qF, $jF); - break; - case 'files': - /* M2M via Filetask */ - $qF = new QueryFilter(FileTask::TASK_ID, $item[Task::TASK_ID], "=", Factory::getFileTaskFactory()); - $jF = new JoinFilter(Factory::getFileTaskFactory(), File::FILE_ID, FileTask::FILE_ID); - $item[$NAME] = $this->joinQuery(Factory::getFileFactory(), $qF, $jF); - break; - case 'pretasks': - /* M2M via SupertaskPretask */ - $qF = new QueryFilter(SupertaskPretask::SUPERTASK_ID, $item[Supertask::SUPERTASK_ID], "=", Factory::getSupertaskPretaskFactory()); - $jF = new JoinFilter(Factory::getSupertaskPretaskFactory(), Pretask::PRETASK_ID, SupertaskPretask::PRETASK_ID); - $item[$NAME] = $this->joinQuery(Factory::getPretaskFactory(), $qF, $jF); - break; - case 'user': - if (get_class($object) == RightGroup::class) { - $mapped_id = $features[RightGroup::RIGHT_GROUP_ID]['alias']; - $qF = new QueryFilter(User::RIGHT_GROUP_ID, $item[$mapped_id], "="); - $objs = Factory::getUserFactory()->filter([Factory::FILTER => $qF]); - $item[$NAME] = array_map(array($this, 'obj2Array'), $objs); - } elseif (get_class($object) == NotificationSetting::class) { - $obj = Factory::getUserFactory()->get($item['userId']); - $item[$NAME] = $this->obj2Array($obj); - } - break; - case 'userMembers': - /* M2M via AccessGroupUser */ - $qF = new QueryFilter(AccessGroupUser::ACCESS_GROUP_ID, $item[AccessGroup::ACCESS_GROUP_ID], "=", Factory::getAccessGroupUserFactory()); - $jF = new JoinFilter(Factory::getAccessGroupUserFactory(), User::USER_ID, AccessGroupUser::USER_ID); - $item[$NAME] = $this->joinQuery(Factory::getUserFactory(), $qF, $jF); - break; - case 'agentMembers': - /* M2M via AccessGroupAgent */ - $qF = new QueryFilter(AccessGroupAgent::ACCESS_GROUP_ID, $item[AccessGroupAgent::ACCESS_GROUP_ID], "=", Factory::getAccessGroupAgentFactory()); - $jF = new JoinFilter(Factory::getAccessGroupAgentFactory(), Agent::AGENT_ID, AccessGroupAgent::AGENT_ID); - $item[$NAME] = $this->joinQuery(Factory::getAgentFactory(), $qF, $jF); - break; - default: - throw new BadFunctionCallException("Internal error: Expansion '$NAME' not implemented!"); + $item[$NAME] = $this->doExpand($object, $NAME); + if (is_null($item[$NAME])) { + throw new BadFunctionCallException("Internal error: Expansion '$NAME' not implemented!"); } - } + }; $expandLeft = array_diff($expand, array_keys($item)); if (sizeof($expandLeft) > 0) { diff --git a/src/inc/apiv2/common/AbstractModelAPI.class.php b/src/inc/apiv2/common/AbstractModelAPI.class.php index f120cfa48..3ad6fd3af 100644 --- a/src/inc/apiv2/common/AbstractModelAPI.class.php +++ b/src/inc/apiv2/common/AbstractModelAPI.class.php @@ -14,7 +14,6 @@ abstract class AbstractModelAPI extends AbstractBaseAPI { abstract static public function getDBAClass(): string; abstract protected function getFactory(): object; - abstract public function getExpandables(): array; abstract protected function getFilterACL(): array; abstract protected function createObject($mappedQuery, $QUERY): int; abstract protected function deleteObject(object $object): void; diff --git a/src/inc/apiv2/model/accessgroups.routes.php b/src/inc/apiv2/model/accessgroups.routes.php index 225a8de31..2bdf44ebe 100644 --- a/src/inc/apiv2/model/accessgroups.routes.php +++ b/src/inc/apiv2/model/accessgroups.routes.php @@ -1,6 +1,13 @@ getId(), "=", Factory::getAccessGroupUserFactory()); + $jF = new JoinFilter(Factory::getAccessGroupUserFactory(), User::USER_ID, AccessGroupUser::USER_ID); + return $this->joinQuery(Factory::getUserFactory(), $qF, $jF); + case 'agentMembers': + $qF = new QueryFilter(AccessGroupAgent::ACCESS_GROUP_ID, $object->getId(), "=", Factory::getAccessGroupAgentFactory()); + $jF = new JoinFilter(Factory::getAccessGroupAgentFactory(), Agent::AGENT_ID, AccessGroupAgent::AGENT_ID); + return $this->joinQuery(Factory::getAgentFactory(), $qF, $jF); + } + } + protected function getFilterACL(): array { return []; } diff --git a/src/inc/apiv2/model/agentassignments.routes.php b/src/inc/apiv2/model/agentassignments.routes.php index d7f404c14..a8d29c216 100644 --- a/src/inc/apiv2/model/agentassignments.routes.php +++ b/src/inc/apiv2/model/agentassignments.routes.php @@ -1,9 +1,10 @@ get($object->getTaskId()); + return $this->obj2Array($obj); + case 'agent': + $obj = Factory::getAgentFactory()->get($object->getAgentId()); + return $this->obj2Array($obj); + } + } + protected function getFilterACL(): array { return []; } diff --git a/src/inc/apiv2/model/agentbinaries.routes.php b/src/inc/apiv2/model/agentbinaries.routes.php index 1640e9327..972df05bb 100644 --- a/src/inc/apiv2/model/agentbinaries.routes.php +++ b/src/inc/apiv2/model/agentbinaries.routes.php @@ -1,9 +1,10 @@ getId(), "=", Factory::getAccessGroupAgentFactory()); + $jF = new JoinFilter(Factory::getAccessGroupAgentFactory(), AccessGroup::ACCESS_GROUP_ID, AccessGroupAgent::ACCESS_GROUP_ID); + return $this->joinQuery(Factory::getAccessGroupFactory(), $qF, $jF); + case 'agentstats': + $qF = new QueryFilter(AgentStat::AGENT_ID, $object->getId(), "="); + return $this->filterQuery(Factory::getAgentStatFactory(), $qF); + } + } + protected function getFilterACL(): array { return []; } diff --git a/src/inc/apiv2/model/agentstats.routes.php b/src/inc/apiv2/model/agentstats.routes.php index 8af46ef77..f97f36f8e 100644 --- a/src/inc/apiv2/model/agentstats.routes.php +++ b/src/inc/apiv2/model/agentstats.routes.php @@ -1,6 +1,9 @@ get($object->getTaskId()); + return $this->obj2Array($obj); + } + } + protected function getFilterACL(): array { return []; } diff --git a/src/inc/apiv2/model/configs.routes.php b/src/inc/apiv2/model/configs.routes.php index 60b1d0d7c..20914af38 100644 --- a/src/inc/apiv2/model/configs.routes.php +++ b/src/inc/apiv2/model/configs.routes.php @@ -1,5 +1,6 @@ get($object->getConfigSectionId()); + return $this->obj2Array($obj); + } + } protected function getFilterACL(): array { return []; diff --git a/src/inc/apiv2/model/configsections.routes.php b/src/inc/apiv2/model/configsections.routes.php index abee73630..9d18b2e74 100644 --- a/src/inc/apiv2/model/configsections.routes.php +++ b/src/inc/apiv2/model/configsections.routes.php @@ -1,5 +1,6 @@ get($object->getCrackerBinaryTypeId()); + return $this->obj2Array($obj); + } + } + protected function getFilterACL(): array { return []; } diff --git a/src/inc/apiv2/model/crackertypes.routes.php b/src/inc/apiv2/model/crackertypes.routes.php index 584ecc5f3..465d7808a 100644 --- a/src/inc/apiv2/model/crackertypes.routes.php +++ b/src/inc/apiv2/model/crackertypes.routes.php @@ -1,9 +1,11 @@ getId(), "="); + return $this->filterQuery(Factory::getCrackerBinaryFactory(), $qF); + } + } + protected function getFilterACL(): array { return []; } diff --git a/src/inc/apiv2/model/files.routes.php b/src/inc/apiv2/model/files.routes.php index 1dd3456da..88959125b 100644 --- a/src/inc/apiv2/model/files.routes.php +++ b/src/inc/apiv2/model/files.routes.php @@ -1,8 +1,9 @@ get($object->getAccessGroupId()); + return $this->obj2Array($obj); + } + } + protected function getFilterACL(): array { return []; } diff --git a/src/inc/apiv2/model/globalpermissiongroups.routes.php b/src/inc/apiv2/model/globalpermissiongroups.routes.php index b751becf3..52ac7d761 100644 --- a/src/inc/apiv2/model/globalpermissiongroups.routes.php +++ b/src/inc/apiv2/model/globalpermissiongroups.routes.php @@ -1,6 +1,10 @@ getId(), "="); + return $this->filterQuery(Factory::getUserFactory(), $qF); + } + } + protected function getFilterACL(): array { return []; } diff --git a/src/inc/apiv2/model/hashes.routes.php b/src/inc/apiv2/model/hashes.routes.php index 81a9fbac1..fe48c348d 100644 --- a/src/inc/apiv2/model/hashes.routes.php +++ b/src/inc/apiv2/model/hashes.routes.php @@ -1,7 +1,8 @@ get($object->getHashlistId()); + return $this->obj2Array($obj); + case 'chunk': + if (is_null($object->getChunkId())) { + /* Chunk expansions are optional, hence the chunk object could be empty */ + return []; + } else { + $obj = Factory::getChunkFactory()->get($object->getChunkId()); + return $this->obj2Array($obj); + } + } + } + protected function getFilterACL(): array { return []; } diff --git a/src/inc/apiv2/model/hashlists.routes.php b/src/inc/apiv2/model/hashlists.routes.php index b665e4991..113721008 100644 --- a/src/inc/apiv2/model/hashlists.routes.php +++ b/src/inc/apiv2/model/hashlists.routes.php @@ -1,7 +1,13 @@ get($object->getAccessGroupId()); + return $this->obj2Array($obj); + case 'hashType': + $obj = Factory::getHashTypeFactory()->get($object->getHashTypeId()); + return $this->obj2Array($obj); + case 'hashes': + $qF = new QueryFilter(Hash::HASHLIST_ID, $object->getId(), "="); + return $this->filterQuery(Factory::getHashFactory(), $qF); + case 'tasks': + $qF = new QueryFilter(TaskWrapper::HASHLIST_ID, $object->getHashTypeId(), "=", Factory::getTaskWrapperFactory()); + $jF = new JoinFilter(Factory::getTaskWrapperFactory(), Task::TASK_WRAPPER_ID, TaskWrapper::TASK_WRAPPER_ID); + return $this->joinQuery(Factory::getTaskFactory(), $qF, $jF); + } + } + protected function getFilterACL(): array { return [new ContainFilter(Hashlist::ACCESS_GROUP_ID, Util::arrayOfIds(AccessUtils::getAccessGroupsOfUser($this->getUser())))]; } diff --git a/src/inc/apiv2/model/hashtypes.routes.php b/src/inc/apiv2/model/hashtypes.routes.php index fa3f8113a..04a34f2e3 100644 --- a/src/inc/apiv2/model/hashtypes.routes.php +++ b/src/inc/apiv2/model/hashtypes.routes.php @@ -1,6 +1,9 @@ get($object->getAgentId()); + return $this->obj2Array($obj); + case 'healthCheck': + $obj = Factory::getHealthCheckFactory()->get($object->getHealthCheckId()); + return $this->obj2Array($obj); + } + } protected function getFilterACL(): array { return []; diff --git a/src/inc/apiv2/model/healthchecks.routes.php b/src/inc/apiv2/model/healthchecks.routes.php index 103ecd90a..d0256a053 100644 --- a/src/inc/apiv2/model/healthchecks.routes.php +++ b/src/inc/apiv2/model/healthchecks.routes.php @@ -1,5 +1,7 @@ get($object->getCrackerBinaryId()); + return $this->obj2Array($obj); + case 'healthCheckAgents': + $qF = new QueryFilter(HealthCheck::HEALTH_CHECK_ID, $object->getId(), "="); + return $this->filterQuery(Factory::getHealthCheckAgentFactory(), $qF); + } + } + protected function getFilterACL(): array { return []; } diff --git a/src/inc/apiv2/model/logentries.routes.php b/src/inc/apiv2/model/logentries.routes.php index f90730061..c269711ad 100644 --- a/src/inc/apiv2/model/logentries.routes.php +++ b/src/inc/apiv2/model/logentries.routes.php @@ -1,9 +1,10 @@ get($object->getUserId()); + return $this->obj2Array($obj); + } + } + protected function getFilterACL(): array { return []; } diff --git a/src/inc/apiv2/model/preprocessors.routes.php b/src/inc/apiv2/model/preprocessors.routes.php index 2126ebea0..1586be81b 100644 --- a/src/inc/apiv2/model/preprocessors.routes.php +++ b/src/inc/apiv2/model/preprocessors.routes.php @@ -1,9 +1,10 @@ getId(), "=", Factory::getFilePretaskFactory()); + $jF = new JoinFilter(Factory::getFilePretaskFactory(), File::FILE_ID, FilePretask::FILE_ID); + return $this->joinQuery(Factory::getFileFactory(), $qF, $jF); + } + } + protected function getFilterACL(): array { return []; } diff --git a/src/inc/apiv2/model/speeds.routes.php b/src/inc/apiv2/model/speeds.routes.php index beac4d68e..2c37376cd 100644 --- a/src/inc/apiv2/model/speeds.routes.php +++ b/src/inc/apiv2/model/speeds.routes.php @@ -1,7 +1,8 @@ get($object->getAgentId()); + return $this->obj2Array($obj); + case 'task': + $obj = Factory::getTaskFactory()->get($object->getTaskId()); + return $this->obj2Array($obj); + } + } + protected function getFilterACL(): array { return []; } diff --git a/src/inc/apiv2/model/supertasks.routes.php b/src/inc/apiv2/model/supertasks.routes.php index 8ebc0ac9f..38d14faef 100644 --- a/src/inc/apiv2/model/supertasks.routes.php +++ b/src/inc/apiv2/model/supertasks.routes.php @@ -1,9 +1,13 @@ getId(), "=", Factory::getSupertaskPretaskFactory()); + $jF = new JoinFilter(Factory::getSupertaskPretaskFactory(), Pretask::PRETASK_ID, SupertaskPretask::PRETASK_ID); + return $this->joinQuery(Factory::getPretaskFactory(), $qF, $jF); + } + } + protected function getFilterACL(): array { return []; } diff --git a/src/inc/apiv2/model/tasks.routes.php b/src/inc/apiv2/model/tasks.routes.php index e0d43c948..b51666345 100644 --- a/src/inc/apiv2/model/tasks.routes.php +++ b/src/inc/apiv2/model/tasks.routes.php @@ -1,6 +1,16 @@ getId(), "=", Factory::getAssignmentFactory()); + $jF = new JoinFilter(Factory::getAssignmentFactory(), Agent::AGENT_ID, Assignment::AGENT_ID); + return $this->joinQuery(Factory::getAgentFactory(), $qF, $jF); + case 'crackerBinary': + $obj = Factory::getCrackerBinaryFactory()->get($object->getCrackerBinaryId()); + return $this->obj2Array($obj); + case 'crackerBinaryType': + $obj = Factory::getCrackerBinaryTypeFactory()->get($object->getCrackerBinaryTypeId()); + return $this->obj2Array($obj); + case 'hashlist': + // Tasks are bit of a special case, as in the task the hashlist is not directly available. + // To get this information we need to join the task with the Hashlist and the TaskWrapper to get the Hashlist. + $qF = new QueryFilter(TaskWrapper::TASK_WRAPPER_ID, $object->getTaskWrapperId(), "=", Factory::getTaskWrapperFactory()); + $jF = new JoinFilter(Factory::getTaskWrapperFactory(), Hashlist::HASHLIST_ID, TaskWrapper::HASHLIST_ID); + return $this->joinQuery(Factory::getHashlistFactory(), $qF, $jF); + case 'speeds': + $qF = new QueryFilter(Speed::TASK_ID, $object->getId(), "="); + return $this->filterQuery(Factory::getSpeedFactory(), $qF); + case 'files': + $qF = new QueryFilter(FileTask::TASK_ID, $object->getId(), "=", Factory::getFileTaskFactory()); + $jF = new JoinFilter(Factory::getFileTaskFactory(), File::FILE_ID, FileTask::FILE_ID); + return $this->joinQuery(Factory::getFileFactory(), $qF, $jF); + } + } + protected function getFilterACL(): array { return []; } diff --git a/src/inc/apiv2/model/taskwrappers.routes.php b/src/inc/apiv2/model/taskwrappers.routes.php index 6cb4c5445..c715934ed 100644 --- a/src/inc/apiv2/model/taskwrappers.routes.php +++ b/src/inc/apiv2/model/taskwrappers.routes.php @@ -1,6 +1,10 @@ get($object->getAccessGroupId()); + return $this->obj2Array($obj); + case 'tasks': + $qF = new QueryFilter(TaskWrapper::TASK_WRAPPER_ID, $object->getId(), "=", Factory::getTaskWrapperFactory()); + $jF = new JoinFilter(Factory::getTaskWrapperFactory(), Task::TASK_WRAPPER_ID, TaskWrapper::TASK_WRAPPER_ID); + return $this->joinQuery(Factory::getTaskFactory(), $qF, $jF); + } + } + protected function getFilterACL(): array { return []; } diff --git a/src/inc/apiv2/model/users.routes.php b/src/inc/apiv2/model/users.routes.php index cd86d09d7..f62b4dd88 100644 --- a/src/inc/apiv2/model/users.routes.php +++ b/src/inc/apiv2/model/users.routes.php @@ -1,8 +1,12 @@ getId(), "=", Factory::getAccessGroupUserFactory()); + $jF = new JoinFilter(Factory::getAccessGroupUserFactory(), AccessGroup::ACCESS_GROUP_ID, AccessGroupUser::ACCESS_GROUP_ID); + return $this->joinQuery(Factory::getAccessGroupFactory(), $qF, $jF); + case 'globalPermissionGroup': + $obj = Factory::getRightGroupFactory()->get($object->getRightGroupId()); + return $this->obj2Array($obj); + } + } + protected function getFilterACL(): array { return []; } diff --git a/src/inc/apiv2/model/vouchers.routes.php b/src/inc/apiv2/model/vouchers.routes.php index c9d8a807b..9e49d82d1 100644 --- a/src/inc/apiv2/model/vouchers.routes.php +++ b/src/inc/apiv2/model/vouchers.routes.php @@ -1,8 +1,9 @@