diff --git a/Makefile b/Makefile index 646c7f91d..ff17c9fca 100644 --- a/Makefile +++ b/Makefile @@ -9,8 +9,10 @@ run-dev: | build-dev stop-dev: docker-compose -f docker/docker-compose.dev.yml down -get-server-shell: - docker-compose -f docker/docker-compose.dev.yml run server bash +server-shell: + docker-compose -f docker/docker-compose.dev.yml run --entrypoint="" server docker/wait-for-dev-dependencies.sh + UID=$$(id -u $${USER}) GID=$$(id -g $${USER}) docker-compose -f docker/docker-compose.dev.yml run --entrypoint="" server bash + docker-compose -f docker/docker-compose.dev.yml down reload-proxy: docker-compose -f docker/docker-compose.dev.yml exec -w /etc/caddy proxy caddy reload diff --git a/autoupdate b/autoupdate index 0197c762d..76d3f5385 160000 --- a/autoupdate +++ b/autoupdate @@ -1 +1 @@ -Subproject commit 0197c762d94c0723b377b0b2773fb329b7ccaeca +Subproject commit 76d3f5385e0a76e79d09d573041a0839d8f483d0 diff --git a/client/src/app/core/repositories/chat/chat-group-repository.service.ts b/client/src/app/core/repositories/chat/chat-group-repository.service.ts index 245bb0ec9..a439707aa 100644 --- a/client/src/app/core/repositories/chat/chat-group-repository.service.ts +++ b/client/src/app/core/repositories/chat/chat-group-repository.service.ts @@ -18,8 +18,14 @@ import { DataStoreService } from '../../core-services/data-store.service'; const ChatGroupRelations: RelationDefinition[] = [ { type: 'M2M', - ownIdKey: 'access_groups_id', - ownKey: 'access_groups', + ownIdKey: 'read_groups_id', + ownKey: 'read_groups', + foreignViewModel: ViewGroup + }, + { + type: 'M2M', + ownIdKey: 'write_groups_id', + ownKey: 'write_groups', foreignViewModel: ViewGroup } ]; diff --git a/client/src/app/shared/animations.ts b/client/src/app/shared/animations.ts index 2e14acd1e..72f2747a1 100644 --- a/client/src/app/shared/animations.ts +++ b/client/src/app/shared/animations.ts @@ -1,5 +1,10 @@ import { animate, state, style, transition, trigger } from '@angular/animations'; +const fadeSpeed = { + fast: 200, + slow: 600 +}; + const slideIn = [style({ transform: 'translateX(-85%)' }), animate('600ms ease')]; const slideOut = [ style({ transform: 'translateX(0)' }), @@ -11,9 +16,15 @@ const slideOut = [ ) ]; +export const collapseAndFade = trigger('collapse', [ + state('in', style({ opacity: 1, height: '100%' })), + transition(':enter', [style({ opacity: 0, height: 0 }), animate(fadeSpeed.fast)]), + transition(':leave', animate(fadeSpeed.fast, style({ opacity: 0, height: 0 }))) +]); + export const fadeAnimation = trigger('fade', [ state('in', style({ opacity: 1 })), - transition(':enter', [style({ opacity: 0 }), animate(600)]), - transition(':leave', animate(600, style({ opacity: 0 }))) + transition(':enter', [style({ opacity: 0 }), animate(fadeSpeed.slow)]), + transition(':leave', animate(fadeSpeed.slow, style({ opacity: 0 }))) ]); export const navItemAnim = trigger('navItemAnim', [transition(':enter', slideIn), transition(':leave', slideOut)]); diff --git a/client/src/app/shared/components/icon-container/icon-container.component.scss b/client/src/app/shared/components/icon-container/icon-container.component.scss index 341d973f5..c8ccb2794 100644 --- a/client/src/app/shared/components/icon-container/icon-container.component.scss +++ b/client/src/app/shared/components/icon-container/icon-container.component.scss @@ -18,10 +18,6 @@ os-icon-container { display: flex; align-items: center; - & + & { - margin-top: 5px; - } - &.small-container { @include icon-container(12px, 12px, 400); } diff --git a/client/src/app/shared/models/chat/chat-group.ts b/client/src/app/shared/models/chat/chat-group.ts index 78d47e751..1de4d1def 100644 --- a/client/src/app/shared/models/chat/chat-group.ts +++ b/client/src/app/shared/models/chat/chat-group.ts @@ -5,7 +5,8 @@ export class ChatGroup extends BaseModel { public id: number; public name: string; - public access_groups_id: number[]; + public read_groups_id: number[]; + public write_groups_id: number[]; public constructor(input?: any) { super(ChatGroup.COLLECTIONSTRING, input); diff --git a/client/src/app/site/chat/components/chat-group-detail/chat-group-detail.component.html b/client/src/app/site/chat/components/chat-group-detail/chat-group-detail.component.html index eb65cc9e1..7b8fc17ff 100644 --- a/client/src/app/site/chat/components/chat-group-detail/chat-group-detail.component.html +++ b/client/src/app/site/chat/components/chat-group-detail/chat-group-detail.component.html @@ -1,17 +1,29 @@
- + {{ group.getTitle() | translate }} , - ... + ... + + + + + + {{ group.getTitle() | translate }} + , + ...
@@ -41,5 +53,4 @@ {{ 'Delete' | translate }} - diff --git a/client/src/app/site/chat/components/chat-group-detail/chat-group-detail.component.ts b/client/src/app/site/chat/components/chat-group-detail/chat-group-detail.component.ts index 60497cb88..343fc1f10 100644 --- a/client/src/app/site/chat/components/chat-group-detail/chat-group-detail.component.ts +++ b/client/src/app/site/chat/components/chat-group-detail/chat-group-detail.component.ts @@ -22,6 +22,7 @@ import { ChatGroup } from 'app/shared/models/chat/chat-group'; import { infoDialogSettings } from 'app/shared/utils/dialog-settings'; import { BaseViewComponentDirective } from 'app/site/base/base-view'; import { ChatNotificationService } from 'app/site/chat/services/chat-notification.service'; +import { ViewGroup } from 'app/site/users/models/view-group'; import { ChatGroupData, EditChatGroupDialogComponent @@ -51,6 +52,12 @@ export class ChatGroupDetailComponent extends BaseViewComponentDirective impleme return isOnBottom; } + public get readOnlyGroups(): ViewGroup[] { + const readGroups = this.chatGroup?.read_groups; + const writeGrous = this.chatGroup?.write_groups; + return readGroups?.filter(group => !writeGrous.includes(group)) || []; + } + public constructor( titleService: Title, protected translate: TranslateService, @@ -111,7 +118,8 @@ export class ChatGroupDetailComponent extends BaseViewComponentDirective impleme public editChat(): void { const chatData: ChatGroupData = { name: this.chatGroup.name, - access_groups_id: this.chatGroup.access_groups_id + read_groups_id: this.chatGroup.read_groups_id, + write_groups_id: this.chatGroup.write_groups_id }; const dialogRef = this.dialog.open(EditChatGroupDialogComponent, { diff --git a/client/src/app/site/chat/components/chat-message/chat-message.component.html b/client/src/app/site/chat/components/chat-message/chat-message.component.html index cf0bcdca6..9d7d5349e 100644 --- a/client/src/app/site/chat/components/chat-message/chat-message.component.html +++ b/client/src/app/site/chat/components/chat-message/chat-message.component.html @@ -4,8 +4,12 @@
{{ text }}
{{ date | localizedDate }}
diff --git a/client/src/app/site/chat/components/chat-tabs/chat-tabs.component.html b/client/src/app/site/chat/components/chat-tabs/chat-tabs.component.html index 44db6b585..342269cfd 100644 --- a/client/src/app/site/chat/components/chat-tabs/chat-tabs.component.html +++ b/client/src/app/site/chat/components/chat-tabs/chat-tabs.component.html @@ -1,9 +1,9 @@ - + @@ -16,14 +16,14 @@ -
+
{{ 'No chat groups available' | translate }}
-
+ {{ 'Message' | translate }} diff --git a/client/src/app/site/chat/components/chat-tabs/chat-tabs.component.ts b/client/src/app/site/chat/components/chat-tabs/chat-tabs.component.ts index e634144c5..f18c5eaa2 100644 --- a/client/src/app/site/chat/components/chat-tabs/chat-tabs.component.ts +++ b/client/src/app/site/chat/components/chat-tabs/chat-tabs.component.ts @@ -7,8 +7,10 @@ import { Title } from '@angular/platform-browser'; import { TranslateService } from '@ngx-translate/core'; import { BehaviorSubject, Observable } from 'rxjs'; +import { OperatorService } from 'app/core/core-services/operator.service'; import { ChatGroupRepositoryService } from 'app/core/repositories/chat/chat-group-repository.service'; import { ChatMessageRepositoryService } from 'app/core/repositories/chat/chat-message-repository.service'; +import { collapseAndFade } from 'app/shared/animations'; import { ChatMessage } from 'app/shared/models/chat/chat-message'; import { BaseViewComponentDirective } from 'app/site/base/base-view'; import { ChatNotificationService, NotificationAmount } from '../../services/chat-notification.service'; @@ -18,7 +20,8 @@ import { ViewChatGroup } from '../../models/view-chat-group'; selector: 'os-chat-tabs', templateUrl: './chat-tabs.component.html', styleUrls: ['./chat-tabs.component.scss'], - encapsulation: ViewEncapsulation.None + encapsulation: ViewEncapsulation.None, + animations: [collapseAndFade] }) export class ChatTabsComponent extends BaseViewComponentDirective implements OnInit { public chatGroupSubject: BehaviorSubject; @@ -27,6 +30,21 @@ export class ChatTabsComponent extends BaseViewComponentDirective implements OnI private notifications: NotificationAmount; + private get chatGroupFromIndex(): ViewChatGroup { + return this.chatGroupSubject.value[this.selectedTabIndex]; + } + + public get chatGroupsExist(): boolean { + return this.chatGroupSubject.value.length > 0; + } + + public get canSendInSelectedChat(): boolean { + if (!this.chatGroupFromIndex) { + return false; + } + return this.operator.isInGroupIds(...this.chatGroupFromIndex?.write_groups_id) || false; + } + public constructor( titleService: Title, translate: TranslateService, @@ -34,6 +52,7 @@ export class ChatTabsComponent extends BaseViewComponentDirective implements OnI private repo: ChatGroupRepositoryService, private chatMessageRepo: ChatMessageRepositoryService, private chatNotificationService: ChatNotificationService, + private operator: OperatorService, formBuilder: FormBuilder ) { super(titleService, translate, matSnackBar); @@ -55,14 +74,10 @@ export class ChatTabsComponent extends BaseViewComponentDirective implements OnI this.selectedTabIndex = event.index; } - public getNotidficationsForChatId(chatId: number): number { + public getNotificationsForChatId(chatId: number): number { return this.notifications?.[chatId] ?? 0; } - public chatGroupsExist(): boolean { - return this.chatGroupSubject.value.length > 0; - } - public isChatMessageEmpty(): boolean { return !this.newMessageForm?.value?.text?.trim(); } @@ -70,7 +85,7 @@ export class ChatTabsComponent extends BaseViewComponentDirective implements OnI public send(): void { const payload = { text: this.newMessageForm.value.text, - chatgroup_id: this.chatGroupSubject.value[this.selectedTabIndex].id + chatgroup_id: this.chatGroupFromIndex.id }; this.chatMessageRepo .create(payload as ChatMessage) diff --git a/client/src/app/site/chat/components/edit-chat-group-dialog/edit-chat-group-dialog.component.html b/client/src/app/site/chat/components/edit-chat-group-dialog/edit-chat-group-dialog.component.html index 9320b025e..7519d1753 100644 --- a/client/src/app/site/chat/components/edit-chat-group-dialog/edit-chat-group-dialog.component.html +++ b/client/src/app/site/chat/components/edit-chat-group-dialog/edit-chat-group-dialog.component.html @@ -24,9 +24,17 @@ + + + diff --git a/client/src/app/site/chat/components/edit-chat-group-dialog/edit-chat-group-dialog.component.ts b/client/src/app/site/chat/components/edit-chat-group-dialog/edit-chat-group-dialog.component.ts index 8f505d037..ca7bb0885 100644 --- a/client/src/app/site/chat/components/edit-chat-group-dialog/edit-chat-group-dialog.component.ts +++ b/client/src/app/site/chat/components/edit-chat-group-dialog/edit-chat-group-dialog.component.ts @@ -10,7 +10,8 @@ import { ViewGroup } from 'app/site/users/models/view-group'; export interface ChatGroupData { name: string; - access_groups_id: number[]; + read_groups_id: number[]; + write_groups_id: number[]; } @Component({ @@ -36,7 +37,8 @@ export class EditChatGroupDialogComponent { this.createMode = !data; this.createUpdateForm = formBuilder.group({ name: [data?.name || '', Validators.required], - access_groups_id: [data?.access_groups_id || []] + read_groups_id: [data?.read_groups_id || []], + write_groups_id: [data?.write_groups_id || []] }); this.groupsBehaviorSubject = groupRepo.getViewModelListBehaviorSubject(); } diff --git a/client/src/app/site/chat/models/view-chat-group.ts b/client/src/app/site/chat/models/view-chat-group.ts index 23a2c19b3..c1dcab5dd 100644 --- a/client/src/app/site/chat/models/view-chat-group.ts +++ b/client/src/app/site/chat/models/view-chat-group.ts @@ -15,5 +15,6 @@ export class ViewChatGroup extends BaseViewModel implements ChatGroup } } export interface ViewChatGroup extends ChatGroup { - access_groups: ViewGroup[]; + read_groups: ViewGroup[]; + write_groups: ViewGroup[]; } diff --git a/client/src/app/site/chat/services/chat.service.ts b/client/src/app/site/chat/services/chat.service.ts index e6c31f444..a7b85f48b 100644 --- a/client/src/app/site/chat/services/chat.service.ts +++ b/client/src/app/site/chat/services/chat.service.ts @@ -18,9 +18,9 @@ export class ChatService { private canSeeSomeChatGroup = false; private canManage = false; - private canSeeChat = new BehaviorSubject(false); + private canSeeChatSubject = new BehaviorSubject(false); public get canSeeChatObservable(): Observable { - return this.canSeeChat.asObservable(); + return this.canSeeChatSubject.asObservable(); } public constructor( @@ -34,7 +34,7 @@ export class ChatService { }); this.repo.getViewModelListBehaviorSubject().subscribe(groups => { - this.canSeeSomeChatGroup = !!groups && groups.length > 0; + this.canSeeSomeChatGroup = groups?.length > 0; this.update(); }); @@ -45,6 +45,6 @@ export class ChatService { } private update(): void { - this.canSeeChat.next(this.chatEnabled && (this.canSeeSomeChatGroup || this.canManage)); + this.canSeeChatSubject.next(this.chatEnabled && (this.canSeeSomeChatGroup || this.canManage)); } } diff --git a/docker/docker-compose.dev.yml b/docker/docker-compose.dev.yml index 9d680394e..8aea37414 100644 --- a/docker/docker-compose.dev.yml +++ b/docker/docker-compose.dev.yml @@ -18,6 +18,7 @@ services: - ../server:/app depends_on: - redis + - postgres postgres: image: postgres:11 diff --git a/server/docker/entrypoint-dev b/server/docker/entrypoint-dev index fb44f22f0..d5ae75895 100755 --- a/server/docker/entrypoint-dev +++ b/server/docker/entrypoint-dev @@ -19,12 +19,7 @@ function isSettingsFileOk() { return 0; } -wait-for-it -t 0 redis:6379 - -until pg_isready -h postgres -p 5432 -U openslides; do - echo "Waiting for Postgres to become available..." - sleep 3 -done +/app/docker/wait-for-dev-dependencies.sh if [[ ! -f "/app/personal_data/var/settings.py" ]]; then echo "Create settings" diff --git a/server/docker/wait-for-dev-dependencies.sh b/server/docker/wait-for-dev-dependencies.sh new file mode 100755 index 000000000..dbb092d71 --- /dev/null +++ b/server/docker/wait-for-dev-dependencies.sh @@ -0,0 +1,10 @@ +#!/bin/bash + +set -e + +wait-for-it -t 0 redis:6379 + +until pg_isready -h postgres -p 5432 -U openslides; do + echo "Waiting for Postgres to become available..." + sleep 3 +done diff --git a/server/manage.py b/server/manage.py old mode 100755 new mode 100644 diff --git a/server/openslides/chat/access_permissions.py b/server/openslides/chat/access_permissions.py index 8a7b9b466..71aff3eb1 100644 --- a/server/openslides/chat/access_permissions.py +++ b/server/openslides/chat/access_permissions.py @@ -7,7 +7,7 @@ from openslides.utils.auth import async_has_perm, async_in_some_groups class ChatGroupAccessPermissions(BaseAccessPermissions): """ Access permissions container for ChatGroup and ChatGroupViewSet. - No base perm: The access permissions are done with the access groups + No base perm: The access permissions are done with the read/write groups. """ async def get_restricted_data( @@ -22,10 +22,11 @@ class ChatGroupAccessPermissions(BaseAccessPermissions): data = full_data else: for full in full_data: - access_groups = full.get("access_groups_id", []) - if len( - full.get("access_groups_id", []) - ) == 0 or await async_in_some_groups(user_id, access_groups): + read_groups = full.get("read_groups_id", []) + write_groups = full.get("write_groups_id", []) + if await async_in_some_groups( + user_id, read_groups + ) or await async_in_some_groups(user_id, write_groups): data.append(full) return data diff --git a/server/openslides/chat/migrations/0002_new_access_groups_1.py b/server/openslides/chat/migrations/0002_new_access_groups_1.py new file mode 100644 index 000000000..4f3af471b --- /dev/null +++ b/server/openslides/chat/migrations/0002_new_access_groups_1.py @@ -0,0 +1,33 @@ +# Generated by Finn Stutzenstein on 2021-02-18 08:12 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ("chat", "0001_initial"), + ("users", "0016_remove_user_ordering"), + ] + + operations = [ + migrations.RenameField( + model_name="chatgroup", + old_name="access_groups", + new_name="read_groups", + ), + migrations.AlterField( + model_name="chatgroup", + name="read_groups", + field=models.ManyToManyField( + blank=True, related_name="chat_read_groups", to="users.Group" + ), + ), + migrations.AddField( + model_name="chatgroup", + name="write_groups", + field=models.ManyToManyField( + blank=True, related_name="chat_write_groups", to="users.Group" + ), + ), + ] diff --git a/server/openslides/chat/migrations/0003_new_access_groups_2.py b/server/openslides/chat/migrations/0003_new_access_groups_2.py new file mode 100644 index 000000000..c7dfbdee4 --- /dev/null +++ b/server/openslides/chat/migrations/0003_new_access_groups_2.py @@ -0,0 +1,19 @@ +# Generated by Finn Stutzenstein on 2021-02-18 08:12 + +from django.db import migrations + + +def copy_read_groups_to_write_groups(apps, schema_editor): + ChatGroup = apps.get_model("chat", "ChatGroup") + + for chatgroup in ChatGroup.objects.all(): + chatgroup.write_groups.add(*chatgroup.read_groups.all()) + + +class Migration(migrations.Migration): + + dependencies = [ + ("chat", "0002_new_access_groups_1"), + ] + + operations = [migrations.RunPython(copy_read_groups_to_write_groups)] diff --git a/server/openslides/chat/models.py b/server/openslides/chat/models.py index d3d1be93d..184fa9edf 100644 --- a/server/openslides/chat/models.py +++ b/server/openslides/chat/models.py @@ -18,7 +18,7 @@ class ChatGroupManager(BaseManager): return ( super() .get_prefetched_queryset(*args, **kwargs) - .prefetch_related("access_groups") + .prefetch_related("read_groups", "write_groups") ) @@ -30,8 +30,11 @@ class ChatGroup(RESTModelMixin, models.Model): objects = ChatGroupManager() name = models.CharField(max_length=256) - access_groups = models.ManyToManyField( - settings.AUTH_GROUP_MODEL, blank=True, related_name="chat_access_groups" + read_groups = models.ManyToManyField( + settings.AUTH_GROUP_MODEL, blank=True, related_name="chat_read_groups" + ) + write_groups = models.ManyToManyField( + settings.AUTH_GROUP_MODEL, blank=True, related_name="chat_write_groups" ) class Meta: @@ -41,14 +44,11 @@ class ChatGroup(RESTModelMixin, models.Model): def __str__(self): return self.name - def can_access(self, user): + def can_write(self, user): if has_perm(user.id, "chat.can_manage"): return True - if not self.access_groups.exists(): - return True - - return in_some_groups(user.id, self.access_groups.values_list(flat=True)) + return in_some_groups(user.id, self.write_groups.values_list(flat=True)) class ChatMessageManager(BaseManager): @@ -61,7 +61,9 @@ class ChatMessageManager(BaseManager): return ( super() .get_prefetched_queryset(*args, **kwargs) - .prefetch_related("chatgroup", "chatgroup__access_groups") + .prefetch_related( + "chatgroup", "chatgroup__read_groups", "chatgroup__write_groups" + ) ) diff --git a/server/openslides/chat/serializers.py b/server/openslides/chat/serializers.py index 6dd563bdf..deae6650b 100644 --- a/server/openslides/chat/serializers.py +++ b/server/openslides/chat/serializers.py @@ -14,7 +14,10 @@ class ChatGroupSerializer(ModelSerializer): Serializer for chat.models.ChatGroup objects. """ - access_groups = IdPrimaryKeyRelatedField( + read_groups = IdPrimaryKeyRelatedField( + many=True, required=False, queryset=get_group_model().objects.all() + ) + write_groups = IdPrimaryKeyRelatedField( many=True, required=False, queryset=get_group_model().objects.all() ) @@ -23,7 +26,8 @@ class ChatGroupSerializer(ModelSerializer): fields = ( "id", "name", - "access_groups", + "read_groups", + "write_groups", ) @@ -35,7 +39,8 @@ class ChatMessageSerializer(ModelSerializer): chatgroup = IdPrimaryKeyRelatedField( required=False, queryset=ChatGroup.objects.all() ) - access_groups_id = SerializerMethodField() + read_groups_id = SerializerMethodField() + write_groups_id = SerializerMethodField() class Meta: model = ChatMessage @@ -46,7 +51,8 @@ class ChatMessageSerializer(ModelSerializer): "timestamp", "username", "user_id", - "access_groups_id", + "read_groups_id", + "write_groups_id", ) read_only_fields = ( "username", @@ -58,5 +64,8 @@ class ChatMessageSerializer(ModelSerializer): data["text"] = validate_html_strict(data["text"]) return data - def get_access_groups_id(self, chatmessage): - return [group.id for group in chatmessage.chatgroup.access_groups.all()] + def get_read_groups_id(self, chatmessage): + return [group.id for group in chatmessage.chatgroup.read_groups.all()] + + def get_write_groups_id(self, chatmessage): + return [group.id for group in chatmessage.chatgroup.write_groups.all()] diff --git a/server/openslides/chat/views.py b/server/openslides/chat/views.py index 96eac207c..d97406a05 100644 --- a/server/openslides/chat/views.py +++ b/server/openslides/chat/views.py @@ -51,8 +51,8 @@ class ChatGroupViewSet(ModelViewSet): def update(self, *args, **kwargs): response = super().update(*args, **kwargs) - # Update all affected chatmessages to update their `access_groups_id` field, - # which is taken from the updated chatgroup. + # Update all affected chatmessages to update their `read_groups_id` and + # `write_groups_id` field, which is taken from the updated chatgroup. inform_changed_data(ChatMessage.objects.filter(chatgroup=self.get_object())) return response @@ -93,7 +93,7 @@ class ChatMessageViewSet( serializer = self.get_serializer(data=request.data) serializer.is_valid(raise_exception=True) - if not serializer.validated_data["chatgroup"].can_access(self.request.user): + if not serializer.validated_data["chatgroup"].can_write(self.request.user): self.permission_denied(self.request) # Do not use the serializer.save since it will put the model in the history. diff --git a/server/openslides/users/views.py b/server/openslides/users/views.py index 77c3688d7..e403cb301 100644 --- a/server/openslides/users/views.py +++ b/server/openslides/users/views.py @@ -22,6 +22,7 @@ from django.http.request import QueryDict from django.utils.encoding import force_bytes, force_text from django.utils.http import urlsafe_base64_decode, urlsafe_base64_encode +from openslides.chat.models import ChatGroup from openslides.saml import SAML_ENABLED from openslides.utils import logging @@ -229,6 +230,7 @@ class UserViewSet(ModelViewSet): old_delegation_user.save() inform_changed_data(user) + inform_changed_data(ChatGroup.objects.all()) return response def assert_vote_not_delegated(self, user): diff --git a/server/tests/integration/chat/test_chat.py b/server/tests/integration/chat/test_chat.py index a2ad6cf52..4d450b90c 100644 --- a/server/tests/integration/chat/test_chat.py +++ b/server/tests/integration/chat/test_chat.py @@ -10,19 +10,24 @@ def test_motion_db_queries(): """ Tests that only the following db queries for chat groups are done: * 1 request to get all chat groups - * 1 request to get all access groups + * 1 request to get all read groups + * 1 request to get all write groups Tests that only the following db queries for chat messages are done: * 1 request to fet all chat messages * 1 request to get all chat groups - * 1 request to get all access groups + * 1 request to get all read groups + * 1 request to get all write groups """ group1 = get_group_model().objects.create(name="group1") group2 = get_group_model().objects.create(name="group2") + group3 = get_group_model().objects.create(name="group3") + group4 = get_group_model().objects.create(name="group4") for i1 in range(5): chatgroup = ChatGroup.objects.create(name=f"motion{i1}") - chatgroup.access_groups.add(group1, group2) + chatgroup.read_groups.add(group1, group2) + chatgroup.write_groups.add(group3, group4) for i2 in range(10): ChatMessage.objects.create( @@ -32,5 +37,5 @@ def test_motion_db_queries(): chatgroup=chatgroup, ) - assert count_queries(ChatGroup.get_elements)() == 2 - assert count_queries(ChatMessage.get_elements)() == 3 + assert count_queries(ChatGroup.get_elements)() == 3 + assert count_queries(ChatMessage.get_elements)() == 4