Skip to content

Commit

Permalink
Merge branch 'ws-connection-loss' into 'main'
Browse files Browse the repository at this point in the history
Ws connection loss

See merge request reportcreator/reportcreator!604
  • Loading branch information
MWedl committed Jul 3, 2024
2 parents 5678db8 + be8064c commit 19836ce
Show file tree
Hide file tree
Showing 11 changed files with 2,080 additions and 896 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@
* Show backup history in web interface
* Store last usage date for API tokens
* Allow duplicating findings
* Fix template pagination error for templates without CVSS score
* Compress PDFs to reduce file sizes
* Use redis as channels layer instead of postgres for collaborative editing
* Fix template pagination error for templates without CVSS score
* Fix multiple bugs in collaborative editing over websockets
* UI: Add button to copy confirm text in delete confirm dialogs
* UI: Fix create finding dialog searchbar cleared on click outside
* UI: Sticky toolbar in markdown editor
Expand Down
2,310 changes: 1,817 additions & 493 deletions api/NOTICE

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions api/generate_notice.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ allow_only="$allow_only;Mozilla Public License 2.0 (MPL 2.0)"
allow_only="$allow_only;Historical Permission Notice and Disclaimer (HPND)"
allow_only="$allow_only;Python Software Foundation License"
allow_only="$allow_only;Zope Public License"
allow_only="$allow_only;ISC License (ISCL)"
allow_only="$allow_only;The Unlicense (Unlicense)"

ignore="webencodings"
ignore="$ignore pyphen"
Expand Down
576 changes: 223 additions & 353 deletions api/poetry.lock

Large diffs are not rendered by default.

5 changes: 2 additions & 3 deletions api/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ django = { extras = ["argon2"], version = "~5.0" }
djangorestframework = "~3.15.0"
weasyprint = "~62.3"

django-phonenumber-field = { version = "^7.0.0", extras = ["phonenumberslite"] }
django-phonenumber-field = { version = "^8.0.0", extras = ["phonenumberslite"] }
django-csp = "^3.7"
django-storages = "^1.13.2"
drf-nested-routers = "^0.94.1"
Expand All @@ -25,8 +25,7 @@ gunicorn = "^22.0.0"
uvicorn = { extras = ["standard"], version = "^0.30.1" }
whitenoise = "^6.4.0"
brotli = "^1.0.9"
channels = { "extras" = ["daphne"], version = "^4.0.0" }
channels-postgres = "^1.0.4"
channels = { "extras" = ["daphne"], version = "^4.1.0" }
channels-redis = "^4.2.0"


Expand Down
16 changes: 1 addition & 15 deletions api/src/reportcreator_api/conf/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@
'drf_spectacular_sidecar',
'simple_history',
'channels',
'channels_postgres',

'reportcreator_api',
'reportcreator_api.users',
Expand Down Expand Up @@ -183,15 +182,7 @@
},
}
else:
CHANNEL_LAYERS = {
'default': {
'BACKEND': 'reportcreator_api.pentests.collab.channels.CustomizedPostgresChannelLayer',
'CONFIG': DATABASES['default'] | {
'TIME_ZONE': TIME_ZONE,
'group_expiry': 60,
},
},
}
CHANNEL_LAYERS = {}



Expand Down Expand Up @@ -716,10 +707,5 @@ def __bool__(self):
'handlers': logging_handlers,
'propagate': False,
},
'channels_postgres.core': {
'level': 'ERROR',
'handlers': logging_handlers,
'propagate': False,
},
},
}
10 changes: 0 additions & 10 deletions api/src/reportcreator_api/pentests/collab/channels.py

This file was deleted.

10 changes: 6 additions & 4 deletions api/src/reportcreator_api/pentests/collab/consumer_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,27 +200,29 @@ async def get_disconnect_message(self):
}

async def connect(self):
if not await self.check_permission(action='connect'):
if not await self.check_permission(action='connect') or not self.channel_layer:
raise DenyConnection()

