Skip to content

Commit 15f3e83

Browse files
committed
Add ALLOW_PUBLIC_BOOKMARKS env for development/testing
1 parent 4ca131d commit 15f3e83

File tree

1 file changed

+22
-5
lines changed

1 file changed

+22
-5
lines changed

src/server.py

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from flask_restx import Api, Resource, reqparse
33
import datetime
44
import hashlib
5+
import os
56
import random
67
import json
78
import time
@@ -71,6 +72,7 @@ def db_conn():
7172
db = db_engine.db_engine(db_url)
7273
return (db, users_table, permalinks_table, user_permalink_table, user_bookmark_table)
7374

75+
ALLOW_PUBLIC_BOOKMARKS = os.environ.get("ALLOW_PUBLIC_BOOKMARKS", "False").lower() == "true"
7476

7577
@api.route('/createpermalink')
7678
class CreatePermalink(Resource):
@@ -263,7 +265,10 @@ class UserBookmarksList(Resource):
263265
def get(self):
264266
username = get_username(get_identity())
265267
if not username:
266-
return jsonify([])
268+
if ALLOW_PUBLIC_BOOKMARKS:
269+
username = "public"
270+
else:
271+
return jsonify([])
267272

268273
tenant = tenant_handler.tenant()
269274
config = config_handler.tenant_config(tenant)
@@ -310,7 +315,10 @@ def get(self):
310315
def post(self):
311316
username = get_username(get_identity())
312317
if not username:
313-
return jsonify({"success": False})
318+
if ALLOW_PUBLIC_BOOKMARKS:
319+
username = "public"
320+
else:
321+
return jsonify({"success": False})
314322

315323
args = userbookmark_parser.parse_args()
316324
state = request.json
@@ -375,7 +383,10 @@ class UserBookmark(Resource):
375383
def get(self, key):
376384
username = get_username(get_identity())
377385
if not username:
378-
return jsonify({"success": False})
386+
if ALLOW_PUBLIC_BOOKMARKS:
387+
username = "public"
388+
else:
389+
return jsonify({"success": False})
379390

380391
db_engine, users_table, permalinks_table, user_permalink_table, user_bookmark_table = db_conn()
381392
if users_table:
@@ -406,7 +417,10 @@ def get(self, key):
406417
def delete(self, key):
407418
username = get_username(get_identity())
408419
if not username:
409-
return jsonify({"success": False})
420+
if ALLOW_PUBLIC_BOOKMARKS:
421+
username = "public"
422+
else:
423+
return jsonify({"success": False})
410424

411425
# Delete into databse
412426
db_engine, users_table, permalinks_table, user_permalink_table, user_bookmark_table = db_conn()
@@ -438,7 +452,10 @@ def delete(self, key):
438452
def put(self, key):
439453
username = get_username(get_identity())
440454
if not username:
441-
return jsonify({"success": False})
455+
if ALLOW_PUBLIC_BOOKMARKS:
456+
username = "public"
457+
else:
458+
return jsonify({"success": False})
442459

443460
args = userbookmark_parser.parse_args()
444461
state = request.json

0 commit comments

Comments
 (0)