Skip to content

Commit

Permalink
Merge branch 'main' into CA-503-Duplicate-applied-controls
Browse files Browse the repository at this point in the history
  • Loading branch information
monsieurswag committed Oct 16, 2024
2 parents af3e7c9 + 3a65bcd commit 526d867
Show file tree
Hide file tree
Showing 24 changed files with 1,150 additions and 13,817 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/frontend-linters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ jobs:
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
- name: Install pnpm
- name: Install latest pnpm
working-directory: ${{env.working-directory}}
run: |
npm install -g pnpm &&
npm --version &&
npm list -g --depth 0
pnpm --version &&
pnpm list -g --depth 0
- name: Install prettier
working-directory: ${{env.working-directory}}
run: pnpm add --save-dev prettier
Expand Down
2 changes: 1 addition & 1 deletion backend/core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2637,7 +2637,7 @@ def create_applied_controls_from_suggestions(self) -> list[AppliedControl]:
)
continue
if applied_controls:
self.applied_controls.add(applied_controls)
self.applied_controls.add(*applied_controls)
return applied_controls

class Meta:
Expand Down
2 changes: 2 additions & 0 deletions backend/core/startup.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,8 @@
"view_globalsettings",
"change_globalsettings",
"view_requirementmappingset",
"add_requirementmappingset",
"delete_requirementmappingset",
"view_requirementmapping",
"add_entity",
"change_entity",
Expand Down
82 changes: 78 additions & 4 deletions backend/core/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -598,12 +598,57 @@ def treatment_plan_pdf(self, request, pk):
serializer_class=RiskAssessmentDuplicateSerializer,
)
def duplicate(self, request, pk):
def duplicate_related_objects(
scenario, duplicate_scenario, target_folder, field_name, model_class
):
"""
Duplicates related objects (e.g., controls, threats, assets) from a source scenario to a duplicate scenario,
ensuring that objects are not duplicated if they already exist in the/a target/parent domain (folder).
Parameters:
- scenario (object): The source scenario containing the related objects to be duplicated.
- duplicate_scenario (object): The duplicate scenario where the objects will be added.
- target_folder (object): The target folder where the duplicated objects will be stored.
- field_name (str): The field name representing the related objects to duplicate in the scenario.
- model_class (class): The model class of the related objects to be processed.
"""

# Get parent folders of the target folder
target_parent_folders = target_folder.get_parent_folders()

# Fetch all related objects for the given field name
related_objects = getattr(scenario, field_name).all()

for obj in related_objects:
# Check if an object with the same name already exists in the target folder
existing_obj = model_class.objects.filter(
name=obj.name, folder=target_folder
).first()

if existing_obj:
# If the object already exists in the targer folder, add the existing one to the duplicate scenario
getattr(duplicate_scenario, field_name).add(existing_obj)

elif obj.folder in target_parent_folders:
# If the object's folder is a parent of the targert folder, add the object to the duplicate scenario
getattr(duplicate_scenario, field_name).add(obj)

else:
# If the object doesn't exist, duplicate the object
duplicate_obj = obj
duplicate_obj.pk = None
duplicate_obj.folder = target_folder
duplicate_obj.save()
getattr(duplicate_scenario, field_name).add(duplicate_obj)

(object_ids_view, _, _) = RoleAssignment.get_accessible_object_ids(
Folder.get_root_folder(), request.user, RiskAssessment
)

if UUID(pk) in object_ids_view:
risk_assessment = self.get_object()
data = request.data

duplicate_risk_assessment = RiskAssessment.objects.create(
name=data["name"],
description=data["description"],
Expand All @@ -614,8 +659,10 @@ def duplicate(self, request, pk):
due_date=risk_assessment.due_date,
status=risk_assessment.status,
)

duplicate_risk_assessment.authors.set(risk_assessment.authors.all())
duplicate_risk_assessment.reviewers.set(risk_assessment.reviewers.all())

for scenario in risk_assessment.risk_scenarios.all():
duplicate_scenario = RiskScenario.objects.create(
risk_assessment=duplicate_risk_assessment,
Expand All @@ -631,11 +678,38 @@ def duplicate(self, request, pk):
strength_of_knowledge=scenario.strength_of_knowledge,
justification=scenario.justification,
)
duplicate_scenario.threats.set(scenario.threats.all())
duplicate_scenario.assets.set(scenario.assets.all())
duplicate_scenario.owner.set(scenario.owner.all())
duplicate_scenario.applied_controls.set(scenario.applied_controls.all())

duplicate_related_objects(
scenario,
duplicate_scenario,
duplicate_risk_assessment.project.folder,
"applied_controls",
AppliedControl,
)
duplicate_related_objects(
scenario,
duplicate_scenario,
duplicate_risk_assessment.project.folder,
"threats",
Threat,
)
duplicate_related_objects(
scenario,
duplicate_scenario,
duplicate_risk_assessment.project.folder,
"assets",
Asset,
)

if (
duplicate_risk_assessment.project.folder
in [risk_assessment.project.folder]
+ risk_assessment.project.folder.sub_folders()
):
duplicate_scenario.owner.set(scenario.owner.all())

duplicate_scenario.save()

