|
@ -13,6 +13,9 @@ from pyramid.httpexceptions import ( |
|
|
HTTPForbidden, |
|
|
HTTPForbidden, |
|
|
HTTPUnauthorized, |
|
|
HTTPUnauthorized, |
|
|
HTTPUnprocessableEntity, |
|
|
HTTPUnprocessableEntity, |
|
|
|
|
|
HTTPNotFound, |
|
|
|
|
|
HTTPFound, |
|
|
|
|
|
HTTPBadRequest |
|
|
) |
|
|
) |
|
|
from pyramid.request import Request |
|
|
from pyramid.request import Request |
|
|
from pyramid.response import Response |
|
|
from pyramid.response import Response |
|
@ -28,6 +31,13 @@ from tildes.schemas.topic import TopicSchema |
|
|
from tildes.schemas.user import UserSchema |
|
|
from tildes.schemas.user import UserSchema |
|
|
from tildes.views import IC_NOOP |
|
|
from tildes.views import IC_NOOP |
|
|
from tildes.views.decorators import ic_view_config, use_kwargs |
|
|
from tildes.views.decorators import ic_view_config, use_kwargs |
|
|
|
|
|
from tildes.models.message import MessageConversation, MessageReply |
|
|
|
|
|
from tildes.schemas.message import NewMessageConversationSchema |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
from pyramid.view import view_config |
|
|
|
|
|
#from pyramid.security import authenticated_userid |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
PASSWORD_FIELD = UserSchema(only=("password",)).fields["password"] |
|
|
PASSWORD_FIELD = UserSchema(only=("password",)).fields["password"] |
|
@ -423,3 +433,47 @@ def delete_user_ban(request: Request) -> Response: |
|
|
request.context.is_banned = False |
|
|
request.context.is_banned = False |
|
|
|
|
|
|
|
|
return Response("Unbanned") |
|
|
return Response("Unbanned") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@view_config( |
|
|
|
|
|
route_name="new_message_from_inbox", |
|
|
|
|
|
renderer="new_message_from_inbox.jinja2", |
|
|
|
|
|
request_method="GET", |
|
|
|
|
|
permission="view", |
|
|
|
|
|
) |
|
|
|
|
|
def get_new_message_form(request: Request) -> dict: |
|
|
|
|
|
"""Render form for entering a new private message to send.""" |
|
|
|
|
|
return {} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# This is the view function for handling the form submission |
|
|
|
|
|
@view_config( |
|
|
|
|
|
route_name="new_message_from_inbox", request_method="POST", permission="message" |
|
|
|
|
|
) |
|
|
|
|
|
@use_kwargs( |
|
|
|
|
|
NewMessageConversationSchema(only=("subject", "markdown", "recipient")), |
|
|
|
|
|
location="form", |
|
|
|
|
|
) |
|
|
|
|
|
def post_new_message( |
|
|
|
|
|
request: Request, subject: str, markdown: str, recipient: str |
|
|
|
|
|
) -> HTTPFound: |
|
|
|
|
|
"""Start a new message conversation with a user.""" |
|
|
|
|
|
recipient_user = ( |
|
|
|
|
|
request.db_session.query(User).filter_by(username=recipient).one_or_none() |
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
if recipient_user is None: |
|
|
|
|
|
raise HTTPBadRequest("Recipient user not found") |
|
|
|
|
|
|
|
|
|
|
|
new_conversation = MessageConversation( |
|
|
|
|
|
sender=request.user, |
|
|
|
|
|
recipient=recipient_user, |
|
|
|
|
|
subject=subject, |
|
|
|
|
|
markdown=markdown, |
|
|
|
|
|
) |
|
|
|
|
|
request.db_session.add(new_conversation) |
|
|
|
|
|
|
|
|
|
|
|
raise HTTPFound(request.route_url("messages_sent")) |