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
Original file line number Diff line number Diff line change
Expand Up @@ -239,8 +239,8 @@ export const workbenchFileContentAttributesQuery = graphql`
`;

const workbenchFileContentMutation = graphql`
mutation WorkbenchFileContentMutation($file: Upload!, $entityId: String, $refreshEntity: Boolean) {
uploadPending(file: $file, entityId: $entityId, refreshEntity: $refreshEntity) {
mutation WorkbenchFileContentMutation($file: Upload!, $entityId: String, $file_markings: [String!], $refreshEntity: Boolean) {
uploadPending(file: $file, entityId: $entityId, file_markings: $file_markings, refreshEntity: $refreshEntity) {
id
}
}
Expand Down Expand Up @@ -426,10 +426,7 @@ const WorkbenchFileContentComponent = ({
+ stixSightings.length
+ containers.length;
if (numberOfObjects > 0) {
let currentEntityId = null;
if (file.metaData.entity_id && file.metaData.entity) {
currentEntityId = file.metaData.entity_id;
}
const currentEntityId = file.metaData.entity_id && file.metaData.entity ? file.metaData.entity_id : null;
// update entity container objects_refs
if (currentEntityId) {
const currentEntityContainer = containers.find(
Expand Down Expand Up @@ -472,7 +469,11 @@ const WorkbenchFileContentComponent = ({
});
commitMutation({
mutation: workbenchFileContentMutation,
variables: { file: fileToUpload, entityId: currentEntityId },
variables: {
file: fileToUpload,
entityId: currentEntityId,
file_markings: file.metaData.file_markings ?? [],
},
});
}
}
Expand Down Expand Up @@ -846,10 +847,7 @@ const WorkbenchFileContentComponent = ({

// region submission
const onSubmitValidate = (values, { setSubmitting, resetForm }) => {
let currentEntityId = null;
if (file.metaData.entity_id && file.metaData.entity) {
currentEntityId = file.metaData.entity_id;
}
const currentEntityId = file.metaData.entity_id && file.metaData.entity ? file.metaData.entity_id : null;
const data = {
id: `bundle--${uuid()}`,
type: 'bundle',
Expand All @@ -871,6 +869,7 @@ const WorkbenchFileContentComponent = ({
variables: {
file: fileToUpload,
entityId: currentEntityId,
file_markings: file.metaData.file_markings ?? [],
refreshEntity: values.refreshEntity,
},
onCompleted: () => {
Expand Down Expand Up @@ -909,10 +908,7 @@ const WorkbenchFileContentComponent = ({
};

const onSubmitConvertToDraft = (values, { setSubmitting, resetForm }) => {
let currentEntityId = null;
if (file.metaData.entity_id && file.metaData.entity) {
currentEntityId = file.metaData.entity_id;
}
const currentEntityId = file.metaData.entity_id && file.metaData.entity ? file.metaData.entity_id : null;
const data = {
id: `bundle--${uuid()}`,
type: 'bundle',
Expand All @@ -934,6 +930,7 @@ const WorkbenchFileContentComponent = ({
variables: {
file: fileToUpload,
entityId: currentEntityId,
file_markings: file.metaData.file_markings ?? [],
refreshEntity: values.refreshEntity,
},
onCompleted: () => {
Expand Down Expand Up @@ -4431,6 +4428,7 @@ const WorkbenchFileContent = createFragmentContainer(
metaData {
mimetype
encoding
file_markings
list_filters
messages {
timestamp
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import DialogActions from '@mui/material/DialogActions';
import Button from '@mui/material/Button';
import makeStyles from '@mui/styles/makeStyles';
import { WorkbenchFileCreatorStixCoreObjectQuery$data } from '@components/common/files/workbench/__generated__/WorkbenchFileCreatorStixCoreObjectQuery.graphql';
import ObjectMarkingField from '@components/common/form/ObjectMarkingField';
import TextField from '../../../../../components/TextField';
import AutocompleteFreeSoloField from '../../../../../components/AutocompleteFreeSoloField';
import ItemIcon from '../../../../../components/ItemIcon';
Expand All @@ -21,6 +22,7 @@ import { WorkbenchFileViewer_entity$data } from './__generated__/WorkbenchFileVi
import { WorkbenchFileCreatorMutation } from './__generated__/WorkbenchFileCreatorMutation.graphql';
import { fetchQuery } from '../../../../../relay/environment';
import useApiMutation from '../../../../../utils/hooks/useApiMutation';
import { fieldSpacingContainerStyle } from '../../../../../utils/field';

// Deprecated - https://mui.com/system/styles/basics/
// Do not use it for new code.
Expand All @@ -44,11 +46,13 @@ const workbenchFileCreatorMutation = graphql`
mutation WorkbenchFileCreatorMutation(
$file: Upload!
$labels: [String]
$file_markings: [String!]
$entityId: String
) {
uploadPending(
file: $file
labels: $labels
file_markings: $file_markings
errorOnExisting: true
entityId: $entityId
) {
Expand All @@ -65,6 +69,7 @@ const fileValidation = (t: (value: string) => string) => Yup.object().shape({
interface WorkbenchFileCreatorFormValues {
name: string;
labels: Option[];
fileMarkings: Option[];
}

interface WorkbenchFileCreatorProps {
Expand Down Expand Up @@ -99,6 +104,7 @@ const WorkbenchFileCreator: FunctionComponent<WorkbenchFileCreatorProps> = ({
const onSubmitCreate: FormikConfig<WorkbenchFileCreatorFormValues>['onSubmit'] = (values, { setSubmitting, resetForm }) => {
let { name } = values;
const finalLabels = values.labels.map((label) => label.value);
const file_markings = values.fileMarkings.map(({ value }) => value);
if (!name.endsWith('.json')) {
name += '.json';
}
Expand All @@ -119,10 +125,7 @@ const WorkbenchFileCreator: FunctionComponent<WorkbenchFileCreatorProps> = ({
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const objects: any = [];
if (entityId) {
fetchQuery(workbenchFileCreatorStixCoreObjectQuery, {
id: entityId,
})
.toPromise()
fetchQuery(workbenchFileCreatorStixCoreObjectQuery, { id: entityId }).toPromise()
.then(async (entityData) => {
const { stixCoreObject: workbenchStixCoreObject } = entityData as WorkbenchFileCreatorStixCoreObjectQuery$data;
if (workbenchStixCoreObject?.toStix) {
Expand All @@ -138,7 +141,7 @@ const WorkbenchFileCreator: FunctionComponent<WorkbenchFileCreatorProps> = ({
type: 'application/json',
});
commitWorkbench({
variables: { file, labels: finalLabels, entityId },
variables: { file, labels: finalLabels, entityId, file_markings },
onCompleted: () => {
handleCompleted();
},
Expand All @@ -155,7 +158,7 @@ const WorkbenchFileCreator: FunctionComponent<WorkbenchFileCreatorProps> = ({
type: 'application/json',
});
commitWorkbench({
variables: { file, labels: finalLabels, entityId },
variables: { file, labels: finalLabels, entityId, file_markings },
onCompleted: () => {
handleCompleted();
},
Expand All @@ -169,6 +172,7 @@ const WorkbenchFileCreator: FunctionComponent<WorkbenchFileCreatorProps> = ({
const initialValues: WorkbenchFileCreatorFormValues = {
name: '',
labels: [],
fileMarkings: [],
};

return (
Expand All @@ -179,7 +183,7 @@ const WorkbenchFileCreator: FunctionComponent<WorkbenchFileCreatorProps> = ({
onSubmit={onSubmitCreate}
onReset={handleCloseCreate}
>
{({ submitForm, handleReset, isSubmitting }) => (
{({ submitForm, handleReset, isSubmitting, setFieldValue }) => (
<Form>
<Dialog
PaperProps={{ elevation: 1 }}
Expand Down Expand Up @@ -221,6 +225,13 @@ const WorkbenchFileCreator: FunctionComponent<WorkbenchFileCreatorProps> = ({
clearIndicator: classes.autoCompleteIndicator,
}}
/>
<ObjectMarkingField
name="fileMarkings"
label={t_i18n('File marking definition levels')}
style={fieldSpacingContainerStyle}
setFieldValue={setFieldValue}
required={false}
/>
</DialogContent>
<DialogActions>
<Button onClick={handleReset} disabled={isSubmitting}>
Expand Down
Loading