Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion src/inc/apiv2/common/AbstractBaseAPI.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ protected static function getExpandPermissions(string $expand): array
DAccessControl::PUBLIC_ACCESS => array(LogEntry::PERM_READ),

// src/inc/defines/notifications.php
DAccessControl::LOGIN_ACCESS => array(NotificationSetting::PERM_CREATE, NotificationSetting::PERM_READ, NotificationSetting::PERM_UPDATE, NotificationSetting::PERM_DELETE),
DAccessControl::LOGIN_ACCESS => array(NotificationSetting::PERM_CREATE, NotificationSetting::PERM_READ, NotificationSetting::PERM_UPDATE, NotificationSetting::PERM_DELETE, LogEntry::PERM_CREATE, LogEntry::PERM_DELETE, LogEntry::PERM_UPDATE),
);

/**
Expand Down Expand Up @@ -804,6 +804,16 @@ protected function validateData(array $data, array $features)
}
}

//function for automatic swagger doc generation
function getAllPostParameters(array $features): array {
$postFeatures = [];
foreach($features as $key => $value) {
if ($value['protected'] == False) {
$postFeatures[$key] = $value;
}
}
return $postFeatures;
}
/**
* Validate incoming parameter keys
*/
Expand Down
38 changes: 25 additions & 13 deletions src/inc/apiv2/common/openAPISchema.routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
function typeLookup($feature): array {
$type_format = null;
$type_enum = null;
$sub_type = null;
if ($feature['type'] == 'int') {
$type = "integer";
} elseif ($feature['type'] == 'uint64') {
Expand All @@ -24,6 +25,7 @@ function typeLookup($feature): array {
$type = "object";
} elseif ($feature['type'] == 'array') {
$type = "array";
$sub_type = "integer"; //TODO: subtype is hardcoded because we only have int arrays
} elseif ($feature['type'] == 'bool') {
$type = "boolean";
} elseif (str_starts_with($feature['type'], 'str(')) {
Expand All @@ -42,6 +44,7 @@ function typeLookup($feature): array {
"type" => $type,
"type_format" => $type_format,
"type_enum" => $type_enum,
"subtype" => $sub_type
];

return $result;
Expand Down Expand Up @@ -184,16 +187,20 @@ function makeProperties($features, $skipPK=false): array {
if ($ret["type_enum"] !== null) {
$propertyVal[$feature['alias']]["enum"] = $ret["type_enum"];
}
if ($ret["subtype"] !== null) {
$propertyVal[$feature['alias']]["items"]["type"] = $ret["subtype"];
}
}
return $propertyVal;
};

function buildPatchPost($properties, $id=null): array {
function buildPatchPost($properties, $name, $id=null): array {
$result = ["data" => [
"type" => "object",
"properties" => [
"type" => [
"type" => "string"
"type" => "string",
"default" => $name
],
"attributes" => [
"type" => "object",
Expand Down Expand Up @@ -381,18 +388,23 @@ function makeDescription($isRelation, $method, $singleObject): string {
*/
if (array_key_exists($name, $components) == false) {
$properties_return_post_patch = [
"id" => [
"type" => "integer",
],
"type" => [
"type" => "string",
"default" => $name
],
"data" => [
"type" => "object",
"properties" => makeProperties($class->getFeaturesWithoutFormfields(), true)
"properties" => [
"id" => [
"type" => "integer",
],
"type" => [
"type" => "string",
"default" => $name
],
"attributes" => [
"type" => "object",
"properties" => makeProperties($class->getFeaturesWithoutFormfields(), true)
],
],
]
];
];

$relationships = ["relationships" =>[
"type" => "object",
Expand All @@ -413,9 +425,9 @@ function makeDescription($isRelation, $method, $singleObject): string {
$json_api_header = makeJsonApiHeader();
$links = makeLinks($uri);
$properties_return_post_patch = array_merge($json_api_header, $properties_return_post_patch);
$properties_create = buildPatchPost(makeProperties($class->getCreateValidFeatures(), true));
$properties_create = buildPatchPost(makeProperties($class->getAllPostParameters($class->getCreateValidFeatures(), true)), $name);
$properties_get = array_merge($json_api_header, $links, $properties_get_single, $included);
$properties_patch = buildPatchPost(makeProperties($class->getPatchValidFeatures(), true));
$properties_patch = buildPatchPost(makeProperties($class->getPatchValidFeatures(), true), $name);

$components[$name . "Create"] =
[
Expand Down
2 changes: 1 addition & 1 deletion src/inc/apiv2/model/agents.routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public static function getToManyRelationships(): array {
}

protected function createObject(array $data): int {
assert(False, "Chunks cannot be created via API");
assert(False, "Agents cannot be created via API");
return -1;
}

Expand Down
8 changes: 8 additions & 0 deletions src/inc/apiv2/model/crackertypes.routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,14 @@ public static function getToManyRelationships(): array {
];
}

function getAllPostParameters(array $features): array {

//for documentation purposes isChunkingAVailable has to be removed
// because it is currently not setable by the user
$features = parent::getAllPostParameters($features);
unset($features[CrackerBinaryType::IS_CHUNKING_AVAILABLE]);
return $features;
}

protected function createObject(array $data): int {
CrackerUtils::createBinaryType($data[CrackerBinaryType::TYPE_NAME]);
Expand Down
7 changes: 6 additions & 1 deletion src/inc/apiv2/model/notifications.routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,19 @@ public static function getToOneRelationships(): array {
];
}

function getAllPostParameters(array $features): array {
$features = parent::getAllPostParameters($features);
unset($features[NotificationSetting::IS_ACTIVE]);
return $features;
}

public function getFormFields(): array {
return ['actionFilter' => ['type' => 'str(256)']];
}

protected function createObject(array $data): int {
$dummyPost = [];
switch (DNotificationType::getObjectType($data['action'])) {
switch (DNotificationType::getObjectType($data[NotificationSetting::ACTION])) {
case DNotificationObjectType::USER:
$dummyPost['user'] = $data['actionFilter'];
break;
Expand Down
6 changes: 6 additions & 0 deletions src/inc/apiv2/model/users.routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,12 @@ protected function createObject($data): int {
return $objects[0]->getId();
}

function getAllPostParameters(array $features): array {

$features = parent::getAllPostParameters($features);
unset($features[User::IS_VALID]);
return $features;
}

protected function deleteObject(object $object): void {
UserUtils::deleteUser($object->getId(), $this->getCurrentUser());
Expand Down