add private boards

Toaster 3 months ago
parent e5f74e88d7
commit 9eaa68b57c

Binary file not shown.

@ -0,0 +1,11 @@
"owner": "your_username",
"permissions": {
"can_create_accounts": true,
"can_create_boards": true,
"can_reply": true,
"can_post": true,
"can_subscribe": true,
"can_follow": true

@ -13,7 +13,11 @@ def boards():
loggedin = tokenchk(uname, token)
if loggedin == True:
# get every board and a list of the user's subscribed boards
boards = json_read("boards.json")
boards_unclean = json_read("boards.json")
boards = {"boards":[]}
for board in boards_unclean["boards"]:
if (not "private" in board) or (uname in board["moderators"]):
subbed = getSubbedArray(uname, boards)
# render boards template
return render_template('boards.html', name=uname, boards=boards["boards"], subbed=subbed)
@ -42,6 +46,9 @@ def createboard():
mod = mod.strip()
if mod.lower() != uname.lower():
bknight(bname, mod)
if "private" in request.form:
if request.form["private"] == "on":
# redirect to new board
return redirect(f"/b/{bname}")
@ -87,6 +94,8 @@ def viewboard(board):
if boardget == False:
return render_template('noboard.html', name=uname, board=board)
if "private" in boardget and not (uname in boardget["moderators"]):
return render_template('err.html', err="This board is private. Only the moderators can read its contents.", refer="/b/")
args = request.args.to_dict()
if "subscribe" in args:
subscribe(uname, boardget["name"])
@ -124,6 +133,12 @@ def viewpost(board, post):
token = request.cookies.get('token')
loggedin = tokenchk(uname, token)
post_json = getPostById(board, post)
board_json = json_read("boards.json")
for board_json in board_json["boards"]:
if board_json["name"] == board:
if "private" in board_json and not (uname in board_json["mods"]):
return render_template('err.html', err="This board is private. Only the moderators can read its contents.", refer="/b/")
if "replies" in post_json:
return render_template('postdetails.html', post=post_json, id=post, board=board, loggedin=loggedin, name=uname, hasreplies=True, replies=post_json["replies"])

@ -137,6 +137,15 @@ def bsetdesc(board, description):
return True
return False
def bprivate(board):
if bexist(board):
boards = json_read("boards.json")
for i in boards["boards"]:
if i["name"] == board:
i["private"] = None
json_sync("boards.json", boards)
return True
return False
def bknight(board, user):
if bexist(board):
boards = json_read("boards.json")

@ -0,0 +1,7 @@
rm boards/*
touch boards/.dontdeleteme
rm *.json
echo '{"boards":[]}' > boards.json
echo '{"users":[]}' > users.json
echo '{}' > follows.json
cat config.json.ex > config.json

@ -34,6 +34,15 @@
<input type="text" name="bmods" value="{{name}}" />
<td width="25%">
Private Board
<p><small>Only you and the moderators specified above will be able to see or use this board.</small></p>
<input type="checkbox" name="private" />

@ -1,3 +1 @@
"users": []