Пример #1
0
from flask import request
from glasskit.utils import resolve_id
from glasskit.api import json_response
from ask.controllers import AuthController
from ask.models import User

users_ctrl = AuthController("users", __name__, require_auth=False)

USER_FIELDS = (
    "_id",
    "first_name",
    "last_name",
    "username",
    "moderator",
    "ext_id",
)


@users_ctrl.route("/list/<ids>")
def list_users(ids):
    ids = ids.split(",")
    ids = [resolve_id(id_) for id_ in ids]
    items = User.find(
        {"$or": [
            {
                "_id": {
                    "$in": ids
                }
            },
            {
                "username": {
Пример #2
0
from bson import ObjectId
from typing import Union
from flask import request
from glasskit.api import json_response, paginated
from glasskit.errors import InputDataError

from ask.controllers import AuthController
from ask.search import search_posts
from ask.models import Answer, Question, User
from ask.unmark import unmark
from ask.utils import cut

search_ctrl = AuthController("search", __name__, require_auth=False)

SEARCH_FIELDS = (
    "_id",
    "body",
    "title",
    "type",
    "parent_id",
    "_score",
    "created_at",
    "tags",
    "question_title",
    "answers_count",
    "points",
    "author_id",
    "has_accepted_answer",
)

Пример #3
0
from pymongo import DESCENDING
from flask import request
from typing import Optional

from glasskit.api import (json_response, paginated, default_transform,
                          json_body_required, get_boolean_request_param)
from glasskit.utils import get_user_from_app_context, resolve_id, NilObjectId
from glasskit.errors import ApiError, NotFound, Forbidden

from ask.controllers import AuthController
from ask.models import Question, Answer, Comment, Vote, User
from ask.errors import NotAccepted
from ask.api import auth_required

questions_ctrl = AuthController("questions", __name__, require_auth=False)

QUESTION_LIST_FIELDS = (
    "_id",
    "title",
    "author_id",
    "points",
    "created_at",
    "edited_at",
    "views_count",
    "tags",
    "answers_count",
    "has_accepted_answer",
    "last_activity_at",
    "human_readable_id",
    "closed",
)
Пример #4
0
from flask import request
from glasskit.api import json_response, json_body_required
from glasskit.utils import get_user_from_app_context
from glasskit.errors import ApiError
from ask.controllers import AuthController
from ask.api import auth_required
from ask.models import Tag, User

tags_ctrl = AuthController("tags", __name__, require_auth=False)


@tags_ctrl.route("/<tagname>")
def show(tagname):
    tag = Tag.get(tagname, "tag not found")
    return json_response({"data": tag.to_dict()})


@tags_ctrl.route("/<tagname>/subscribe", methods=["POST"])
@auth_required
def subscribe(tagname):
    Tag.get(tagname, "tag not found")
    user: User = get_user_from_app_context()
    user.subscribe_to_tag(tagname)
    return json_response({"data": user.tag_subscription.to_dict()})


@tags_ctrl.route("/<tagname>/unsubscribe", methods=["POST"])
@auth_required
def unsubscribe(tagname):
    Tag.get(tagname, "tag not found")
    user: User = get_user_from_app_context()
Пример #5
0
from glasskit import ctx
from glasskit.api import json_response, paginated
from glasskit.utils import get_user_from_app_context
from glasskit.errors import NotFound
from ask.controllers import AuthController
from ask.models import User
from ask.models.event import Event

events_ctrl = AuthController("events", __name__, require_auth=True)


@events_ctrl.route("/")
def index():
    user: User = get_user_from_app_context()
    events = user.get_new_events().sort("created_at", -1)
    return json_response(
        paginated(events, limit=5, transform=lambda event: event.api_dict()))


@events_ctrl.route("/<event_id>/dismiss", methods=["POST"])
def dismiss(event_id):
    user: User = get_user_from_app_context()
    event = Event.get(event_id, "event not found")
    if event.user_id != user._id:
        raise NotFound("event not found")
    if not event.dismissed:
        event.dismiss()
    return json_response({"data": event.api_dict()})


@events_ctrl.route("/dismiss_all", methods=["POST"])
Пример #6
0
from flask import session, request, redirect
from glasskit import ctx
from glasskit.utils import get_user_from_app_context
from glasskit.api import json_response, json_body_required

from ask.api import auth_required
from ask.controllers import AuthController
from ask.idconnect.provider import BaseProvider
from ask.models import User
from ask.errors import AuthenticationError

account_ctrl = AuthController("account", __name__, require_auth=False)

ACCOUNT_FIELDS = (
    "_id",
    "username",
    "first_name",
    "last_name",
    "ext_id",
    "tag_subscription",
    "user_subscription",
    "avatar_url",
)

ACCOUNT_RESTRICTED_FIELDS = (
    "moderator",
    "email",
    "telegram_id",
    "icq_id",
)
Пример #7
0
from flask import request
from glasskit.api import json_response, json_body_required
from glasskit.errors import InputDataError
from glasskit.utils import get_user_from_app_context, resolve_id

from ask.controllers import AuthController
from ask.models import User
from .users import USER_FIELDS

subs_ctrl = AuthController("subscriptions", __name__, require_auth=True)

TAG_SUBSCRIPTION_FIELDS = (
    "_id",
    "tags",
    "user_id",
)


@subs_ctrl.route("/tags", methods=["GET"])
def tag_subscription():
    user: User = get_user_from_app_context()
    ts = user.tag_subscription
    return json_response({"data": ts.tags})


@subs_ctrl.route("/users", methods=["GET"])
def users_subscription():
    user: User = get_user_from_app_context()
    us = user.user_subscription
    users = []
    for user in us.subscribed_to: