mirror of
https://github.com/dartdavros/chatballs.git
synced 2026-10-05 09:14:58 +03:00
21 файл доехал до репозитория с `\r\r\n` внутри: строка кончается двумя возвратами каретки и переводом строки. Python такое читает, поэтому оно и дожило, но линуксовые инструменты спотыкаются — ruff принимает одиночный CR за перевод строки и пишет его в вывод, портя файл дальше. Содержимое не менялось: `git diff -w` по этим файлам пуст, различаются только переводы строк. Правило `*.py text eol=lf` в .gitattributes закрывает повтор — на Windows такие файлы теперь и выкладываются с LF. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
44 lines
1.4 KiB
Python
44 lines
1.4 KiB
Python
from rest_framework.request import Request
|
|
from rest_framework.views import APIView
|
|
|
|
from chatballs.api.permissions import HasCapability
|
|
from chatballs.conversations.models import Conversation
|
|
from chatballs.conversations.selectors import conversation_for_context
|
|
from chatballs.identity.audit import record_audit_event
|
|
from chatballs.identity.policy import require_capability
|
|
|
|
|
|
class ConversationViewBase(APIView):
|
|
permission_classes = [HasCapability]
|
|
required_capability = "conversations.view"
|
|
|
|
def _org(self, request: Request):
|
|
return request.tenant_context.organization
|
|
|
|
def _conversation(
|
|
self,
|
|
request: Request,
|
|
conversation_id: int,
|
|
capability: str = "conversations.view",
|
|
) -> Conversation:
|
|
conversation = conversation_for_context(
|
|
context=request.tenant_context, conversation_id=conversation_id
|
|
)
|
|
if not require_capability(
|
|
request.tenant_context.membership, capability, conversation
|
|
):
|
|
raise Conversation.DoesNotExist
|
|
return conversation
|
|
|
|
def _audit(
|
|
self, request: Request, action: str, conversation: Conversation
|
|
) -> None:
|
|
record_audit_event(
|
|
action=f"conversations.{action}",
|
|
actor=request.user,
|
|
organization=self._org(request),
|
|
object_type="Conversation",
|
|
object_id=str(conversation.id),
|
|
request=request,
|
|
)
|