Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions chafan_core/app/api/api_v1/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from chafan_core.app.api.api_v1.endpoints import (
activities,
admin_tools,
answer_suggest_edits,
answers,
applications,
Expand All @@ -28,6 +29,7 @@
questions,
reports,
rewards,
rss,
search,
sitemaps,
sites,
Expand All @@ -38,8 +40,6 @@
users,
webhooks,
ws,
rss,
admin_tools,
)

api_router = APIRouter()
Expand Down Expand Up @@ -99,7 +99,9 @@
coin_payments.router, prefix="/coin-payments", tags=["coin_payments"]
)
api_router.include_router(audit_logs.router, prefix="/audit-logs", tags=["audit_logs"])
api_router.include_router(admin_tools.router, prefix="/admin_tools", tags=["admin_tools"])
api_router.include_router(
admin_tools.router, prefix="/admin_tools", tags=["admin_tools"]
)
api_router.include_router(webhooks.router, prefix="/webhooks", tags=["webhooks"])
api_router.include_router(feedbacks.router, prefix="/feedbacks", tags=["feedbacks"])
api_router.include_router(reports.router, prefix="/reports", tags=["reports"])
Expand Down
10 changes: 6 additions & 4 deletions chafan_core/app/api/api_v1/endpoints/activities.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import logging
from typing import Any, Optional, Union

from fastapi import APIRouter, Depends, Request
Expand All @@ -12,8 +13,6 @@
from chafan_core.app.schemas.answer import AnswerPreview, AnswerPreviewForVisitor
from chafan_core.utils.base import unwrap


import logging
logger = logging.getLogger(__name__)

