Skip to content

[PROD] fix: use u-bahn token for all u-bahn calls #107

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

Merged
merged 1 commit into from
Jan 12, 2021
Merged
Changes from all commits
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
33 changes: 5 additions & 28 deletions src/common/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ function encodeQueryString (queryObj, nesting = '') {
* @returns {String} user id.
*/
async function getUserIds (userId) {
const token = await getM2MToken()
const token = await getM2MUbahnToken()
const q = {
enrich: true,
externalProfile: {
Expand Down Expand Up @@ -369,7 +369,7 @@ async function getTopcoderUserById (userId) {
* @returns the request result
*/
async function getUserById (userId, enrich) {
const token = await getM2MToken()
const token = await getM2MUbahnToken()
const res = await request
.get(`${config.TC_API}/users/${userId}` + (enrich ? '?enrich=true' : ''))
.set('Authorization', `Bearer ${token}`)
Expand Down Expand Up @@ -482,7 +482,7 @@ async function getProjectById (currentUser, id) {
* @returns the request result
*/
async function getTopcoderSkills (criteria) {
const token = await getM2MToken()
const token = await getM2MUbahnToken()
try {
const res = await request
.get(`${config.TC_API}/skills`)
Expand Down Expand Up @@ -514,7 +514,7 @@ async function getTopcoderSkills (criteria) {
* @returns the request result
*/
async function getSkillById (skillId) {
const token = await getM2MToken()
const token = await getM2MUbahnToken()
const res = await request
.get(`${config.TC_API}/skills/${skillId}`)
.set('Authorization', `Bearer ${token}`)
Expand All @@ -524,28 +524,6 @@ async function getSkillById (skillId) {
return _.pick(res.body, ['id', 'name'])
}

/**
* Function to get user skills
* @param {String} token the user request token
* @param {String} userId user id
* @returns the request result
*/
async function getUserSkill (token, userId) {
const url = `${config.TC_API}/users/${userId}/skills`
const res = await request
.get(url)
.set('Authorization', token)
.set('Content-Type', 'application/json')
.set('Accept', 'application/json')
localLogger.debug({ context: 'getUserSkill', message: `response body: ${JSON.stringify(res.body)}` })
return _.map(res.body, item => {
return {
id: item.id,
name: item.skill.name
}
})
}

/**
* Encapsulate the getUserId function.
* Make sure a user exists in ubahn(/v5/users) and return the id of the user.
Expand Down Expand Up @@ -587,7 +565,7 @@ async function ensureJobById (jobId) {
* @returns {Object} the user data
*/
async function ensureUserById (userId) {
const token = await getM2MToken()
const token = await getM2MUbahnToken()
try {
const res = await request
.get(`${config.TC_API}/users/${userId}`)
Expand Down Expand Up @@ -660,7 +638,6 @@ module.exports = {
getProjectById,
getTopcoderSkills,
getSkillById,
getUserSkill,
ensureJobById,
ensureUserById,
getAuditM2Muser,
Expand Down