Skip to content

Commit

Permalink
[backend] Fix validation and schema for ThreatActors
Browse files Browse the repository at this point in the history
  • Loading branch information
Kedae committed Feb 27, 2024
1 parent cb26a80 commit 2f4485e
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ export const stixDomainObjectFileEdit = async (context, user, sdoId, { id, order
}
return file;
});
const { element: updatedElement } = await updateAttribute(context, user, sdoId, ABSTRACT_STIX_DOMAIN_OBJECT, { key: 'x_opencti_files', value: files });
const { element: updatedElement } = await updateAttribute(context, user, sdoId, ABSTRACT_STIX_DOMAIN_OBJECT, [{ key: 'x_opencti_files', value: files }]);
return notify(BUS_TOPICS[ABSTRACT_STIX_DOMAIN_OBJECT].EDIT_TOPIC, updatedElement, user);
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ const stixDomainObjectsAttributes: { [k: string]: Array<AttributeDefinition> } =
[ENTITY_TYPE_THREAT_ACTOR_GROUP]: [
iAliasedIds,
aliases,
{ ...files, update: true },
{ name: 'name', label: 'Name', type: 'string', format: 'short', mandatoryType: 'external', editDefault: true, multiple: false, upsert: true, isFilterable: true },
{ name: 'description', label: 'Description', type: 'string', format: 'text', mandatoryType: 'customizable', editDefault: true, multiple: false, upsert: true, isFilterable: true },
{ name: 'threat_actor_types', label: 'Threat actor types', format: 'vocabulary', type: 'string', vocabularyCategory: 'threat_actor_group_type_ov', mandatoryType: 'customizable', editDefault: true, multiple: true, upsert: false, isFilterable: true },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import { ENTITY_TYPE_EVENT } from '../event/event-types';
import { ENTITY_HASHED_OBSERVABLE_STIX_FILE } from '../../schema/stixCyberObservable';
import { ENTITY_TYPE_LOCATION_ADMINISTRATIVE_AREA } from '../administrativeArea/administrativeArea-types';
import { ENTITY_TYPE_IDENTITY_ORGANIZATION } from '../organization/organization-types';
import { files } from '../../schema/attribute-definition';

interface Measures {
measure: number | null
Expand Down Expand Up @@ -83,6 +84,7 @@ const THREAT_ACTOR_INDIVIDUAL_DEFINITION: ModuleDefinition<StoreEntityThreatActo
},
},
attributes: [
{ ...files, update: true },
{ name: 'name', label: 'Name', type: 'string', format: 'short', mandatoryType: 'external', editDefault: true, multiple: false, upsert: true, isFilterable: true },
{ name: 'description', label: 'Description', type: 'string', format: 'text', mandatoryType: 'customizable', editDefault: true, multiple: false, upsert: true, isFilterable: true },
{ name: 'threat_actor_types', label: 'Threat actor types', type: 'string', format: 'vocabulary', vocabularyCategory: 'threat_actor_individual_type_ov', mandatoryType: 'customizable', editDefault: true, multiple: true, upsert: false, isFilterable: true },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ export const validateAndFormatSchemaAttribute = (
const validateFormatSchemaAttributes = async (context: AuthContext, user: AuthUser, instanceType: string, editInputs: EditInput[]) => {
const validateFormatSchemaAttributesFn = async () => {
const availableAttributes = schemaAttributesDefinition.getAttributes(instanceType);
if (R.isEmpty(editInputs) || !Array.isArray(editInputs)) {
throw UnsupportedError('Cannot validate an empty or invalid input', { input: editInputs });
}
editInputs.forEach((editInput) => {
const attributeDefinition = availableAttributes.get(editInput.key);
validateAndFormatSchemaAttribute(editInput.key, attributeDefinition, editInput);
Expand Down Expand Up @@ -210,6 +213,9 @@ export const validateInputUpdate = async (
entitySetting: BasicStoreEntityEntitySetting,
) => {
const validateInputUpdateFn = async () => {
if (R.isEmpty(editInputs) || !Array.isArray(editInputs)) {
throw UnsupportedError('Cannot validate an empty or invalid input', { input: editInputs });
}
// Convert input to record
const instanceFromInputs: Record<string, unknown> = {};
editInputs.forEach((obj) => { instanceFromInputs[obj.key] = obj.value; });
Expand Down

0 comments on commit 2f4485e

Please sign in to comment.