Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add viewer privilage #274

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions index.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# encode.py
import datetime
import jwt # import jwt library
SECRET_KEY = "test123"
# json data to encode
json_data = {
"roles": ["moderator:firstboard","viewer:hboard"]
}
encode_data = jwt.encode(payload=json_data, \
key=SECRET_KEY, algorithm="HS256")
print(encode_data)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# encode.py
import datetime
import jwt # import jwt library
SECRET_KEY = "test123"
# json data to encode
json_data = {
"roles": ["moderator:firstboard","viewer:hboard"]
}
encode_data = jwt.encode(payload=json_data, \
key=SECRET_KEY, algorithm="HS256")
print(encode_data)

We probably don't want to create a python script here

102 changes: 57 additions & 45 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"jsonwebtoken": "^8.5.1",
"polyfill-library": "^3.107.1",
"serve-static": "^1.14.1",
"socket.io": "^4",
"socket.io": "^4.6.1",
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This does not seem to be linked to the current PR. You can open a distinct pr to update dependencies

"statsd-client": "^0.4.7"
},
"scripts": {
Expand Down
14 changes: 13 additions & 1 deletion server/templating.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,26 @@ class Template {
}
}


const jwtBoardnameAuth = require("./jwtBoardnameAuth"); // have to delete
class BoardTemplate extends Template {
parameters(parsedUrl, request, isModerator) {
const params = super.parameters(parsedUrl, request, isModerator);
const parts = parsedUrl.pathname.split("boards/", 2);
console.log(parts[1]);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
console.log(parts[1]);

const boardUriComponent = parts[1];
params["boardUriComponent"] = boardUriComponent;
params["board"] = decodeURIComponent(boardUriComponent);
params["hideMenu"] = parsedUrl.query.hideMenu == "true" || false;
const query = parsedUrl.query;
const token = query.token;
const boardName = parts[1];
const userRole = jwtBoardnameAuth.roleInBoard(token, boardName);
if (userRole === "viewer") {
params["hideMenu"] = true;
} else {
params["hideMenu"] = false;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
params["hideMenu"] = false;
params["hideMenu"] = false;

you don't want to override that. keep the value from the query

}
params["moderator"] = isModerator;
return params;
}
}
Expand Down