Skip to content

Commit 6c03ff1

Browse files
authored
Merge pull request #119 from PROCOLLAB-github/dev
Supermassive PR - too much fixes and features
2 parents 969d307 + ec76d53 commit 6c03ff1

57 files changed

Lines changed: 4083 additions & 1148 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,5 +135,4 @@ dmypy.json
135135

136136
cache
137137

138-
static
139138
staticfiles

chats/consumers/chat.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -205,8 +205,3 @@ async def __process_general_event(self, event: Event, room_name: str):
205205
# await self.close(200)
206206
else:
207207
raise ValueError("Unknown event type")
208-
209-
210-
class NotificationConsumer(AsyncJsonWebsocketConsumer):
211-
# TODO: implement this
212-
pass

chats/consumers/event_types/DirectEvent.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
from chats.models import DirectChatMessage, DirectChat
22
from chats.websockets_settings import Event, EventType
33
from asgiref.sync import sync_to_async
4-
from chats.exceptions import WrongChatIdException, UserNotMessageAuthorException
4+
from chats.exceptions import (
5+
WrongChatIdException,
6+
UserNotMessageAuthorException,
7+
UserIsNotAuthor,
8+
)
59
from django.core.cache import cache
610
from chats.utils import (
711
get_user_channel_cache_key,
@@ -80,7 +84,7 @@ async def process_read_message_event(self, event: Event, room_name: str):
8084
msg = await sync_to_async(DirectChatMessage.objects.get)(
8185
pk=event.content["message_id"]
8286
)
83-
if msg.chat_id != chat_id or msg.author_id != other_user:
87+
if msg.chat_id != chat_id or msg.author_id != other_user.id:
8488
raise WrongChatIdException(
8589
"Some of chat/message ids are wrong, you can't access this message"
8690
)
@@ -106,6 +110,10 @@ async def process_delete_message_event(self, event: Event, room_name: str):
106110
message_id = event.content["message_id"]
107111

108112
message = await sync_to_async(DirectChatMessage.objects.get)(pk=message_id)
113+
114+
if self.user.id != message.author_id:
115+
raise UserIsNotAuthor(f"User {self.user.id} is not author {message.text}")
116+
109117
message.is_deleted = True
110118
await sync_to_async(message.save)()
111119

chats/consumers/event_types/ProjectEvent.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
WrongChatIdException,
77
UserNotInChatException,
88
UserNotMessageAuthorException,
9+
UserIsNotAuthor,
910
)
1011

1112
from chats.serializers import (
@@ -74,7 +75,10 @@ async def process_read_message_event(self, event: Event, room_name: str):
7475
raise UserNotInChatException(
7576
f"User {self.user.id} is not in project chat {msg.chat_id}"
7677
)
77-
if msg.chat_id != event.content["chat_id"]:
78+
same_chat = await sync_to_async(ProjectChat.objects.get)(
79+
pk=event.content["chat_id"]
80+
)
81+
if msg.chat_id != same_chat.id:
7882
raise WrongChatIdException(
7983
"Some of chat/message ids are wrong, you can't access this message"
8084
)
@@ -107,6 +111,9 @@ async def process_delete_message_event(self, event: Event, room_name: str):
107111
message = await sync_to_async(ProjectChatMessage.objects.get)(
108112
pk=event.content["message_id"]
109113
)
114+
115+
if self.user.id != message.author_id:
116+
raise UserIsNotAuthor(f"User {self.user.id} is not author {chat_id}")
110117
message.is_deleted = True
111118
await sync_to_async(message.save)()
112119

chats/consumers/notification.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from channels.generic.websocket import AsyncJsonWebsocketConsumer
22

33

4-
class ChatConsumer(AsyncJsonWebsocketConsumer):
4+
class NotificationConsumer(AsyncJsonWebsocketConsumer):
5+
# TODO: implement this
56
pass

chats/exceptions.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ class UserNotInChatException(ChatException):
1515
pass
1616

1717

18+
class UserIsNotAuthor(ChatException):
19+
pass
20+
21+
1822
class UserNotMessageAuthorException(ChatException):
1923
pass
2024

chats/migrations/0007_remove_directchatmessage_file_url_and_more.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Generated by Django 4.1.3 on 2023-03-22 20:27
1+
# Generated by Django 4.1.3 on 2023-04-03 13:04
22

33
from django.db import migrations
44

@@ -10,7 +10,6 @@ class Migration(migrations.Migration):
1010
]
1111

1212
operations = [
13-
1413
migrations.DeleteModel(
1514
name="ChatAttachment",
1615
),
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Generated by Django 4.1.3 on 2023-04-04 11:48
2+
3+
from django.db import migrations, models
4+
import django.db.models.deletion
5+
6+
7+
class Migration(migrations.Migration):
8+
9+
dependencies = [
10+
("chats", "0010_alter_filetomessage_file"),
11+
]
12+
13+
operations = [
14+
migrations.AlterField(
15+
model_name="filetomessage",
16+
name="direct_message",
17+
field=models.ForeignKey(
18+
null=True,
19+
on_delete=django.db.models.deletion.CASCADE,
20+
related_name="file_to_message",
21+
to="chats.directchatmessage",
22+
),
23+
),
24+
migrations.AlterField(
25+
model_name="filetomessage",
26+
name="project_message",
27+
field=models.ForeignKey(
28+
null=True,
29+
on_delete=django.db.models.deletion.CASCADE,
30+
related_name="file_to_message",
31+
to="chats.projectchatmessage",
32+
),
33+
),
34+
]

chats/tests/__init__.py

Whitespace-only changes.

chats/tests/constants.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
TEST_USER1 = {
2+
"email": "only_for_test@test.test",
3+
"password": "very_strong_password",
4+
"first_name": "Test1",
5+
"last_name": "Test1",
6+
"birthday": "2000-01-01",
7+
}
8+
TEST_USER2 = {
9+
"email": "test@test.test",
10+
"password": "very_strong_password",
11+
"first_name": "Test2",
12+
"last_name": "Test2",
13+
"birthday": "2000-01-01",
14+
}
15+
TEST_USER3 = {
16+
"email": "test2@test.test",
17+
"password": "very_strong_password",
18+
"first_name": "Test3",
19+
"last_name": "Test3",
20+
"birthday": "2000-01-01",
21+
}

0 commit comments

Comments
 (0)