router = APIRouter()
Expand Down Expand Up @@ -46,10 +45,13 @@ async def get_feed(
Get activity feed.
"""
current_user_id: int = unwrap(cached_layer.principal_id)
logger.info(f"User {current_user_id} GET activity skip={before_activity_id} limit={limit}, random={random}, full={full_answers}")
logger.info(
f"User {current_user_id} GET activity skip={before_activity_id} limit={limit}, random={random}, full={full_answers}"
)

activities = await cached_layer.get_user_activity(
current_user_id, before_activity_id, limit, random, subject_user_uuid)
current_user_id, before_activity_id, limit, random, subject_user_uuid
)

data = schemas.FeedSequence(activities=activities, random=random)
return _update_feed_seq(cached_layer, data, full_answers=full_answers)
Expand Down
19 changes: 10 additions & 9 deletions chafan_core/app/api/api_v1/endpoints/admin_tools.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import logging

from fastapi import APIRouter, Depends, Response

from chafan_core.app.config import settings
from chafan_core.app.api import deps
from chafan_core.app.cached_layer import CachedLayer
from chafan_core.app.config import settings
from chafan_core.app.feed import get_site_activities
from chafan_core.utils.base import HTTPException_
from chafan_core.app.responders.rss import build_rss
from chafan_core.utils.base import HTTPException_

import logging
logger = logging.getLogger(__name__)


Expand All @@ -17,9 +17,10 @@

@router.get("/full_site_activity/{passcode}/rss.xml")
async def get_site_activity(
*, response: Response,
cached_layer: CachedLayer = Depends(deps.get_cached_layer),
passcode: str
*,
response: Response,
cached_layer: CachedLayer = Depends(deps.get_cached_layer),
passcode: str
) -> str:
"""
Get full cha.fan activity.
Expand All @@ -28,8 +29,8 @@ async def get_site_activity(
code = settings.DEBUG_ADMIN_TOOL_FULL_SITE_PASSCODE
if code is None or code == "" or code != passcode:
raise HTTPException_(status_code=405, detail="Not allowed ")
activities = await get_site_activities(cached_layer, None, settings.LIMIT_RSS_ADMIN_TOOL_FULL_SITE_ITEMS, True)
activities = await get_site_activities(
cached_layer, None, settings.LIMIT_RSS_ADMIN_TOOL_FULL_SITE_ITEMS, True
)
rss_str = build_rss(activities, site=None)
return Response(content=rss_str, media_type="application/rss+xml")


10 changes: 5 additions & 5 deletions chafan_core/app/api/api_v1/endpoints/answers.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import logging
from typing import Any, List, Union

from fastapi import APIRouter, Depends, Query, Request, Response
Expand All @@ -17,11 +18,10 @@
from chafan_core.app.schemas.answer import AnswerModUpdate
from chafan_core.app.schemas.event import EventInternal, UpvoteAnswerInternal
from chafan_core.app.schemas.richtext import RichText
from chafan_core.app.task import postprocess_new_answer
from chafan_core.utils.base import HTTPException_, filter_not_none, get_utc_now, unwrap
from chafan_core.utils.constants import MAX_ARCHIVE_PAGINATION_LIMIT
from chafan_core.app.task import postprocess_new_answer

import logging
logger = logging.getLogger(__name__)

router = APIRouter()
Expand Down Expand Up @@ -257,9 +257,9 @@ def _update_answer(
if answer_in.updated_content:
del answer_in_dict["updated_content"]
answer_in_dict["body"] = answer_in.updated_content.source
answer_in_dict[
"body_prerendered_text"
] = answer_in.updated_content.rendered_text
answer_in_dict["body_prerendered_text"] = (
answer_in.updated_content.rendered_text
)
answer_in_dict["editor"] = answer_in.updated_content.editor

answer_in_dict["body_draft"] = None
Expand Down
4 changes: 2 additions & 2 deletions chafan_core/app/api/api_v1/endpoints/article_columns.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
from typing import Any, List, Optional

from fastapi import APIRouter, Depends
from chafan_core.app.config import settings

from chafan_core.app import crud, schemas
from chafan_core.app.api import deps
from chafan_core.app.cached_layer import CachedLayer
from chafan_core.app.config import settings
from chafan_core.utils.base import HTTPException_, filter_not_none

router = APIRouter()
Expand Down Expand Up @@ -42,7 +42,7 @@ async def get_article_column_articles(
)
articles = article_column.articles
if not current_user_id:
articles = articles[:settings.VISITORS_READ_ARTICLE_LIMIT]
articles = articles[: settings.VISITORS_READ_ARTICLE_LIMIT]
return filter_not_none(
[cached_layer.materializer.preview_of_article(a) for a in articles]
)
Expand Down
7 changes: 5 additions & 2 deletions chafan_core/app/api/api_v1/endpoints/articles.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import datetime
import logging
from typing import Any, List, Optional, Union

from fastapi import APIRouter, Depends, Request
Expand All @@ -19,7 +20,6 @@
from chafan_core.utils.base import ContentVisibility, HTTPException_
from chafan_core.utils.constants import MAX_ARCHIVE_PAGINATION_LIMIT

import logging
logger = logging.getLogger(__name__)


Expand All @@ -37,7 +37,10 @@ async def get_article(
article = cached_layer.get_article_by_uuid(uuid, current_user_id)
if article is None:
cached_layer.create_audit(
api=f"get_article {uuid} retrieved None", request=request, user_id=current_user_id)
api=f"get_article {uuid} retrieved None",
request=request,
user_id=current_user_id,
)
raise HTTPException_(
status_code=400,
detail="The article doesn't exists in the system.",
Expand Down
2 changes: 1 addition & 1 deletion chafan_core/app/api/api_v1/endpoints/channels.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import logging
from typing import Any, List

from fastapi import APIRouter, Depends
Expand All @@ -8,7 +9,6 @@
from chafan_core.app.materialize import check_user_in_channel
from chafan_core.utils.base import HTTPException_

import logging
logger = logging.getLogger(__name__)


Expand Down
2 changes: 1 addition & 1 deletion chafan_core/app/api/api_v1/endpoints/comments.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import datetime
import logging
from typing import Any, Optional

from fastapi import APIRouter, Depends
Expand All @@ -12,7 +13,6 @@
from chafan_core.app.task import postprocess_comment_update, postprocess_new_comment
from chafan_core.utils.base import HTTPException_

import logging
logger = logging.getLogger(__name__)

router = APIRouter()
Expand Down
15 changes: 8 additions & 7 deletions chafan_core/app/api/api_v1/endpoints/invitation_links.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from fastapi import APIRouter, Depends

from chafan_core.app import crud, schemas, models
from chafan_core.app import crud, models, schemas
from chafan_core.app.api import deps
from chafan_core.app.cached_layer import CachedLayer
from chafan_core.app.common import OperationType
Expand Down Expand Up @@ -35,14 +35,15 @@ async def create_invitation_link(
)
invited_to_site_id = invited_to_site.id
invitation_link = await crud.invitation_link.create_invitation(
db, invited_to_site_id=invited_to_site_id, inviter=current_user
)
crud.audit_log.create_with_user(
db, ipaddr="0.0.0.0", user_id=current_user.id, api=f"Created invitation link {invitation_link.uuid}"
db, invited_to_site_id=invited_to_site_id, inviter=current_user
)
return cached_layer.materializer.invitation_link_schema_from_orm(
invitation_link
crud.audit_log.create_with_user(
db,
ipaddr="0.0.0.0",
user_id=current_user.id,
api=f"Created invitation link {invitation_link.uuid}",
)
return cached_layer.materializer.invitation_link_schema_from_orm(invitation_link)


@router.get("/daily", response_model=schemas.InvitationLink)
Expand Down
Loading
Loading