Skip to content

Commit

Permalink
Merge branch 'main' into CA-519-Move-from-localItems-to-safeTranslate…
Browse files Browse the repository at this point in the history
…-to-translate-dynamic-strings
  • Loading branch information
monsieurswag committed Oct 17, 2024
2 parents 69b9d32 + 8cd02fd commit 4de6635
Show file tree
Hide file tree
Showing 14 changed files with 175 additions and 28 deletions.
108 changes: 108 additions & 0 deletions .github/workflows/backend-migrations-check.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
name: Backend migrations check

on:
pull_request:
branches: [main, develop]
types: [opened, synchronize]
workflow_dispatch:

env:
GITHUB_WORKFLOW: github_actions
backend-directory: ./backend
enterprise-backend-directory: ./enterprise/backend
enterprise-backend-settings-module: enterprise_core.settings

jobs:
migrations-check:
runs-on: ubuntu-20.04

strategy:
max-parallel: 4
matrix:
python-version: ["3.11"]

steps:
- uses: actions/checkout@v4
- name: Set up python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
cache: "pip"
- uses: actions/setup-node@v4
with:
node-version: latest
- name: Install requirements
working-directory: ${{ env.backend-directory }}
run: |
python -m pip install --upgrade pip
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: Create backend environment variables file
working-directory: ${{ env.backend-directory }}
run: |
touch .env
echo DJANGO_DEBUG=True >> .env
echo [email protected] >> .env
echo DJANGO_SUPERUSER_PASSWORD=1234 >> .env
echo DB_HOST=localhost >> .env
echo CISO_ASSISTANT_SUPERUSER_EMAIL='' >> .env
echo CISO_ASSISTANT_URL=http://localhost:4173 >> .env
echo DEFAULT_FROM_EMAIL='[email protected]' >> .env
echo EMAIL_HOST=localhost >> .env
echo [email protected] >> .env
echo EMAIL_HOST_PASSWORD=password >> .env
echo EMAIL_PORT=1025 >> .env
- name: Check that migrations were made
working-directory: ${{ env.backend-directory }}
run: |
export $(grep -v '^#' .env | xargs)
python manage.py makemigrations --check --dry-run --verbosity=3
enterprise-migrations-check:
runs-on: ubuntu-20.04

strategy:
max-parallel: 4
matrix:
python-version: ["3.11"]

steps:
- uses: actions/checkout@v4
- name: Set up python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
cache: "pip"
- name: Install Poetry
uses: snok/install-poetry@v1
with:
virtualenvs-create: false
installer-parallel: true
- name: Install backend requirements
working-directory: ${{ env.backend-directory }}
run: poetry install
- name: Install enterprise backend
working-directory: ${{ env.enterprise-backend-directory }}
run: poetry install
- name: Create backend environment variables file
working-directory: ${{ env.backend-directory }}
run: |
touch .env
echo DJANGO_DEBUG=True >> .env
echo [email protected] >> .env
echo DJANGO_SUPERUSER_PASSWORD=1234 >> .env
echo DB_HOST=localhost >> .env
echo CISO_ASSISTANT_SUPERUSER_EMAIL='' >> .env
echo CISO_ASSISTANT_URL=http://localhost:4173 >> .env
echo DEFAULT_FROM_EMAIL='[email protected]' >> .env
echo EMAIL_HOST=localhost >> .env
echo [email protected] >> .env
echo EMAIL_HOST_PASSWORD=password >> .env
echo EMAIL_PORT=1025 >> .env
echo DJANGO_SETTINGS_MODULE=enterprise_core.settings >> .env
echo LICENSE_SEATS=999 >> .env
- name: Check that migrations were made
working-directory: ${{ env.backend-directory }}
run: |
export $(grep -v '^#' .env | xargs)
poetry run python manage.py makemigrations --check --dry-run --verbosity=3 --settings=${{ env.enterprise-backend-settings-module }}
if [ $? -ne 0 ]; then echo "::error Migrations were not made, please run the makemigrations command." && exit 1; fi
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*.sqlite3
django_secret_key
temp/
db/
./db/
.dccache
/backend/profiles
./backend/ciso_assistant/.meta
Expand Down
2 changes: 1 addition & 1 deletion backend/core/startup.py
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ def startup(sender: AppConfig, **kwargs):
name="Global", content_type=Folder.ContentType.ROOT, builtin=True
)
# if main entity does not exist, then create it
if not Entity.objects.filter(name="Main").exists():
if not Entity.get_main_entity():
main = Entity.objects.create(
name="Main", folder=Folder.get_root_folder(), builtin=True
)
Expand Down
4 changes: 4 additions & 0 deletions backend/core/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ def __str__(self) -> str:
str(UserGroupCodename.THIRD_PARTY_RESPONDENT): _("Third-party respondent"),
}

# NOTE: This is set to "Main" now, but will be changed to a unique identifier
# for internationalization.
MAIN_ENTITY_DEFAULT_NAME = "Main"

