Skip to content

Commit 42cd6bf

Browse files
committed
feat: remove emsi dependence and use u-bahn-api instead for skills
Skill suggestion will now be fetched from the `u-bahn-api`, instead of EMSI. Remove EMSI dependence. Addresses topcoder-archive#627
1 parent 0cfbf2a commit 42cd6bf

File tree

12 files changed

+23
-114
lines changed

12 files changed

+23
-114
lines changed

README.md

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,5 @@ Configuration for the application is at `config/default.js` and `config/producti
6262
- TEMPLATE_S3_BUCKET: the template s3 bucket name, default value is 'ubahn'
6363
- UPLOAD_S3_BUCKET: the upload s3 bucket name, default value is 'ubahn'
6464
- S3_OBJECT_URL_EXPIRY_TIME: the s3 url expiry time, default value is '1 hour'
65-
- EMSI_CLIENT_ID: emsi oAuth 2.0 client id, used to get emis oAuth 2.0 token
66-
- EMSI_CLIENT_SECRET: emsi oAuth 2.0 client secret, used to get emsi oAuth 2.0 token
67-
- EMSI_GRANT_TYPE: emsi oAuth 2.0 grant_type, used to get emsi oAuth 2.0 token, should always be the string 'client_credentials'
68-
- EMSI_SCOPE: emsi oAuth 2.0 scope, used to get emsi oAuth 2.0 token, default value is 'emsi_open'
69-
- EMSI_AUTH_URL: emsi oAuth 2.0 auth url, used to get emsi oAuth 2.0 token, default value is 'https://auth.emsicloud.com/connect/token'
70-
- EMSI_BASE_URL: emsi base url, used to get emsi skills, default value is 'https://skills.emsicloud.com/versions/latest'
7165

7266
Also check out the client folder's README file for additional configurations to set for the front end. You can find the required configurations under client/src/config.js

client/README.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ REACT_APP_API_URL => The endpoint from which the application retrieves the users
1111
1212
REACT_BULK_UPLOAD_TEMPLATE_ID => The id of the database record which is associated with the bulk upload template file. You would need to query the backend to get the id and then set it against this variable
1313
14-
REACT_APP_EMSI_SKILLPROVIDER_ID => The skill provider id with name 'EMSI'. Denotes that the skills with an externalId are using EMSI as the skill provider.
15-
1614
REACT_APP_ATTRIBUTE_ID_LOCATION
1715
REACT_APP_ATTRIBUTE_ID_COMPANY
1816
REACT_APP_ATTRIBUTE_ID_TITLE

client/src/components/EditProfileModal/index.jsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import ProfileCard from "../ProfileCard";
1010
import SuggestionBox from "../SuggestionBox";
1111

1212
import style from "./style.module.scss";
13-
import config from "../../config";
1413

1514
export default function EditProfileModal({
1615
onCancel,
@@ -64,7 +63,9 @@ export default function EditProfileModal({
6463
const addSkill = (skill) => {
6564
// Verify that the skill does not already exist on the user
6665
const index = localUser.skills.findIndex(
67-
(existingSkill) => existingSkill.externalId === skill.id
66+
(existingSkill) =>
67+
existingSkill.skillProviderId === skill.skillProviderId &&
68+
existingSkill.externalId === skill.skillId
6869
);
6970
const exists = localUser.skills[index];
7071

@@ -78,10 +79,10 @@ export default function EditProfileModal({
7879
delete skills[index].isDeleted;
7980
} else {
8081
skills.push({
81-
externalId: skill.id, // The skill id returned from EMSI becomes externalId in our db
82+
externalId: skill.skillId, // The skill id returned from API becomes externalId in our db
8283
isNew: true,
8384
name: skill.name,
84-
skillProviderId: config.EMSI_SKILLPROVIDER_ID,
85+
skillProviderId: skill.skillProviderId,
8586
});
8687
}
8788

client/src/components/FiltersSideMenu/filters.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,13 @@ export default function SearchTabFilters() {
142142
const addSkillToFilter = (skill) => {
143143
const skillFilters = JSON.parse(JSON.stringify(search.selectedSkills));
144144

145-
if (skillFilters.findIndex((s) => s.id === skill.id) !== -1) {
145+
if (
146+
skillFilters.findIndex(
147+
(s) =>
148+
s.skillProviderId === skill.skillProviderId &&
149+
s.skillId === skill.skillId
150+
) !== -1
151+
) {
146152
return;
147153
}
148154

@@ -152,7 +158,11 @@ export default function SearchTabFilters() {
152158

153159
const removeSkillFromFilter = (skill) => {
154160
const skillFilters = JSON.parse(JSON.stringify(search.selectedSkills));
155-
const index = skillFilters.findIndex((s) => s.id === skill.id);
161+
const index = skillFilters.findIndex(
162+
(s) =>
163+
s.skillProviderId === skill.skillProviderId &&
164+
s.skillId === skill.skillId
165+
);
156166

157167
if (index === -1) {
158168
return;

client/src/components/SuggestionBox/index.jsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import React from "react";
22
import Autosuggest from "react-autosuggest";
33
import config from "../../config";
44
import api from "../../services/api";
5+
import { getSingleOrg } from "../../services/user-org";
56
import style from "./style.module.scss";
67
import _ from "lodash";
78
import { useSearch, FILTERS } from "../../lib/search";
@@ -59,12 +60,13 @@ const getSkillsSuggestions = async (apiClient, inputValue) => {
5960
}
6061

6162
term = encodeURIComponent(term);
63+
const organizationId = getSingleOrg();
6264

63-
const url = `${config.API_PREFIX}/skills?q=${term}`;
65+
const url = `${config.API_URL}/search/skills?organizationId=${organizationId}&keyword=${term}`;
6466

6567
const { data } = await apiClient.get(url);
6668

67-
return data.skills;
69+
return data;
6870
};
6971

7072
/**

client/src/config.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ export default {
99
GROUPS_PER_PAGE: process.env.REACT_APP_GROUPS_PER_PAGE || 1000,
1010

1111
BULK_UPLOAD_TEMPLATE_ID: process.env.REACT_APP_BULK_UPLOAD_TEMPLATE_ID,
12-
EMSI_SKILLPROVIDER_ID: process.env.REACT_APP_EMSI_SKILLPROVIDER_ID,
1312

1413
DEFAULT_SORT_ORDER: "name",
1514
ITEMS_PER_PAGE: 12,

config/default.js

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,5 @@ module.exports = {
4343
TEMPLATE_FILE_MIMETYPE: process.env.TEMPLATE_FILE_MIMETYPE || 'application/vnd.ms-excel,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
4444
TEMPLATE_S3_BUCKET: process.env.TEMPLATE_S3_BUCKET || 'ubahn',
4545
UPLOAD_S3_BUCKET: process.env.UPLOAD_S3_BUCKET || 'ubahn',
46-
S3_OBJECT_URL_EXPIRY_TIME: process.env.S3_OBJECT_URL_EXPIRY_TIME || 60 * 60,
47-
48-
EMSI: {
49-
CLIENT_ID: process.env.EMSI_CLIENT_ID,
50-
CLIENT_SECRET: process.env.EMSI_CLIENT_SECRET,
51-
GRANT_TYPE: process.env.EMSI_GRANT_TYPE || 'client_credentials',
52-
SCOPE: process.env.EMSI_SCOPE || 'emsi_open',
53-
AUTH_URL: process.env.EMSI_AUTH_URL || 'https://auth.emsicloud.com/connect/token',
54-
BASE_URL: process.env.EMSI_BASE_URL || 'https://skills.emsicloud.com/versions/latest'
55-
}
46+
S3_OBJECT_URL_EXPIRY_TIME: process.env.S3_OBJECT_URL_EXPIRY_TIME || 60 * 60
5647
}

docker/sample.api.env

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,13 @@ AUTH_SECRET=
88
AWS_ACCESS_KEY_ID=
99
AWS_REGION=
1010
AWS_SECRET_ACCESS_KEY=
11-
EMSI_CLIENT_ID=
12-
EMSI_CLIENT_SECRET=
1311
NODE_ENV=
1412
REACT_APP_API_PREFIX=
1513
REACT_APP_API_URL=
1614
REACT_APP_AUTH0_AUDIENCE=
1715
REACT_APP_AUTH0_CLIENTID=
1816
REACT_APP_AUTH0_DOMAIN=
1917
REACT_APP_BULK_UPLOAD_TEMPLATE_ID=
20-
REACT_APP_EMSI_SKILLPROVIDER_ID=
2118
REACT_APP_GROUPS_API_URL=
2219
TEMPLATE_S3_BUCKET=
2320
TOKEN_CACHE_TIME=

src/common/helper.js

Lines changed: 1 addition & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -288,40 +288,6 @@ async function postEvent (topic, payload) {
288288
await busApiClient.postEvent(message)
289289
}
290290

291-
// cache the emsi token
292-
const tokenCache = new NodeCache()
293-
294-
/**
295-
* Get emsi token
296-
* @returns {string} the emsi token
297-
*/
298-
async function getEmsiToken () {
299-
let token = tokenCache.get('emsi_token')
300-
if (!token) {
301-
const res = await axios.post(config.EMSI.AUTH_URL, querystring.stringify({
302-
client_id: config.EMSI.CLIENT_ID,
303-
client_secret: config.EMSI.CLIENT_SECRET,
304-
grant_type: config.EMSI.GRANT_TYPE,
305-
scope: config.EMSI.SCOPE
306-
}))
307-
token = res.data.access_token
308-
tokenCache.set('emsi_token', token, res.data.expires_in)
309-
}
310-
return token
311-
}
312-
313-
/**
314-
* Get data from emsi
315-
* @param {String} path the emsi endpoint path
316-
* @param {String} params get params
317-
* @returns {Object} response data
318-
*/
319-
async function getEmsiObject (path, params) {
320-
const token = await getEmsiToken()
321-
const res = await axios.get(`${config.EMSI.BASE_URL}${path}`, { params, headers: { authorization: `Bearer ${token}` } })
322-
return res.data
323-
}
324-
325291
module.exports = {
326292
wrapExpress,
327293
autoWrapExpress,
@@ -334,6 +300,5 @@ module.exports = {
334300
generateS3Url,
335301
scan,
336302
validateDuplicate,
337-
postEvent,
338-
getEmsiObject
303+
postEvent
339304
}

src/controllers/SkillController.js

Lines changed: 0 additions & 18 deletions
This file was deleted.

src/routes.js

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -66,15 +66,6 @@ module.exports = {
6666
scopes: [constants.Scopes.GetTemplate, constants.Scopes.AllTemplate]
6767
}
6868
},
69-
'/skills': {
70-
get: {
71-
controller: 'SkillController',
72-
method: 'getEntity',
73-
auth: 'jwt',
74-
access: constants.AllAuthenticatedUsers,
75-
scopes: [constants.Scopes.GetSkill, constants.Scopes.AllSkill]
76-
}
77-
},
7869
'/health': {
7970
get: {
8071
controller: 'HealthCheckController',

src/services/SkillService.js

Lines changed: 0 additions & 21 deletions
This file was deleted.

0 commit comments

Comments
 (0)