duplicate_risk_assessment.save()
return Response({"results": "risk assessment duplicated"})

Expand Down
15 changes: 0 additions & 15 deletions frontend/.eslintignore

This file was deleted.

5 changes: 4 additions & 1 deletion frontend/.eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ module.exports = {
'plugin:storybook/recommended'
],
parser: '@typescript-eslint/parser',
plugins: ['@typescript-eslint'],
plugins: ['@typescript-eslint', 'eslint-plugin-intuitem-sveltekit'],
rules: {
'eslint-plugin-intuitem-sveltekit/secure-redirect': 'error'
},
parserOptions: {
sourceType: 'module',
ecmaVersion: 2020,
Expand Down
1 change: 1 addition & 0 deletions frontend/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ tests/results/
tests/reports/
yarn.lock
vite.config.js.timestamp-*
vite.config.ts.timestamp-*
/packages/create-svelte/template/CHANGELOG.md
/packages/package/test/**/package
/documentation/types.js
Expand Down
1 change: 1 addition & 0 deletions frontend/.prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ node_modules
!.env.example
/tests/reports/*
/tests/results/*
**/paraglide

# Ignore files for PNPM, NPM and YARN
pnpm-lock.yaml
Expand Down
82 changes: 82 additions & 0 deletions frontend/eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import typescriptEslint from '@typescript-eslint/eslint-plugin';
import intuitemSveltekit from './plugins/eslint/eslint-plugin-intuitem-sveltekit/index.js';
import globals from 'globals';
import tsParser from '@typescript-eslint/parser';
import parser from 'svelte-eslint-parser';
import path from 'node:path';
import { fileURLToPath } from 'node:url';
import js from '@eslint/js';
import { FlatCompat } from '@eslint/eslintrc';

const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const compat = new FlatCompat({
baseDirectory: __dirname,
recommendedConfig: js.configs.recommended,
allConfig: js.configs.all
});

export default [
{
ignores: [
'**/.DS_Store',
'**/node_modules',
'build',
'.svelte-kit',
'package',
'**/.env',
'**/.env.*',
'!**/.env.example',
'tests/reports/*',
'tests/results/*',
'**/pnpm-lock.yaml',
'**/package-lock.json',
'**/yarn.lock'
]
},
...compat.extends(
'eslint:recommended',
'plugin:@typescript-eslint/recommended',
'plugin:svelte/recommended',
'prettier',
'plugin:storybook/recommended'
),
{
plugins: {
'@typescript-eslint': typescriptEslint,
'eslint-plugin-intuitem-sveltekit': intuitemSveltekit
},

languageOptions: {
globals: {
...globals.browser,
...globals.node
},

parser: tsParser,
ecmaVersion: 2020,
sourceType: 'module',

parserOptions: {
extraFileExtensions: ['.svelte']
}
},

rules: {
'eslint-plugin-intuitem-sveltekit/secure-redirect': 'error'
}
},
{
files: ['**/*.svelte'],

languageOptions: {
parser: parser,
ecmaVersion: 5,
sourceType: 'script',

parserOptions: {
parser: '@typescript-eslint/parser'
}
}
}
];
6 changes: 4 additions & 2 deletions frontend/messages/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@
"noObservation": "No observation",
"importMatrices": "Import matrices",
"importFrameworks": "Import frameworks",
"importMappings": "Import mappings",
"summary": "Summary",
"composer": "Composer",
"statistics": "Statistics",
Expand Down Expand Up @@ -471,7 +472,7 @@
"avoid": "Avoided",
"transfer": "Shared",
"primary": "Primary",
"support": "Support",
"support": "Supporting",
"toDo": "To do",
"inProgress": "In progress",
"inReview": "In review",
Expand Down Expand Up @@ -689,7 +690,8 @@
"referenceLink": "Reference link",
"mission": "Mission",
"ownedFolders": "Owned domains",
"thirdParty": "Third parties",
"thirdParty": "Third party",
"thirdPartyCategory": "Third parties",
"entityAssessment": "Entity assessment",
"entityAssessments": "Entity assessments",
"addEntityAssessment": "Add entity assessment",
Expand Down
4 changes: 3 additions & 1 deletion frontend/messages/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@
"observation": "Observation",
"importMatrices": "Importer des matrices",
"importFrameworks": "Importer des référentiels",
"importMappings": "Importer des mappings",
"summary": "Synthèse",
"composer": "Compositeur",
"statistics": "Statistiques",
Expand Down Expand Up @@ -687,7 +688,8 @@
"backupLoadingError": "Une erreur s'est produite lors du chargement de la sauvegarde.",
"backupGreaterVersionError": "Impossible de charger la sauvegarde, la version de la sauvegarde est supérieure à la version actuelle de votre application.",
"backupLowerVersionError": "Une erreur s'est produite, la version de sauvegarde est peut-être trop ancienne, si c'est le cas, elle doit être mise à jour avant de réessayer.",
"thirdParty": "Gestion des tiers",
"thirdParty": "Tiers",
"thirdPartyCategory": "Gestion des tiers",
"catalog": "Catalogue",
"actions": "Actions"
}
Loading

0 comments on commit 526d867

Please sign in to comment.