COUNTRY_FLAGS = {
"fr": "🇫🇷",
"en": "🇬🇧",
Expand Down
11 changes: 10 additions & 1 deletion backend/tprm/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from django.utils.translation import gettext_lazy as _
from core.base_models import NameDescriptionMixin, AbstractBaseModel
from core.models import Assessment, ComplianceAssessment, Evidence
from iam.models import FolderMixin, PublishInRootFolderMixin
from iam.models import Folder, FolderMixin, PublishInRootFolderMixin
from iam.views import User


Expand All @@ -27,6 +27,15 @@ class Meta:
verbose_name = _("Entity")
verbose_name_plural = _("Entities")

@classmethod
def get_main_entity(cls):
return (
cls.objects.filter(builtin=True)
.filter(owned_folders=Folder.get_root_folder())
.order_by("created_at")
.first()
)


class EntityAssessment(Assessment):
class Conclusion(models.TextChoices):
Expand Down
20 changes: 16 additions & 4 deletions enterprise/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ cd ../backend
poetry shell
```

3. Install enterprise backend module
3. Install enterprise backend module.

```sh
cd ../enterprise/backend
Expand All @@ -46,21 +46,33 @@ poetry install
export SQLITE_FILE=db/ciso-assistant-enterprise.sqlite3
```

5. Run the development server
5. Apply migrations.

```sh
poetry run ./manage.sh migrate
```

6. Create a Django superuser, that will be CISO Assistant administrator.

```sh
poetry run ./manage.sh createsuperuser
```

7. Run the development server.

```sh
poetry run ./manage.sh runserver
```

### Running the frontend

1. cd into the enteprise frontend directory
1. cd into the enteprise frontend directory.

```bash
cd enterprise/frontend
```

3. Start a development server (make sure that the django app is running)
3. Start a development server (make sure that the django app is running).

```bash
make dev
Expand Down
2 changes: 2 additions & 0 deletions enterprise/backend/db/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*
!.gitignore
27 changes: 27 additions & 0 deletions enterprise/backend/enterprise_core/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
from django.conf import settings

from core.views import BaseModelViewSet
from core.utils import MAIN_ENTITY_DEFAULT_NAME
from iam.models import User
from tprm.models import Entity

from .models import ClientSettings
from .serializers import ClientSettingsReadSerializer
Expand All @@ -39,6 +41,31 @@ def delete(self, request, *args, **kwargs):
status=status.HTTP_405_METHOD_NOT_ALLOWED,
)

def perform_update(self, serializer):
instance = serializer.save()
self._update_main_entity_name(instance)

def _update_main_entity_name(self, instance):
main_entity = Entity.get_main_entity()

if instance.name:
self._set_main_entity_name(main_entity, instance.name)
elif main_entity.name != MAIN_ENTITY_DEFAULT_NAME:
self._set_main_entity_name(main_entity, MAIN_ENTITY_DEFAULT_NAME)

def _set_main_entity_name(self, main_entity, new_name):
if main_entity.name == new_name:
return

logger.info("Updating main entity name", entity=main_entity, name=new_name)
try:
main_entity.name = new_name
main_entity.save()
logger.info("Main entity name updated", entity=main_entity, name=new_name)
except Exception as e:
logger.error("An error occurred while renaming main entity", exc_info=e)
raise

@action(methods=["get"], detail=False, permission_classes=[AllowAny])
def info(self, request):
try:
Expand Down
17 changes: 0 additions & 17 deletions frontend/src/lib/components/DetailView/DetailView.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -150,20 +150,6 @@
modalStore.trigger(modal);
}
function getForms(model: Record<string, any>) {
let { form: createForm, message: createMessage } = superForm(model.createForm, {
onUpdated: ({ form }) =>
handleFormUpdated({ form, pageStatus: $page.status, closeModal: true })
});
let { form: deleteForm, message: deleteMessage } = superForm(model.deleteForm, {
onUpdated: ({ form }) =>
handleFormUpdated({ form, pageStatus: $page.status, closeModal: true })
});
return { createForm, createMessage, deleteForm, deleteMessage };
}
let forms: Record<string, any> = {};
const user = $page.data.user;
const canEditObject: boolean = Object.hasOwn(user.permissions, `change_${data.model.name}`);
Expand All @@ -175,9 +161,6 @@
!data.data.builtin
);
};
$: Object.entries(data.relatedModels).forEach(([key, value]) => {
forms[key] = getForms(value);
});
</script>

<div class="flex flex-col space-y-2">
Expand Down
1 change: 1 addition & 0 deletions frontend/src/lib/components/Forms/Question.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
<RadioGroup active="variant-filled-primary" hover="hover:variant-soft-primary">
{#each question.options as option}
<RadioItem
class="whitespace-nowrap"
bind:group={question.answer}
name="question"
value={option}
Expand Down
1 change: 1 addition & 0 deletions frontend/src/lib/utils/table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,7 @@ export const listViewFields: ListViewFieldsConfig = {
filters: {
folder: { ...DOMAIN_FILTER, alwaysDisplay: true },
category: CATEGORY_FILTER,
provider: PROVIDER_FILTER,
csf_function: CSF_FUNCTION_FILTER
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,7 @@
<div class="absolute top-2 right-4 mt-2 space-x-1">
<div class="flex flex-col space-y-1">
<a
href="/compliance-assessments/{compliance_assessment.id}/edit"
href="/compliance-assessments/{compliance_assessment.id}/edit?next=/analytics?tab=3"
class="btn variant-filled-primary"
><i class="fa-solid fa-edit mr-2" /> {m.edit()}
</a>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@
{/if}
{/each}
{/if}
{#if node.question.questions}
{#if node.question && node.question.questions}
<span class="badge" style="background-color: pink; color: {darkenColor('#FFC0CB', 0.5)}"
>{node.question.questions.length} {m.questionOrQuestions()}</span
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@
{/if}
<div class="flex flex-col w-full place-items-center">
<Accordion regionCaret="flex">
<AccordionItem>
<AccordionItem caretOpen="rotate-0" caretClosed="-rotate-90">
<svelte:fragment slot="summary"
><p class="flex">{m.observation()}</p></svelte:fragment
>
Expand Down Expand Up @@ -348,7 +348,7 @@
</div>
</svelte:fragment>
</AccordionItem>
<AccordionItem>
<AccordionItem caretOpen="rotate-0" caretClosed="-rotate-90">
<svelte:fragment slot="summary"
><p class="flex items-center space-x-2">
<span>{m.evidence()}</span>
Expand Down

0 comments on commit 4de6635

Please sign in to comment.