Skip to content

Commit

Permalink
Fix conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
Yakser committed Jul 25, 2023
2 parents cc1522f + 553918a commit bc5f3a8
Show file tree
Hide file tree
Showing 100 changed files with 4,190 additions and 1,518 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/django-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ jobs:
steps:
- uses: actions/checkout@v2

- name: Set up Python 3.9
- name: Set up Python 3.11
uses: actions/setup-python@v2
with:
python-version: 3.9
python-version: 3.11

- name: cache poetry install
uses: actions/cache@v2
Expand Down Expand Up @@ -46,4 +46,4 @@ jobs:
- name: Run tests
run: poetry run python manage.py test
env:
DEBUG: True
DEBUG: True
2 changes: 1 addition & 1 deletion .github/workflows/lints.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.9]
python-version: [3.11]
steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/release-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ jobs:
steps:
- uses: actions/checkout@v2

- name: Set up Python 3.9
- name: Set up Python 3.11
uses: actions/setup-python@v2
with:
python-version: 3.9
python-version: 3.11

- name: cache poetry install
uses: actions/cache@v2
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -135,5 +135,5 @@ dmypy.json

cache

staticfiles
static
/emails/
10 changes: 1 addition & 9 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,12 +1,4 @@
FROM node:16 as emails

RUN mkdir build
WORKDIR /build

COPY ./scripts ./scripts


FROM python:3.9
FROM python:3.11

RUN apt update --no-install-recommends -y

Expand Down
8 changes: 4 additions & 4 deletions chats/consumers/chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ async def connect(self):
async for project_id in project_ids_list:
# FIXME: if a user is a leader but not a collaborator, this doesn't work
# upd: it seems not possible to be a leader without being a collaborator
# join room for each project
# It's currently not possible to do this in a single call,
# so we have to do it in a loop (e.g. that's O(N) calls to layer backend, redis cache that would be)
# join room for each project -
# It's currently not possible to do this in a single call, -
# so we have to do it in a loop (e.g. that's O(N) calls to layer backend, redis cache that would be) -
await self.channel_layer.group_add(
f"{EventGroupType.CHATS_RELATED}_{project_id}", self.channel_name
)
Expand All @@ -65,7 +65,7 @@ async def connect(self):
await self.accept()

async def disconnect(self, close_code):
"""User disconnected from websocket, Don't have to do anything here"""
"""User disconnected from websocket"""
pass

async def receive_json(self, content, **kwargs):
Expand Down
35 changes: 18 additions & 17 deletions chats/tests/test_direct.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@


class DirectTests(TestCase):
"""Direct tests for chats"""
@classmethod
def setUpTestData(cls):
user = get_user_model().objects.create(**TEST_USER1)
Expand All @@ -21,7 +22,7 @@ async def test_connect_with_crutch(self):

