示例#1
0
 def delete(self, id):
     article = content_manager.get_article_by_id(id, g.user)
     if article:
         content_manager.unbookmark_article(article)
         content_manager.commit_changes()
         return responses.success({"article": article.to_json()})
     return responses.error("Article not found", 404)
示例#2
0
    def get(self):
        """
        Returns object like:
        {
            'user': User.to_json,
            'boxes': List[Box.to_json]
            'boxes_articles_count': Map[Box.id -> int]
        }
        """
        # Get currently logged in user
        user = g.user.to_json()
        # Get list of boxes for the user
        boxes = triage_manager.get_boxes_for_user(g.user)
        # Get count of articles per box
        boxes_count = {
            box.id: content_manager.get_num_articles_by_box_id(g.user, box.id)
            for box in boxes
        }

        user_config, new_config = user_manager.get_user_config(g.user)
        if new_config:
            user_manager.commit_changes()
        ## JSON
        ret = {
            "user": g.user.to_json(),
            "boxes": list(map(lambda box: box.to_json(), boxes)),
            "boxes_articles_count": boxes_count,
            "user_config": user_config.to_json(),
        }
        return responses.success(ret)
示例#3
0
 def get(self):
     """
     Get all boxes for the logged in user.
     """
     boxes = triage_manager.get_boxes_for_user(g.user)
     return responses.success(
         {"boxes": list(map(lambda box: box.to_json(), boxes))})
示例#4
0
 def put(self, put_args):
     """Update user config option for gmail_auto_archive"""
     do_auto_archive = put_args["auto_archive"]
     user_config = user_manager.set_auto_archive_config(g.user, do_auto_archive)
     user_manager.commit_changes()
     if user_config:
         return responses.success(user_config.to_json())
     return responses.error("Something went wrong")
示例#5
0
 def get(self):
     email = user_manager.get_google_account_email(g.user)
     if email:
         ret = {"email": email}
         return responses.success(ret)
     else:
         return responses.error(
             "Google account credentials do not exist or have expired."
         )
示例#6
0
 def post(self, args):
     """
     Move an article into a new box, return the list of article ids for the target box.
     """
     new_triage = triage_manager.triage_article(g.user,
                                                args.get("article_id"),
                                                args.get("box_id"))
     article_ids = content_manager.get_articles_by_box_id(
         g.user, args["box_id"])
     ret = {"article_ids": article_ids}
     triage_manager.commit_changes()
     return responses.success(ret)
示例#7
0
 def post(self, args):
     login_user = user_manager.google_login_callback(args["callback_url"])
     if login_user:
         cookie_name = jwt.jwt_cookie_name
         jwt_token = jwt.encode_jwt(login_user.login_id)
         headers = {
             "Set-Cookie": f"{cookie_name}={jwt_token}; Path=/; HttpOnly"
         }
         ret = {"user": login_user.to_json()}
         return responses.success(ret, extra_headers=headers)
     else:
         return responses.error(
             "There was an error logging in with google account", 500)
示例#8
0
    def get(self, args: dict):
        """Gets article data for given ids

        Args:
            args ({'articleIds': List[int]}): [description]

        Returns:
            200, {'articles': [Article.to_json(), ...]}
        """
        articles = content_manager.get_articles_by_id(g.user, id, args["articleIds"])
        return responses.success(
            {"articles": [article.to_json() for article in articles]}
        )
示例#9
0
    def get(self, args: dict):
        """
        Gets article ids matching search query, sorted by box id of that article.
        """
        matches = {}
        user_boxes = triage_manager.get_boxes_for_user(g.user)
        for box in user_boxes:
            article_ids = content_manager.get_articles_by_search_query(
                g.user, box.id, args["query"].lower()
            )
            matches.update({box.id: article_ids})

        ret = {"query": args["query"], "matches": matches}
        return responses.success(ret)
示例#10
0
 def post(self, args: dict):
     from_address = args["from_address"]
     existing_subscription = content_manager.get_subscription_by_from_address(
         from_address
     )
     if existing_subscription:
         subscription = existing_subscription
     else:
         subscription = content_manager.create_subscription(from_address)
     if not subscription:
         return responses.error("Something went wrong", 500)
     new_user_subscription = user_manager.add_user_subscription(g.user, subscription)
     user_manager.commit_changes()
     return responses.success("Success")
示例#11
0
 def post(self, args):
     (new_user, signup_outcome) = user_manager.google_signup_callback(
         args["callback_url"])
     if new_user:
         user_manager.commit_changes()
         cookie_name = jwt.jwt_cookie_name
         jwt_token = jwt.encode_jwt(new_user.login_id)
         headers = {
             "Set-Cookie": f"{cookie_name}={jwt_token}; Path=/; HttpOnly"
         }
         ret = {"user": new_user.to_json()}
         if signup_outcome.is_error():
             ret.update(signup_outcome.error_json)
         return responses.success(ret, extra_headers=headers)
     else:
         return responses.error(signup_outcome.error_json, 500)
示例#12
0
 def get(self, id: int):
     """
     Get articles ids for box with id.
     """
     article_ids = content_manager.get_articles_by_box_id(g.user, id)
     return responses.success({"article_ids": article_ids})
示例#13
0
 def get(self, id):
     article = content_manager.get_article_by_id(id, g.user)
     if article is None:
         logger.info(f"Trying to get article with id={id} but it doesn't exists")
         return responses.error("Article not found.", 404)
     return responses.success(article.to_json())
示例#14
0
 def get(self):
     google_auth_url = user_manager.gmail_permissions_step1(g.user)
     user_manager.commit_changes()
     ret = {"redirect_url": google_auth_url}
     return responses.success(ret)
示例#15
0
 def get(self):
     google_auth_url = user_manager.google_login_step1()
     ret = {"redirect_url": google_auth_url}
     return responses.success(ret)
示例#16
0
 def delete(self):
     """Sets empty cookie (to simulate logging out)"""
     cookie_name = jwt.jwt_cookie_name
     headers = {"Set-Cookie": f"{cookie_name}=" "; Path=/; HttpOnly"}
     return responses.success("Successfully logged out.", 200, headers)
示例#17
0
 def get(self):
     """Get's user model for currently logged in user."""
     return responses.success({"user": g.user.to_json()})