Skip to content

Commit

Permalink
Feature/with feature flags (#1716)
Browse files Browse the repository at this point in the history
Co-authored-by: Joana Maia <[email protected]>
  • Loading branch information
2 people authored and sausage-todd committed Dec 7, 2023
1 parent 3967c6c commit 5bb4bf7
Show file tree
Hide file tree
Showing 21 changed files with 383 additions and 38 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,6 @@ api-test/__pycache__/api_test.cpython-39-pytest-6.2.4.pyc
/backend/superface/**
docker/volume

services/libs/*/dist
services/libs/*/dist

**/.cubestore
5 changes: 4 additions & 1 deletion backend/.env.dist.local
Original file line number Diff line number Diff line change
Expand Up @@ -167,11 +167,14 @@ CROWD_ANALYTICS_TENANT_ID=
CROWD_ANALYTICS_BASE_URL=
CROWD_ANALYTICS_API_TOKEN=

# GITHUB_TOKEN
CROWD_GITHUB_TOKEN=

# Temporal
CROWD_TEMPORAL_SERVER_URL=localhost:7233
CROWD_TEMPORAL_NAMESPACE=default
CROWD_TEMPORAL_ENCRYPTION_KEY_ID=local
CROWD_TEMPORAL_ENCRYPTION_KEY=FweBMRnGCLshER8FlSvNusQA6G3MRUKt

# Seach sync api
CROWD_SEARCH_SYNC_API_URL=http://search-sync-api:8083
CROWD_SEARCH_SYNC_API_URL=http://search-sync-api:8083
3 changes: 3 additions & 0 deletions backend/config/custom-environment-variables.json
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,9 @@
"url": "CROWD_EAGLE_EYE_URL",
"apiKey": "CROWD_EAGLE_EYE_API_KEY"
},
"githubToken": {
"token": "CROWD_GITHUB_TOKEN"
},
"slackAlerting": {
"url": "CROWD_SLACK_ALERTING_URL"
},
Expand Down
1 change: 1 addition & 0 deletions backend/config/default.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
"enrichment": {},
"organizationEnrichment": {},
"eagleEye": {},
"githubToken": {},
"unleash": {
"db": {}
},
Expand Down
39 changes: 23 additions & 16 deletions backend/package-lock.json

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