async def test_send_new_message_direct_with_myself(
self,
): # Сообщения в чат с самим собой
): # Chat messages with yourself
communicator = WebsocketCommunicator(ChatConsumer.as_asgi(), "/ws/chat/")
communicator.scope["user"] = self.user
connected, subprotocol = await communicator.connect()
Expand All @@ -41,15 +42,15 @@ async def test_send_new_message_direct_with_myself(
self.assertFalse("error" in response.keys())
content = response["content"]
message = content["message"]
# Проверка input == output
# Checking input == output
self.assertEqual(response["type"], data["type"])
self.assertEqual(data["content"]["chat_id"], content["chat_id"])
self.assertEqual(data["content"]["text"], message["text"])
self.assertEqual(data["content"]["reply_to"], message["reply_to"])
self.assertEqual(data["content"]["is_edited"], message["is_edited"])
self.assertFalse(message["is_deleted"])

async def test_send_new_message_to_orher_chat(self): # Сообщение в чужой чат
async def test_send_new_message_to_other_chat(self): # Message in someone else's chat
await sync_to_async(get_user_model().objects.create)(**TEST_USER2)
user = await sync_to_async(get_user_model().objects.create)(**TEST_USER3)
communicator = WebsocketCommunicator(ChatConsumer.as_asgi(), "/ws/chat/")
Expand All @@ -72,7 +73,7 @@ async def test_send_new_message_to_orher_chat(self): # Сообщение в ч

async def test_is_edited_new_message_direct_with_myself(
self,
): # Проверка на редактированность нового сообщения
): # Checking if a new message has been edited
communicator = WebsocketCommunicator(ChatConsumer.as_asgi(), "/ws/chat/")
communicator.scope["user"] = self.user
connected, subprotocol = await communicator.connect()
Expand All @@ -92,7 +93,7 @@ async def test_is_edited_new_message_direct_with_myself(
message = response["content"]["message"]
self.assertTrue(message["is_edited"] != data["content"]["is_edited"])

async def test_new_message_with_two_users(self): # Чат на двоих новое сообщение
async def test_new_message_with_two_users(self): # New message for private messages
await sync_to_async(get_user_model().objects.create)(**TEST_USER2)
communicator = WebsocketCommunicator(ChatConsumer.as_asgi(), "/ws/chat/")
communicator.scope["user"] = self.user
Expand All @@ -114,7 +115,7 @@ async def test_new_message_with_two_users(self): # Чат на двоих но

async def test_read_message_with_new_user(
self,
): # Чтение чужих сообщений в своём чате
): # Reading other people's messages in your chat
user = await sync_to_async(get_user_model().objects.create)(**TEST_USER2)
communicator = WebsocketCommunicator(ChatConsumer.as_asgi(), "/ws/chat/")
communicator.scope["user"] = user
Expand Down Expand Up @@ -154,7 +155,7 @@ async def test_read_message_with_new_user(
self.assertFalse("error" in response.keys())
self.assertTrue(direct_message.is_read)

async def test_read_message_with_myself(self): # Чтение своих сообщений
async def test_read_message_with_myself(self):
user = await sync_to_async(get_user_model().objects.create)(**TEST_USER2)
communicator = WebsocketCommunicator(ChatConsumer.as_asgi(), "/ws/chat/")
communicator.scope["user"] = user
Expand Down Expand Up @@ -191,7 +192,7 @@ async def test_read_message_with_myself(self): # Чтение своих соо

async def test_read_someone_elses_message(
self,
): # Чтение чужих сообщение в чужом чате
): # Reading someone else's message in someone else's chat
await sync_to_async(get_user_model().objects.create)(**TEST_USER2)
user = await sync_to_async(get_user_model().objects.create)(**TEST_USER3)
communicator = WebsocketCommunicator(ChatConsumer.as_asgi(), "/ws/chat/")
Expand Down Expand Up @@ -232,7 +233,7 @@ async def test_read_someone_elses_message(
self.assertTrue("error" in response.keys())
self.assertFalse(direct_message.is_read)

async def test_edit_my_message_in_myself(self): # Редактирование в чате с самим собой
async def test_edit_my_message_in_myself(self):
communicator = WebsocketCommunicator(ChatConsumer.as_asgi(), "/ws/chat/")
communicator.scope["user"] = self.user
connected, subprotocol = await communicator.connect()
Expand Down Expand Up @@ -267,7 +268,7 @@ async def test_edit_my_message_in_myself(self): # Редактирование
self.assertTrue(direct_message.is_edited)
self.assertEqual(direct_message.text, text)

async def test_edit_my_message(self): # Редактирование в чате с кем-то
async def test_edit_my_message(self): # Editing while chatting with someone
await sync_to_async(get_user_model().objects.create)(**TEST_USER2)
communicator = WebsocketCommunicator(ChatConsumer.as_asgi(), "/ws/chat/")
communicator.scope["user"] = self.user
Expand Down Expand Up @@ -305,7 +306,7 @@ async def test_edit_my_message(self): # Редактирование в чат

async def test_edit_other_message(
self,
): # Редактирование чужих сообщений в своём чате
): # Editing other people's messages in your chat
user = await sync_to_async(get_user_model().objects.create)(**TEST_USER2)
communicator = WebsocketCommunicator(ChatConsumer.as_asgi(), "/ws/chat/")
communicator.scope["user"] = self.user
Expand Down Expand Up @@ -346,9 +347,9 @@ async def test_edit_other_message(
self.assertFalse(direct_message.is_edited)
self.assertTrue(direct_message.text != text)

async def test_edit_other_message_in_other_char(
async def test_edit_other_message_in_other_chat(
self,
): # Редактирование чужих сообщений в чужом чате
):
await sync_to_async(get_user_model().objects.create)(**TEST_USER2)
user = await sync_to_async(get_user_model().objects.create)(**TEST_USER3)
communicator = WebsocketCommunicator(ChatConsumer.as_asgi(), "/ws/chat/")
Expand Down Expand Up @@ -393,7 +394,7 @@ async def test_edit_other_message_in_other_char(

async def test_delete_message_in_myself(
self,
): # Удаление сообщений в чате с самим собой
):
communicator = WebsocketCommunicator(ChatConsumer.as_asgi(), "/ws/chat/")
communicator.scope["user"] = self.user
connected, subprotocol = await communicator.connect()
Expand Down Expand Up @@ -425,7 +426,7 @@ async def test_delete_message_in_myself(
direct_message = await sync_to_async(DirectChatMessage.objects.get)(id=1)
self.assertTrue(direct_message.is_deleted)

async def test_delete_message(self): # Удаление сообщений в чате с кем-то
async def test_delete_message(self): # Delete messages in a chat with someone
await sync_to_async(get_user_model().objects.create)(**TEST_USER2)
communicator = WebsocketCommunicator(ChatConsumer.as_asgi(), "/ws/chat/")
communicator.scope["user"] = self.user
Expand Down Expand Up @@ -458,7 +459,7 @@ async def test_delete_message(self): # Удаление сообщений в
direct_message = await sync_to_async(DirectChatMessage.objects.get)(id=1)
self.assertTrue(direct_message.is_deleted)

async def test_delete_other_message(self): # Удаление чужих сообщений в чате с кем-то
async def test_delete_other_message(self): # Delete someone else's messages in a chat with someone
user = await sync_to_async(get_user_model().objects.create)(**TEST_USER2)
communicator = WebsocketCommunicator(ChatConsumer.as_asgi(), "/ws/chat/")
communicator.scope["user"] = self.user
Expand Down Expand Up @@ -498,7 +499,7 @@ async def test_delete_other_message(self): # Удаление чужих соо

async def test_delete_other_message_in_other_chat(
self,
): # Удаление чужих сообщений в чужом чате
): # Deleting someone else's messages in someone else's chat
await sync_to_async(get_user_model().objects.create)(**TEST_USER2)
user = await sync_to_async(get_user_model().objects.create)(**TEST_USER3)
communicator = WebsocketCommunicator(ChatConsumer.as_asgi(), "/ws/chat/")
Expand Down
2 changes: 1 addition & 1 deletion chats/tests/test_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from chats.consumers import ChatConsumer
from asgiref.sync import sync_to_async

# from chats.tests.helpres import chat_connect
# from chats.tests.helpres import chat_connect -
from projects.models import Project, Collaborator
from chats.models import ProjectChat, ProjectChatMessage
from chats.websockets_settings import EventType
Expand Down
6 changes: 3 additions & 3 deletions chats/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@

def clean_message_text(text: str) -> str:
"""
Cleans message text.
Cleans message text. -
"""

return text.strip()


def validate_message_text(text: str) -> bool:
"""
Validates message text.
Validates message text. -
"""
# TODO: add bad word filter
return 0 < len(text) <= 8192
Expand Down Expand Up @@ -118,7 +118,7 @@ async def match_files_and_messages(file_urls, messages):


def get_all_files(messages):
# looks like something bad
# looks like something bad -
files = []
for message in messages:
if hasattr(message, "file_to_message"):
Expand Down
2 changes: 1 addition & 1 deletion chats/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def get(self, request, *args, **kwargs) -> Response:
data = DirectChatDetailSerializer(DirectChat.get_chat(user1, user2)).data

if user1 == request.user:
# may be is better to use serializer or return dict
# may be is better to use serializer or return dict -
# {"first_name": user2.first_name, "last_name": user2.last_name}
data["name"] = f"{user2.first_name} {user2.last_name}"
data["image_address"] = user2.avatar
Expand Down
20 changes: 20 additions & 0 deletions core/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from django.contrib import admin
from core.models import Like, View, Link


@admin.register(Like)
class LikeAdmin(admin.ModelAdmin):
list_display = ("id", "user", "content_type", "object_id", "content_object")
list_display_links = ("id", "user", "content_type", "object_id", "content_object")


@admin.register(View)
class ViewAdmin(admin.ModelAdmin):
list_display = ("id", "user", "content_type", "object_id", "content_object")
list_display_links = ("id", "user", "content_type", "object_id", "content_object")


@admin.register(Link)
class LinkAdmin(admin.ModelAdmin):
list_display = ("id", "link", "content_type", "object_id", "content_object")
list_display_links = ("id", "link", "content_type", "object_id", "content_object")
2 changes: 2 additions & 0 deletions core/constants.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
ONE_DAY_IN_SECONDS = 60 * 60 * 24
ONE_WEEK_IN_SECONDS = ONE_DAY_IN_SECONDS * 7
VIEWS_CACHING_TIMEOUT = 60 * 1
LIKES_CACHING_TIMEOUT = 60 * 1
54 changes: 54 additions & 0 deletions core/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# Generated by Django 4.2 on 2023-06-08 20:05

from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

initial = True

dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
("contenttypes", "0002_remove_content_type_name"),
]

operations = [
migrations.CreateModel(
name="Like",
fields=[
(
"id",
models.BigAutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
("object_id", models.PositiveIntegerField()),
(
"content_type",
models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE,
related_name="likes",
to="contenttypes.contenttype",
),
),
(
"user",
models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE,
related_name="likes",
to=settings.AUTH_USER_MODEL,
),
),
],
options={
"verbose_name": "Лайк",
"verbose_name_plural": "Лайки",
"unique_together": {("user", "content_type", "object_id")},
},
),
]
Loading

0 comments on commit bc5f3a8

Please sign in to comment.