Skip to content

Commit a89b2ba

Browse files
committed
Merge branch 'feature/challenge-filters-refactoring' into merge
2 parents 47ba657 + 0843a45 commit a89b2ba

File tree

97 files changed

+3490
-4666
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

97 files changed

+3490
-4666
lines changed

config/default.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
"ONLINE_REVIEW": "https://software.topcoder-dev.com",
5252
"STUDIO": "https://studio.topcoder-dev.com",
5353
"TCO": "https://www.topcoder.com/tco",
54+
"USER_SETTINGS": "https://lc1-user-settings-service.herokuapp.com",
5455
"WIPRO": "https://wipro.topcoder.com"
5556
},
5657
"DOMAIN": "topcoder-dev.com",

docs/how-to-add-a-new-topcoder-community.md

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@ To add a new community with the name **demo**, we should follow the following pr
1010
"authorizedGroupIds": [
1111
"12345"
1212
],
13-
"challengeGroupId": "12345",
14-
"challengeFilterTag": "",
13+
"challengeFilter": {
14+
"groupIds": ["12345"]
15+
},
1516
"communityId": "demo",
1617
"communitySelector": [{
1718
"label": "Demo Community",
@@ -25,6 +26,7 @@ To add a new community with the name **demo**, we should follow the following pr
2526
"redirect": "https://ios.topcoder.com/",
2627
"value": "3"
2728
}],
29+
"groupId": "12345",
2830
"leaderboardApiUrl": "https://api.topcoder.com/v4/looks/0/run/json/",
2931
"logos": [
3032
"/themes/demo/logo_topcoder_with_name.svg"
@@ -49,10 +51,28 @@ To add a new community with the name **demo**, we should follow the following pr
4951
```
5052
Its fields serve the following purposes:
5153
- `authorizedGroupIds` - *String Array* - Optional. Array of group IDs. If specified, access to the community will be restricted only to authenticated visitors, included into, at least, one of the groups listed in this array. If undefined, community will be accessible to any visitors (including non-authenticated ones).
52-
- `challengeGroupId` - *String* - Optional. ID of the group holding challenges related to this community. If undefined, challenge listing in this community will show all public challenges.
53-
- `challengeFilterTag` - *String* - Optional. If specified, and not an empty string, only challenges having this technology tag will be shown inside the community (it acts as an additional filter after the group-based filtering).
54+
- `challengeFilter` - *Object* - Challenge filter matching challenges related to the community. This object can include any options known to the `/src/utils/challenge-listing/filter.js` module, though in many cases you want to use just one of these:
55+
```js
56+
/* Matches challenges belonging to any of the groups listed by ID. */
57+
{
58+
"groupIds": ["12345"]
59+
}
60+
61+
/* Matches challenges tagged with at least one of the tags. */
62+
{
63+
"tags": ["JavaScript"]
64+
}
65+
66+
/* Matches challenges belonging to any of the groups AND tagged with
67+
* at least one of the tags. */
68+
{
69+
"groupIds": ["12345"],
70+
"tags": ["JavaScript"]
71+
}
72+
```
5473
- `communityId` - *String* - Unique ID of this community.
5574
- `communitySelector` - *Object Array* - Specifies data for the community selection dropdown inside the community header. Each object MUST HAVE `label` and `value` string fields, and MAY HAVE `redirect` field. If `redirect` field is specified, a click on that option in the dropdown will redirect user to the specified URL.
75+
- `groupId` - *String* - This value of group ID is now used to fetch community statistics. Probably, it makes sense to use this value everywhere where `authorizedGroupIds` array is used, however, at the moment, these two are independent.
5676
- `leaderboardApiUrl` - *String* - Endpoint from where the leaderboard data should be loaded.
5777
- `logo` - *String Array* - Array of image URLs to insert as logos into the left corner of community's header.
5878
- `menuItems` - *Object Array* - Specifies options for the community navigation menu (both in the header and footer). Each object MUST HAVE `title` and `url` fields. For now, `url` field should be a relative link inside the community, within the same path segment.

src/server/tc-communities/community-2/metadata.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22
"authorizedGroupIds": [
33
"20000002"
44
],
5-
"challengeGroupId": "20000002",
6-
"challengeFilterTag": "",
5+
"challengeFilter": {
6+
"groupIds": ["20000002"]
7+
},
78
"communityId": "community-2",
89
"communityName": "Community 2",
910
"communitySelector": [{
@@ -18,6 +19,7 @@
1819
"redirect": "https://ios.topcoder.com/",
1920
"value": "3"
2021
}],
22+
"groupId": "20000002",
2123
"leaderboardApiUrl": "https://api.topcoder.com/v4/looks/458/run/json/",
2224
"logos": [
2325
"/themes/community-2/wipro-logo.png",

src/server/tc-communities/demo-expert/metadata.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
{
2-
"challengeGroupId": "1001",
3-
"challengeFilterTag": ".NET",
2+
"challengeFilter": {
3+
"groupIds": ["1001"],
4+
"tags": [".NET"]
5+
},
46
"communityId": "demo-expert",
57
"communityName": "Demo Expert Community",
68
"communitySelector": [{
@@ -15,6 +17,7 @@
1517
"redirect": "https://ios.topcoder.com/",
1618
"value": "3"
1719
}],
20+
"groupId": "1001",
1821
"logos": [
1922
"/themes/demo-expert/logo_topcoder_with_name.svg"
2023
],

src/server/tc-communities/example-theme-default/metadata.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{
2+
"authorizedGroupIds": [],
23
"communityId": "example-theme-default",
34
"communityName": "Example Community",
45
"logos": ["http://predix.topcoder.com/wp-content/uploads/sites/7/2016/11/topcoder-hat-logo.png"],

src/server/tc-communities/example-theme-green/metadata.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{
2+
"authorizedGroupIds": [],
23
"communityId": "example-theme-green",
34
"communityName": "Example Community",
45
"logos": ["http://predix.topcoder.com/wp-content/uploads/sites/7/2016/11/topcoder-hat-logo.png"],

src/server/tc-communities/example-theme-red/metadata.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{
2+
"authorizedGroupIds": [],
23
"communityId": "example-theme-red",
34
"communityName": "Example Community",
45
"logos": ["http://predix.topcoder.com/wp-content/uploads/sites/7/2016/11/topcoder-hat-logo.png"],

src/server/tc-communities/index.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,43 @@
22
* Routes for demo API of tc-communities
33
*/
44

5+
import _ from 'lodash';
56
import express from 'express';
7+
import fs from 'fs';
68
import { getCommunitiesMetadata } from 'utils/tc';
79

810
const router = express.Router();
911

12+
/**
13+
* GET challenge filters for public and specified private communities.
14+
* As of now, it expects that array of IDs of groups a user has access to
15+
* will be passed in the query. It uses these IDs to determine which communities
16+
* should be included into the response.
17+
*/
18+
router.get('/', (req, res) => {
19+
const filters = [];
20+
const groups = new Set(req.query.groups || []);
21+
const communities = fs.readdirSync(__dirname);
22+
communities.forEach((community) => {
23+
try {
24+
const path = `${__dirname}/${community}/metadata.json`;
25+
const data = JSON.parse(fs.readFileSync(path, 'utf8'));
26+
if (!data.authorizedGroupIds
27+
|| data.authorizedGroupIds.some(id => groups.has(id))) {
28+
filters.push({
29+
filter: data.challengeFilter || {},
30+
id: data.communityId,
31+
name: data.communityName,
32+
});
33+
}
34+
} catch (e) {
35+
_.noop();
36+
}
37+
});
38+
filters.sort((a, b) => a.name.localeCompare(b.name));
39+
res.json(filters);
40+
});
41+
1042
/**
1143
* Endpoint for community meta data
1244
*/

src/server/tc-communities/tc-prod-dev/metadata.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
2-
"challengeGroupId": "20000001",
3-
"challengeFilterTag": "",
2+
"challengeFilter": {
3+
"groupIds": ["20000001"]
4+
},
45
"communityId": "tc-prod-dev",
56
"communityName": "Topcoder Product Development",
67
"communitySelector": [{
@@ -15,6 +16,7 @@
1516
"redirect": "https://ios.topcoder.com/",
1617
"value": "3"
1718
}],
19+
"groupId": "20000001",
1820
"logos": [
1921
"/themes/wipro/logo_topcoder_with_name.svg"
2022
],

src/server/tc-communities/wipro/metadata.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22
"authorizedGroupIds": [
33
"20000000"
44
],
5-
"challengeGroupId": "20000000",
6-
"challengeFilterTag": "",
5+
"challengeFilter": {
6+
"groupIds": ["20000000"]
7+
},
78
"communityId": "wipro",
89
"communityName": "Wipro Hybrid Crowd",
910
"communitySelector": [{
@@ -18,6 +19,7 @@
1819
"redirect": "https://ios.topcoder.com/",
1920
"value": "3"
2021
}],
22+
"groupId": "20000000",
2123
"leaderboardApiUrl": "https://api.topcoder.com/v4/looks/458/run/json/",
2224
"logos": [
2325
"/themes/wipro/wipro-logo.png",

0 commit comments

Comments
 (0)