await super().connect()
await self.channel_layer.group_add(self.group_name, self.channel_name)

await self.create_client_info()
if initial_msg := await self.get_initial_message():
await self.send_json(initial_msg)

await self.channel_layer.group_add(self.group_name, self.channel_name)
if connect_msg := await self.get_connect_message():
await self.send_colllab_event(connect_msg)

async def disconnect(self, close_code):
await self.channel_layer.group_discard(self.group_name, self.channel_name)
if self.channel_layer:
await self.channel_layer.group_discard(self.group_name, self.channel_name)
await self.delete_client_info()
if disconnect_msg := await self.get_disconnect_message():
await self.send_colllab_event(disconnect_msg)
await super().disconnect(close_code)

async def send_colllab_event(self, event):
if not event:
if not event or not self.channel_layer:
return
elif isinstance(event, CollabEvent):
await self.channel_layer.group_send(self.group_name, {
Expand Down
22 changes: 12 additions & 10 deletions api/src/reportcreator_api/pentests/consumers.py
Original file line number Diff line number Diff line change
Expand Up @@ -492,18 +492,20 @@ def collab_delete(self, content):
def send_collab_event_project(event: CollabEvent):
group_name = f'project_{event.related_id}'
layer = get_channel_layer()
async_to_sync(layer.group_send)(group_name, {
'type': 'collab_event',
'id': str(event.id),
'path': event.path,
})
if layer:
async_to_sync(layer.group_send)(group_name, {
'type': 'collab_event',
'id': str(event.id),
'path': event.path,
})


def send_collab_event_user(event: CollabEvent):
group_name = f'user_{event.related_id}'
layer = get_channel_layer()
async_to_sync(layer.group_send)(group_name, {
'type': 'collab_event',
'id': str(event.id),
'path': event.path,
})
if layer:
async_to_sync(layer.group_send)(group_name, {
'type': 'collab_event',
'id': str(event.id),
'path': event.path,
})
7 changes: 7 additions & 0 deletions deploy/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ services:
retries: 30
restart: unless-stopped
stop_grace_period: 120s
redis:
image: bitnami/redis:7.2
environment:
REDIS_PASSWORD: reportcreator
expose:
- 6379
app:
build:
context: ../
Expand All @@ -46,6 +52,7 @@ services:
DATABASE_NAME: reportcreator
DATABASE_USER: reportcreator
DATABASE_PASSWORD: reportcreator
REDIS_URL: redis://:reportcreator@redis:6379/0
HTTP_PROXY: ${HTTP_PROXY-}
HTTPS_PROXY: ${HTTPS_PROXY-}
env_file: app.env
Expand Down
14 changes: 7 additions & 7 deletions dev/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ services:
timeout: 5s
retries: 30
stop_grace_period: 120s
# redis:
# image: bitnami/redis:7.2
# environment:
# REDIS_PASSWORD: reportcreator
# expose:
# - 6379
redis:
image: bitnami/redis:7.2
environment:
REDIS_PASSWORD: reportcreator
expose:
- 6379
# rabbitmq:
# image: rabbitmq:3
# hostname: rabbitmq
Expand Down Expand Up @@ -136,7 +136,7 @@ services:
DATABASE_USER: reportcreator
DATABASE_PASSWORD: reportcreator
SPELLCHECK_URL: http://languagetool:8010/
# REDIS_URL: redis://:reportcreator@redis:6379/0
REDIS_URL: redis://:reportcreator@redis:6379/0
# CELERY_BROKER_URL: amqp://reportcreator:reportcreator@rabbitmq:5672/
# CELERY_RESULT_BACKEND: reportcreator_api.tasks.rendering.celery_worker:CustomRPCBackend://reportcreator:reportcreator@rabbitmq:5672/
env_file: ../deploy/app.env
Expand Down

0 comments on commit 19836ce

Please sign in to comment.