|
2 | 2 | from flask_restx import Api, Resource, reqparse |
3 | 3 | import datetime |
4 | 4 | import hashlib |
| 5 | +import os |
5 | 6 | import random |
6 | 7 | import json |
7 | 8 | import time |
@@ -71,6 +72,7 @@ def db_conn(): |
71 | 72 | db = db_engine.db_engine(db_url) |
72 | 73 | return (db, users_table, permalinks_table, user_permalink_table, user_bookmark_table) |
73 | 74 |
|
| 75 | +ALLOW_PUBLIC_BOOKMARKS = os.environ.get("ALLOW_PUBLIC_BOOKMARKS", "False").lower() == "true" |
74 | 76 |
|
75 | 77 | @api.route('/createpermalink') |
76 | 78 | class CreatePermalink(Resource): |
@@ -263,7 +265,10 @@ class UserBookmarksList(Resource): |
263 | 265 | def get(self): |
264 | 266 | username = get_username(get_identity()) |
265 | 267 | if not username: |
266 | | - return jsonify([]) |
| 268 | + if ALLOW_PUBLIC_BOOKMARKS: |
| 269 | + username = "public" |
| 270 | + else: |
| 271 | + return jsonify([]) |
267 | 272 |
|
268 | 273 | tenant = tenant_handler.tenant() |
269 | 274 | config = config_handler.tenant_config(tenant) |
@@ -310,7 +315,10 @@ def get(self): |
310 | 315 | def post(self): |
311 | 316 | username = get_username(get_identity()) |
312 | 317 | if not username: |
313 | | - return jsonify({"success": False}) |
| 318 | + if ALLOW_PUBLIC_BOOKMARKS: |
| 319 | + username = "public" |
| 320 | + else: |
| 321 | + return jsonify({"success": False}) |
314 | 322 |
|
315 | 323 | args = userbookmark_parser.parse_args() |
316 | 324 | state = request.json |
@@ -375,7 +383,10 @@ class UserBookmark(Resource): |
375 | 383 | def get(self, key): |
376 | 384 | username = get_username(get_identity()) |
377 | 385 | if not username: |
378 | | - return jsonify({"success": False}) |
| 386 | + if ALLOW_PUBLIC_BOOKMARKS: |
| 387 | + username = "public" |
| 388 | + else: |
| 389 | + return jsonify({"success": False}) |
379 | 390 |
|
380 | 391 | db_engine, users_table, permalinks_table, user_permalink_table, user_bookmark_table = db_conn() |
381 | 392 | if users_table: |
@@ -406,7 +417,10 @@ def get(self, key): |
406 | 417 | def delete(self, key): |
407 | 418 | username = get_username(get_identity()) |
408 | 419 | if not username: |
409 | | - return jsonify({"success": False}) |
| 420 | + if ALLOW_PUBLIC_BOOKMARKS: |
| 421 | + username = "public" |
| 422 | + else: |
| 423 | + return jsonify({"success": False}) |
410 | 424 |
|
411 | 425 | # Delete into databse |
412 | 426 | db_engine, users_table, permalinks_table, user_permalink_table, user_bookmark_table = db_conn() |
@@ -438,7 +452,10 @@ def delete(self, key): |
438 | 452 | def put(self, key): |
439 | 453 | username = get_username(get_identity()) |
440 | 454 | if not username: |
441 | | - return jsonify({"success": False}) |
| 455 | + if ALLOW_PUBLIC_BOOKMARKS: |
| 456 | + username = "public" |
| 457 | + else: |
| 458 | + return jsonify({"success": False}) |
442 | 459 |
|
443 | 460 | args = userbookmark_parser.parse_args() |
444 | 461 | state = request.json |
|
0 commit comments