bookmark collections
This commit is contained in:
@@ -2,7 +2,7 @@ from flask import Blueprint, request, url_for
|
||||
from ..lib.babycode import babycode_to_html
|
||||
from ..constants import REACTION_EMOJI
|
||||
from .users import is_logged_in, get_active_user
|
||||
from ..models import APIRateLimits, Threads, Reactions
|
||||
from ..models import APIRateLimits, Threads, Reactions, Users, BookmarkCollections
|
||||
from ..db import db
|
||||
|
||||
bp = Blueprint("api", __name__, url_prefix="/api/")
|
||||
@@ -96,3 +96,46 @@ def remove_reaction(post_id):
|
||||
reaction.delete()
|
||||
|
||||
return {'status': 'removed'}
|
||||
|
||||
@bp.post('/manage-bookmark-collections/<user_id>')
|
||||
def manage_bookmark_collections(user_id):
|
||||
if not is_logged_in():
|
||||
return {'error': 'not authorized', 'error_code': 401}, 401
|
||||
|
||||
target_user = Users.find({'id': user_id})
|
||||
if target_user.id != get_active_user().id:
|
||||
return {'error': 'forbidden', 'error_code': 403}, 403
|
||||
|
||||
if target_user.is_guest():
|
||||
return {'error': 'forbidden', 'error_code': 403}, 403
|
||||
|
||||
collections_data = request.json
|
||||
for idx, coll_data in enumerate(collections_data.get('collections')):
|
||||
if coll_data['is_new']:
|
||||
collection = BookmarkCollections.create({
|
||||
'name': coll_data['name'],
|
||||
'user_id': target_user.id,
|
||||
'sort_order': idx,
|
||||
})
|
||||
else:
|
||||
collection = BookmarkCollections.find({'id': coll_data['id']})
|
||||
if not collection:
|
||||
continue
|
||||
|
||||
update = {'name': coll_data['name']}
|
||||
if not collection.is_default:
|
||||
update['sort_order'] = idx
|
||||
collection.update(update)
|
||||
|
||||
for removed_id in collections_data.get('removed_collections'):
|
||||
collection = BookmarkCollections.find({'id': removed_id})
|
||||
if not collection:
|
||||
continue
|
||||
|
||||
if collection.is_default:
|
||||
continue
|
||||
|
||||
collection.delete()
|
||||
|
||||
|
||||
return {'status': 'ok'}, 200
|
||||
|
||||
@@ -4,7 +4,7 @@ from flask import (
|
||||
from functools import wraps
|
||||
from ..db import db
|
||||
from ..lib.babycode import babycode_to_html, BABYCODE_VERSION
|
||||
from ..models import Users, Sessions, Subscriptions, Avatars, PasswordResetLinks, InviteKeys, BookmarkCollections
|
||||
from ..models import Users, Sessions, Subscriptions, Avatars, PasswordResetLinks, InviteKeys, BookmarkCollections, BookmarkedThreads
|
||||
from ..constants import InfoboxKind, PermissionLevel
|
||||
from ..auth import digest, verify
|
||||
from wand.image import Image
|
||||
@@ -700,4 +700,16 @@ def bookmarks(username):
|
||||
return redirect(url_for('.bookmarks', username=get_active_user().username))
|
||||
|
||||
collections = target_user.get_bookmark_collections()
|
||||
|
||||
return render_template('users/bookmarks.html', collections=collections)
|
||||
|
||||
|
||||
@bp.get('/<username>/bookmarks/collections')
|
||||
@login_required
|
||||
def bookmark_collections(username):
|
||||
target_user = Users.find({'username': username})
|
||||
if not target_user or target_user.username != get_active_user().username:
|
||||
return redirect(url_for('.bookmark_collections', username=get_active_user().username))
|
||||
|
||||
collections = target_user.get_bookmark_collections()
|
||||
return render_template('users/bookmark_collections.html', collections=collections)
|
||||
|
||||
Reference in New Issue
Block a user