ensure new users get a default collection on signup and any missing users get them too
This commit is contained in:
@@ -162,6 +162,13 @@ def clear_api_limits():
|
|||||||
for l in limits:
|
for l in limits:
|
||||||
l.delete()
|
l.delete()
|
||||||
|
|
||||||
|
def ensure_default_collection():
|
||||||
|
from .db import db
|
||||||
|
from .models import BookmarkCollections
|
||||||
|
with db.transaction():
|
||||||
|
for missing_user in BookmarkCollections.get_users_without_default():
|
||||||
|
BookmarkCollections.create_default(missing_user)
|
||||||
|
|
||||||
cache = Cache()
|
cache = Cache()
|
||||||
|
|
||||||
def create_app():
|
def create_app():
|
||||||
@@ -243,6 +250,8 @@ def create_app():
|
|||||||
|
|
||||||
reparse_babycode()
|
reparse_babycode()
|
||||||
|
|
||||||
|
ensure_default_collection()
|
||||||
|
|
||||||
bind_default_badges(app.config['BADGES_PATH'])
|
bind_default_badges(app.config['BADGES_PATH'])
|
||||||
|
|
||||||
app.config['SESSION_COOKIE_SECURE'] = True
|
app.config['SESSION_COOKIE_SECURE'] = True
|
||||||
|
|||||||
@@ -506,10 +506,24 @@ class BookmarkCollections(Model):
|
|||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def create_default(cls, user_id):
|
def create_default(cls, user_id):
|
||||||
q = """INSERT INTO bookmark_collections (user_id, name, is_default, sort_order)
|
return cls.create({
|
||||||
VALUES (?, "Bookmarks", 1, 0) RETURNING id
|
'user_id': user_id,
|
||||||
|
'name': 'Bookmarks',
|
||||||
|
'is_default': True,
|
||||||
|
'sort_order': 0,
|
||||||
|
})
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def get_users_without_default():
|
||||||
|
q = """
|
||||||
|
SELECT users.id FROM users
|
||||||
|
WHERE NOT EXISTS (
|
||||||
|
SELECT 1 FROM bookmark_collections bc
|
||||||
|
WHERE bc.user_id = users.id
|
||||||
|
AND bc.is_default = 1
|
||||||
|
)
|
||||||
"""
|
"""
|
||||||
res = db.fetch_one(q, user_id)
|
return [row['id'] for row in db.query(q)]
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_for_user(cls, user_id):
|
def get_for_user(cls, user_id):
|
||||||
|
|||||||
Reference in New Issue
Block a user