-
Notifications
You must be signed in to change notification settings - Fork 54
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
refactors answers codes to parse user data from jwt token. Moves pars… #274
Changes from all commits
ed8e993
fa27c2f
1073f3f
824a49c
5990672
6caa54f
3df3c6e
fb2fd28
38c4719
015c44f
41edf1a
07df3ae
5c502bb
6f977ff
882d962
69208c0
983db74
5260a08
9dc6a36
77584bd
79dac25
995229a
f99f1c0
83de058
6e8a18c
2a4f0c7
2ea48e4
ce64670
ee30405
1788b7e
406a87b
ebac419
78cdba4
d15d535
f4c5164
167a2aa
4c9ebc0
20a299b
969a676
0ad249b
38af035
1aacbcb
cf5bdf1
248d88a
5196eca
686b844
be3ab4c
d454a61
301b236
95b0907
3873924
e048a0b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# Contributor Covenant Code of Conduct | ||
|
||
## Our Pledge | ||
|
||
In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation. | ||
|
||
## Our Standards | ||
|
||
Examples of behavior that contributes to creating a positive environment include: | ||
|
||
* Using welcoming and inclusive language | ||
* Being respectful of differing viewpoints and experiences | ||
* Gracefully accepting constructive criticism | ||
* Focusing on what is best for the community | ||
* Showing empathy towards other community members | ||
|
||
Examples of unacceptable behavior by participants include: | ||
|
||
* The use of sexualized language or imagery and unwelcome sexual attention or advances | ||
* Trolling, insulting/derogatory comments, and personal or political attacks | ||
* Public or private harassment | ||
* Publishing others' private information, such as a physical or electronic address, without explicit permission | ||
* Other conduct which could reasonably be considered inappropriate in a professional setting | ||
|
||
## Our Responsibilities | ||
|
||
Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior. | ||
|
||
Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful. | ||
|
||
## Scope | ||
|
||
This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers. | ||
|
||
## Enforcement | ||
|
||
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team on [Slack](https://join.slack.com/t/hackingcovid19/shared_invite/zt-cs0oy49c-bwn5uoilSme1iqFDDK7~zg "Hacking Covid19"). The project team will review and investigate all complaints, and will respond in a way that it deems appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately. | ||
Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership. | ||
|
||
## Attribution | ||
|
||
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [http://contributor-covenant.org/version/1/4][version] | ||
|
||
[homepage]: http://contributor-covenant.org | ||
[version]: http://contributor-covenant.org/version/1/4/ |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
const jose = require('jose'); | ||
|
||
export const parseToken = (jwtToken) => { | ||
const item = jose.JWT.decode(jwtToken); | ||
const user = new User(); | ||
user.profilestatus = "level 0"; | ||
user.fullname = item.given_name + " " + item.family_name; | ||
user.b2cid = item.sub; | ||
user.lastsignintime = item.auth_time; | ||
user.email = item.emails[0]; | ||
return user; | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,10 @@ const getUrls = require('get-urls'); | |
|
||
const QuestionDao = require('../models/questionDao') | ||
|
||
|
||
import { parseToken } from './common'; | ||
import { answerContainerId } from '../config'; | ||
|
||
/** | ||
* @swagger | ||
* definitions: | ||
|
@@ -314,6 +318,12 @@ class PostList { | |
let sources = []; | ||
let youtubeLinks = []; | ||
let answer = req.body; | ||
let userData = parseToken(answer.jwt); | ||
|
||
const userDetails = { | ||
id: userData.id, | ||
name: userData.anonymous ? userData.fullname : null | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. shouldn't name be null when There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hi @aviskarkc10 If anonymous, we should call it "Anonymous". I am going to merge this code from Alex to test and test. Thanks Jay There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This will be reversed. I will make this change. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes this should be reversed. Sorry! |
||
} | ||
|
||
const urls = getUrls(answer.text); | ||
|
||
|
@@ -332,22 +342,19 @@ class PostList { | |
|
||
return { | ||
...answer, | ||
userDetails, | ||
country: userData.country, | ||
sources, | ||
youtubeLinks | ||
}; | ||
} | ||
|
||
async addAnswer (req, res) { | ||
const answer = this.parseAnswer(req) | ||
var firstAnsweredBy = {}, lastAnsweredBy = {}; | ||
firstAnsweredBy.name = "Nth Opinion" | ||
firstAnsweredBy.loginId = "e060f24a-bd81-4d65-877f-857f31f2cf31" | ||
lastAnsweredBy.name = "Nth Opinion" | ||
lastAnsweredBy.loginId = "e060f24a-bd81-4d65-877f-857f31f2cf31" | ||
answer["firstAnsweredBy"] = firstAnsweredBy; | ||
answer["lastAnsweredBy"] = lastAnsweredBy; | ||
var date = new Date(); | ||
var timestamp = Math.floor(date.getTime()/1000.0); | ||
answer["firstAnsweredBy"] = answer.userDetails; | ||
answer["lastAnsweredBy"] = answer.userDetails; | ||
let date = new Date(); | ||
let timestamp = Math.floor(date.getTime()/1000.0); | ||
answer.firstAnsweredOn = timestamp; | ||
answer.lastAnsweredOn = timestamp; | ||
await this.questionDao.addAnswer(answer) | ||
|
@@ -356,20 +363,12 @@ class PostList { | |
|
||
async editAnswer (req, res) { | ||
const answer = this.parseAnswer(req) | ||
if (answer.lastAnsweredBy === undefined) | ||
{ | ||
var lastAnsweredBy = {}; | ||
lastAnsweredBy.name = "Nth Opinion" | ||
lastAnsweredBy.loginId = "e060f24a-bd81-4d65-877f-857f31f2cf31" | ||
answer["lastAnsweredBy"] = lastAnsweredBy; | ||
} | ||
else | ||
if (answer.lastAnsweredBy === undefined || answer.lastAnsweredBy != answer.userDetails.name) | ||
{ | ||
answer.lastAnsweredBy.name = "Nth Opinion" | ||
answer.lastAnsweredBy.loginId = "e060f24a-bd81-4d65-877f-857f31f2cf31" | ||
answer.lastAnsweredBy = answer.userDetails; | ||
} | ||
var date = new Date(); | ||
var timestamp = Math.floor(date.getTime()/1000.0); | ||
let date = new Date(); | ||
let timestamp = Math.floor(date.getTime()/1000.0); | ||
answer.lastAnsweredOn = timestamp; | ||
await this.questionDao.editAnswer(answer) | ||
res.send('ok') | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
better to use
camelCase
variable naming. Will make our code consistentThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @aviskarkc10 The class variables for the class user is matched with how the fields in the NoSQL container. CosmosDB is case sensitive. In C# we can map the class variable to database field , not sure how it is in node.js, so kept exactly the same. That is my code. We can discuss more in slack. Thanks