-
Notifications
You must be signed in to change notification settings - Fork 1
Chat Sharing #200
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
LennartSchmidtKern
wants to merge
12
commits into
dev
Choose a base branch
from
conversation-sharing
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Chat Sharing #200
Changes from 10 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
53b7d26
share table
LennartSchmidtKern 48a1bcf
index and deletions shared conversation
LennartSchmidtKern 8589b8b
global update
LennartSchmidtKern 682442e
global sharing
LennartSchmidtKern 6ea7b36
Merge branch 'dev' into conversation-sharing
LennartSchmidtKern 05e1364
merge
LennartSchmidtKern ad77b35
get by user global share
LennartSchmidtKern bd41e25
adding project sharing settings
LennartSchmidtKern 769f600
user management and project and tags
LennartSchmidtKern a184024
get global share
LennartSchmidtKern f890096
PR comments
LennartSchmidtKern f4b9d5d
filter conversation tags by user
LennartSchmidtKern File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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,68 @@ | ||
| from operator import or_ | ||
| from typing import List, Optional | ||
| from ..business_objects import general | ||
| from ..session import session | ||
| from ..models import CognitionConversation, ConversationGlobalShare | ||
| from submodules.model.util import sql_alchemy_to_dict | ||
|
|
||
|
|
||
| def get(conversation_global_share_id: str) -> Optional[ConversationGlobalShare]: | ||
| return ( | ||
| session.query(ConversationGlobalShare) | ||
| .filter(ConversationGlobalShare.id == conversation_global_share_id) | ||
| .first() | ||
| ) | ||
|
|
||
|
|
||
| def get_by_conversation(conversation_id: str) -> List[ConversationGlobalShare]: | ||
LennartSchmidtKern marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| return ( | ||
| session.query(ConversationGlobalShare) | ||
| .filter(ConversationGlobalShare.conversation_id == conversation_id) | ||
| .first() | ||
| ) | ||
|
|
||
|
|
||
| def create( | ||
| conversation_id: str, | ||
| shared_by: str, | ||
| with_commit: bool = True, | ||
| ) -> ConversationGlobalShare: | ||
| global_share = ConversationGlobalShare( | ||
| conversation_id=conversation_id, shared_by=shared_by | ||
| ) | ||
| general.add(global_share, with_commit) | ||
| return global_share | ||
|
|
||
|
|
||
| def delete_by_conversation( | ||
| conversation_id: str, user_id: str, with_commit: bool = True | ||
| ): | ||
| ( | ||
| session.query(ConversationGlobalShare) | ||
| .filter( | ||
| ConversationGlobalShare.conversation_id == conversation_id, | ||
| ConversationGlobalShare.shared_by == user_id, | ||
| ) | ||
| .delete() | ||
| ) | ||
| if with_commit: | ||
| session.commit() | ||
LennartSchmidtKern marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
|
|
||
| def get_by_user(project_id: str, user_id: str) -> List[ConversationGlobalShare]: | ||
LennartSchmidtKern marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| conversation_global_shares = ( | ||
| session.query(ConversationGlobalShare, CognitionConversation.header) | ||
| .join( | ||
| CognitionConversation, | ||
| ConversationGlobalShare.conversation_id == CognitionConversation.id, | ||
| ) | ||
| .filter(ConversationGlobalShare.shared_by == user_id) | ||
| .filter(CognitionConversation.project_id == project_id) | ||
| .all() | ||
| ) | ||
| conversation_global_shares_dict = [] | ||
| for share_obj, header in conversation_global_shares: | ||
| share_dict = sql_alchemy_to_dict(share_obj) | ||
| share_dict["conversation_header"] = header | ||
| conversation_global_shares_dict.append(share_dict) | ||
| return conversation_global_shares_dict | ||
This file contains hidden or 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,187 @@ | ||
| from operator import or_ | ||
| from typing import List, Optional | ||
| from ..business_objects import general | ||
| from ..session import session | ||
| from ..models import ConversationShare, CognitionConversation | ||
| from submodules.model.util import sql_alchemy_to_dict | ||
|
|
||
|
|
||
| def get(share_id: str, user_id: str) -> Optional[ConversationShare]: | ||
| return ( | ||
| session.query(ConversationShare) | ||
| .filter(ConversationShare.id == share_id) | ||
| .filter( | ||
| or_( | ||
| ConversationShare.shared_by == user_id, | ||
| ConversationShare.shared_with == user_id, | ||
| ) | ||
| ) | ||
| .first() | ||
| ) | ||
|
|
||
|
|
||
| def get_all_by_conversation(conversation_id: str) -> List[ConversationShare]: | ||
| return ( | ||
| session.query(ConversationShare) | ||
| .filter(ConversationShare.conversation_id == conversation_id) | ||
| .all() | ||
| ) | ||
|
|
||
|
|
||
| def update_by_conversation( | ||
| conversation_id: str, | ||
| user_id: str, | ||
| shared_with: List[str], | ||
| can_copy: Optional[bool] = None, | ||
| with_commit: bool = True, | ||
| ) -> List[ConversationShare]: | ||
| existing_shares = ( | ||
| session.query(ConversationShare) | ||
| .filter(ConversationShare.conversation_id == conversation_id) | ||
| .filter(ConversationShare.shared_by == user_id) | ||
| .all() | ||
| ) | ||
|
|
||
| existing_shared_with = {share.shared_with: share for share in existing_shares} | ||
| shared_with_set = set(shared_with) | ||
|
|
||
| for share in existing_shares: | ||
| if share.shared_with not in shared_with_set: | ||
| session.delete(share) | ||
LennartSchmidtKern marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| for sharing_user_id in shared_with: | ||
| if sharing_user_id not in existing_shared_with: | ||
| share = ConversationShare( | ||
| conversation_id=conversation_id, | ||
| shared_with=sharing_user_id, | ||
| shared_by=user_id, | ||
| can_copy=can_copy if can_copy is not None else False, | ||
| ) | ||
| general.add(share, with_commit=False) | ||
| else: | ||
| if can_copy is not None: | ||
| existing_shared_with[sharing_user_id].can_copy = can_copy | ||
|
|
||
| general.flush_or_commit(with_commit) | ||
|
|
||
| updated_shares = ( | ||
| session.query(ConversationShare) | ||
| .filter(ConversationShare.conversation_id == conversation_id) | ||
| .filter(ConversationShare.shared_by == user_id) | ||
| .all() | ||
| ) | ||
| return updated_shares | ||
|
|
||
|
|
||
| def get_all_shared_by_or_for_user( | ||
| project_id: str, user_id: str, with_header: bool = True | ||
| ) -> List[ConversationShare]: | ||
| conversation_shares = ( | ||
| session.query(ConversationShare, CognitionConversation.header) | ||
| .join( | ||
| CognitionConversation, | ||
| ConversationShare.conversation_id == CognitionConversation.id, | ||
| ) | ||
| .filter(CognitionConversation.project_id == project_id) | ||
| .filter( | ||
| or_( | ||
| ConversationShare.shared_by == user_id, | ||
| ConversationShare.shared_with == user_id, | ||
| ) | ||
| ) | ||
| .all() | ||
| ) | ||
| conversation_shares_dict = [] | ||
| for share_obj, header in conversation_shares: | ||
| share_dict = sql_alchemy_to_dict(share_obj) | ||
| share_dict["conversation_header"] = header | ||
| conversation_shares_dict.append(share_dict) | ||
|
|
||
| return conversation_shares_dict | ||
|
|
||
|
|
||
| def get_all_shared_by_user(user_id: str) -> List[ConversationShare]: | ||
| return ( | ||
| session.query(ConversationShare) | ||
| .filter(ConversationShare.shared_by == user_id) | ||
| .all() | ||
| ) | ||
|
|
||
|
|
||
| def create( | ||
| conversation_id: str, | ||
| shared_with: str, | ||
| shared_by: str, | ||
| can_copy: bool = False, | ||
| with_commit: bool = True, | ||
| ) -> ConversationShare: | ||
| share = ConversationShare( | ||
| conversation_id=conversation_id, | ||
| shared_with=shared_with, | ||
| shared_by=shared_by, | ||
| can_copy=can_copy, | ||
| ) | ||
| general.add(share, with_commit) | ||
| return share | ||
|
|
||
|
|
||
| def create_many( | ||
| conversation_id: str, | ||
| shared_with_user_ids: List[str], | ||
| shared_by: str, | ||
| can_copy: bool = False, | ||
| with_commit: bool = True, | ||
| ) -> List[ConversationShare]: | ||
|
|
||
| shares = [] | ||
|
|
||
| for user_id in shared_with_user_ids: | ||
| share = ConversationShare( | ||
| conversation_id=conversation_id, | ||
| shared_with=user_id, | ||
| shared_by=shared_by, | ||
| can_copy=can_copy, | ||
| ) | ||
| general.add(share, with_commit=False) | ||
| shares.append(share) | ||
|
|
||
LennartSchmidtKern marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| general.flush_or_commit(with_commit) | ||
| return shares | ||
|
|
||
|
|
||
| def update( | ||
| share_id: str, | ||
| user_id: str, | ||
| can_copy: Optional[bool] = None, | ||
| with_commit: bool = True, | ||
| ) -> Optional[ConversationShare]: | ||
| share_entity = get(share_id) | ||
| if share_entity is None: | ||
| return None | ||
|
|
||
| if str(share_entity.shared_by) != user_id: | ||
| raise ValueError("You are not allowed to update this sharing context.") | ||
|
|
||
| if can_copy is not None: | ||
| share_entity.can_copy = can_copy | ||
|
|
||
| general.flush_or_commit(with_commit) | ||
| return share_entity | ||
|
|
||
|
|
||
| def delete_shared_with( | ||
| conversation_share_id: str, user_id: str, with_commit: bool = True | ||
| ) -> None: | ||
| session.query(ConversationShare).filter( | ||
| ConversationShare.id == conversation_share_id | ||
| ).filter(ConversationShare.shared_with == user_id).delete() | ||
| general.flush_or_commit(with_commit) | ||
|
|
||
|
|
||
| def delete_shared_by_by_conversation_id( | ||
| conversation_id: str, user_id: str, with_commit: bool = True | ||
| ) -> None: | ||
| session.query(ConversationShare).filter( | ||
| ConversationShare.conversation_id == conversation_id | ||
| ).filter(ConversationShare.shared_by == user_id).delete() | ||
| general.flush_or_commit(with_commit) | ||
This file contains hidden or 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 hidden or 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 hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.