5 changes: 5 additions & 0 deletions backend/src/api/member/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ export default (app) => {
app.get(`/tenant/:tenantId/member`, safeWrap(require('./memberList').default))
app.get(`/tenant/:tenantId/member/active`, safeWrap(require('./memberActiveList').default))
app.get(`/tenant/:tenantId/member/:id`, safeWrap(require('./memberFind').default))
app.get(
`/tenant/:tenantId/member/github/:id`,
featureFlagMiddleware(FeatureFlag.FIND_GITHUB, 'errors.featureFlag.notEnabled'),
safeWrap(require('./memberFindGithub').default),
)
app.put(`/tenant/:tenantId/member/:memberId/merge`, safeWrap(require('./memberMerge').default))
app.put(
`/tenant/:tenantId/member/:memberId/no-merge`,
Expand Down
26 changes: 26 additions & 0 deletions backend/src/api/member/memberFindGithub.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import Permissions from '../../security/permissions'
import MemberService from '../../services/memberService'
import PermissionChecker from '../../services/user/permissionChecker'

/**
* GET /tenant/{tenantId}/member/{id}
* @summary Find a member
* @tag Members
* @security Bearer
* @description Find a single member by ID.
* @pathParam {string} tenantId - Your workspace/tenant ID
* @pathParam {string} id - The ID of the member
* @response 200 - Ok
* @responseContent {MemberResponse} 200.application/json
* @responseExample {MemberFind} 200.application/json.Member
* @response 401 - Unauthorized
* @response 404 - Not found
* @response 429 - Too many requests
*/
export default async (req, res) => {
new PermissionChecker(req).validateHas(Permissions.values.memberRead)

const payload = await new MemberService(req).findGithub(req.params.id)

await req.responseHandler.success(req, res, payload)
}
3 changes: 2 additions & 1 deletion backend/src/bin/scripts/unleash-init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ const constaintConfiguration = {
},
],
],
[FeatureFlag.FIND_GITHUB]: [[]],
[FeatureFlag.LINKEDIN]: [
[
{
Expand Down Expand Up @@ -428,7 +429,7 @@ async function createStrategy(flag: FeatureFlag, constraints: any[]): Promise<vo
}

log.info(`Feature flag ${flag} constraints not found - creating...`)

constraints = constraints || []
for (const constraint of constraints) {
const id = generateUUIDv1()
await seq.query(
Expand Down
4 changes: 4 additions & 0 deletions backend/src/conf/configTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,10 @@ export interface EagleEyeConfiguration {
apiKey: string
}

export interface GithubTokenConfiguration {
token: string
}

export interface UnleashConfiguration {
url: string
adminApiKey: string
Expand Down
4 changes: 4 additions & 0 deletions backend/src/conf/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import {
IBackendTemporalConfig,
EncryptionConfiguration,
IOpenStatusApiConfig,
GithubTokenConfiguration,
} from './configTypes'

// TODO-kube
Expand Down Expand Up @@ -125,6 +126,9 @@ export const ORGANIZATION_ENRICHMENT_CONFIG: OrganizationEnrichmentConfiguration

export const EAGLE_EYE_CONFIG: EagleEyeConfiguration = config.get<EagleEyeConfiguration>('eagleEye')

export const GITHUB_TOKEN_CONFIG: GithubTokenConfiguration =
config.get<GithubTokenConfiguration>('githubToken')

export const UNLEASH_CONFIG: UnleashConfiguration = config.get<UnleashConfiguration>('unleash')

export const OPENSEARCH_CONFIG: IOpenSearchConfig = config.get<IOpenSearchConfig>('opensearch')
Expand Down
24 changes: 24 additions & 0 deletions backend/src/services/memberService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import MemberAttributeSettingsService from './memberAttributeSettingsService'
import OrganizationService from './organizationService'
import SearchSyncService from './searchSyncService'
import SettingsService from './settingsService'
import { GITHUB_TOKEN_CONFIG } from '../conf'
import { ServiceType } from '@/conf/configTypes'

export default class MemberService extends LoggerBase {
Expand Down Expand Up @@ -789,6 +790,29 @@ export default class MemberService extends LoggerBase {
})
}

async findGithub(memberId) {
const memberIdentities = (await MemberRepository.findById(memberId, this.options)).username
const axios = require('axios')
// GitHub allows a maximum of 5 parameters
const identities = Object.values(memberIdentities).flat().slice(0, 5)
// Join the usernames for search
const identitiesQuery = identities.join('+OR+')
const url = `https://api.github.com/search/users?q=${identitiesQuery}`
const headers = {
Accept: 'application/vnd.github+json',
Authorization: `Bearer ${GITHUB_TOKEN_CONFIG.token}`,
'X-GitHub-Api-Version': '2022-11-28',
}
const response = await axios.get(url, { headers })
const data = response.data.items.map((item) => ({
username: item.login,
avatarUrl: item.avatar_url,
score: item.score,
url: item.html_url,
}))
return data
}

/**
* Given two members, add them to the toMerge fields of each other.
* It will also update the tenant's toMerge list, removing any entry that contains
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -650,11 +650,16 @@
<app-member-dropdown-content
v-if="selectedActionMember"
:member="selectedActionMember"
@find-github="isFindGithubDrawerOpen = selectedActionMember"
@merge="isMergeDialogOpen = selectedActionMember"
@close-dropdown="closeDropdown"
/>
</div>
</el-popover>
<app-member-find-github-drawer
v-if="isFindGithubDrawerOpen"
v-model="isFindGithubDrawerOpen"
/>
<app-member-merge-dialog v-model="isMergeDialogOpen" />
<app-tag-popover v-model="isEditTagsDialogOpen" :member="editTagMember" @reload="fetchMembers({ reload: true })" />
</div>
Expand All @@ -680,6 +685,7 @@ import { getSegmentsFromProjectGroup } from '@/utils/segments';
import AppMemberMergeDialog from '@/modules/member/components/member-merge-dialog.vue';
import AppTagPopover from '@/modules/tag/components/tag-popover.vue';
import AppPagination from '@/shared/pagination/pagination.vue';
import AppMemberFindGithubDrawer from '@/modules/member/components/member-find-github-drawer.vue';
import AppSharedTagList from '@/shared/tag/tag-list.vue';
import AppSvg from '@/shared/svg/svg.vue';
import AppMemberBadge from '../member-badge.vue';
Expand Down Expand Up @@ -708,6 +714,8 @@ const memberDropdownPopover = ref(null);
const actionBtnRefs = ref({});
const selectedActionMember = ref(null);
const isFindGithubDrawerOpen = ref(null);
const props = defineProps({
hasIntegrations: {
type: Boolean,
Expand Down
Loading

0 comments on commit 5bb4bf7

Please sign in to comment.