-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add chat_message collection and update the chat_group collection. * Modify chat_group.create, add a check_name_unique and add a test. * Modify chat_group.update: Add a name unique check, add a test. * Change restriction_mode of user/chat_message_. * Fix models, add missing restriciton_mode. * Fix tests. * Fix example-data. * Fix meeting.clone. * Add the chat_message.create action and tests. * Add chat_message.update action and some tests. * Add chat_message.delete action and some tests. * Add a cascade to chat_group/chat_message_ids. * Add a CheckNameUniqueMixin and use it. Update a test. * Use meeting interferring create action for chat_message.create.
- Loading branch information
Showing
21 changed files
with
388 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,32 @@ | ||
from typing import Any, Dict | ||
|
||
from ....models.models import ChatGroup | ||
from ....permissions.permissions import Permissions | ||
from ....shared.patterns import FullQualifiedId | ||
from ...generics.update import UpdateAction | ||
from ...util.default_schema import DefaultSchema | ||
from ...util.register import register_action | ||
from .mixins import ChatEnabledMixin | ||
from .mixins import ChatEnabledMixin, CheckUniqueNameMixin | ||
|
||
|
||
@register_action("chat_group.update") | ||
class ChatGroupUpdate(ChatEnabledMixin, UpdateAction): | ||
class ChatGroupUpdate(ChatEnabledMixin, CheckUniqueNameMixin, UpdateAction): | ||
""" | ||
Action to update a projector message. | ||
Action to update a chat group. | ||
""" | ||
|
||
model = ChatGroup() | ||
schema = DefaultSchema(ChatGroup()).get_update_schema( | ||
optional_properties=["name", "read_group_ids", "write_group_ids"], | ||
) | ||
permission = Permissions.Chat.CAN_MANAGE | ||
|
||
def update_instance(self, instance: Dict[str, Any]) -> Dict[str, Any]: | ||
instance = super().update_instance(instance) | ||
if "name" in instance: | ||
chat_group = self.datastore.get( | ||
FullQualifiedId(self.model.collection, instance["id"]), ["name"] | ||
) | ||
if instance["name"] != chat_group.get("name"): | ||
self.check_name_unique(instance) | ||
return instance |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from . import create, delete, update # noqa |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
from time import time | ||
from typing import Any, Dict | ||
|
||
from ....models.models import ChatMessage | ||
from ....shared.exceptions import PermissionDenied | ||
from ....shared.patterns import Collection, FullQualifiedId | ||
from ...mixins.create_action_with_inferred_meeting import ( | ||
CreateActionWithInferredMeeting, | ||
) | ||
from ...util.default_schema import DefaultSchema | ||
from ...util.register import register_action | ||
|
||
|
||
@register_action("chat_message.create") | ||
class ChatMessageCreate(CreateActionWithInferredMeeting): | ||
""" | ||
Action to create a chat message. | ||
""" | ||
|
||
model = ChatMessage() | ||
schema = DefaultSchema(ChatMessage()).get_create_schema( | ||
required_properties=["chat_group_id", "content"], | ||
) | ||
relation_field_for_meeting = "chat_group_id" | ||
|
||
def update_instance(self, instance: Dict[str, Any]) -> Dict[str, Any]: | ||
instance = super().update_instance(instance) | ||
instance["user_id"] = self.user_id | ||
instance["created"] = round(time()) | ||
return instance | ||
|
||
def check_permissions(self, instance: Dict[str, Any]) -> None: | ||
chat_group = self.datastore.get( | ||
FullQualifiedId(Collection("chat_group"), instance["chat_group_id"]), | ||
["meeting_id", "write_group_ids"], | ||
) | ||
write_group_set = set(chat_group.get("write_group_ids", [])) | ||
meeting_id = chat_group["meeting_id"] | ||
user = self.datastore.get( | ||
FullQualifiedId(Collection("user"), self.user_id), | ||
[f"group_${meeting_id}_ids"], | ||
) | ||
user_group_set = set(user.get(f"group_${meeting_id}_ids", [])) | ||
if not (write_group_set & user_group_set): | ||
raise PermissionDenied("You are not allowed to write in this chat group.") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
from typing import Any, Dict | ||
|
||
from ....models.models import ChatMessage | ||
from ....permissions.permission_helper import has_perm | ||
from ....permissions.permissions import Permissions | ||
from ....shared.exceptions import PermissionDenied | ||
from ....shared.patterns import FullQualifiedId | ||
from ...generics.delete import DeleteAction | ||
from ...util.default_schema import DefaultSchema | ||
from ...util.register import register_action | ||
|
||
|
||
@register_action("chat_message.delete") | ||
class ChatMessageDelete(DeleteAction): | ||
""" | ||
Action to delet a chat message. | ||
""" | ||
|
||
model = ChatMessage() | ||
schema = DefaultSchema(ChatMessage()).get_delete_schema() | ||
|
||
def check_permissions(self, instance: Dict[str, Any]) -> None: | ||
chat_message = self.datastore.get( | ||
FullQualifiedId(self.model.collection, instance["id"]), | ||
["user_id", "meeting_id"], | ||
) | ||
if chat_message.get("user_id") != self.user_id and not has_perm( | ||
self.datastore, | ||
self.user_id, | ||
Permissions.Chat.CAN_MANAGE, | ||
chat_message["meeting_id"], | ||
): | ||
raise PermissionDenied( | ||
"You are not allowed to perform action chat_message.delete" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
from typing import Any, Dict | ||
|
||
from ....models.models import ChatMessage | ||
from ....shared.exceptions import PermissionDenied | ||
from ....shared.patterns import FullQualifiedId | ||
from ...generics.update import UpdateAction | ||
from ...util.default_schema import DefaultSchema | ||
from ...util.register import register_action | ||
|
||
|
||
@register_action("chat_message.update") | ||
class ChatMessageUpdate(UpdateAction): | ||
""" | ||
Action to update a chat message. | ||
""" | ||
|
||
model = ChatMessage() | ||
schema = DefaultSchema(ChatMessage()).get_update_schema( | ||
optional_properties=["content"], | ||
) | ||
|
||
def check_permissions(self, instance: Dict[str, Any]) -> None: | ||
chat_message = self.datastore.get( | ||
FullQualifiedId(self.model.collection, instance["id"]), ["user_id"] | ||
) | ||
if chat_message.get("user_id") != self.user_id: | ||
raise PermissionDenied("You must be creator of a chat message to edit it.") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.