Skip to content
Open
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion backend/src/api/activity/activityChannels.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import PermissionChecker from '../../services/user/permissionChecker'
export default async (req, res) => {
new PermissionChecker(req).validateHas(Permissions.values.activityRead)

const payload = await new ActivityService(req).findActivityChannels(req.query.segments)
const payload = await new ActivityService(req).findActivityChannels()

await req.responseHandler.success(req, res, payload)
}
3 changes: 2 additions & 1 deletion backend/src/api/activity/activityTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import PermissionChecker from '../../services/user/permissionChecker'

export default async (req, res) => {
new PermissionChecker(req).validateHas(Permissions.values.activityRead)
const payload = await new ActivityService(req).findActivityTypes(req.query.segments)

const payload = await new ActivityService(req).findActivityTypes()

await req.responseHandler.success(req, res, payload)
}
22 changes: 20 additions & 2 deletions backend/src/database/repositories/integrationRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
} from '@crowd/data-access-layer/src/integrations'
import { QueryExecutor } from '@crowd/data-access-layer/src/queryExecutor'
import { getReposGroupedByOrgForIntegrations } from '@crowd/data-access-layer/src/repositories'
import { getSegmentSubprojectIds } from '@crowd/data-access-layer/src/segments'
import { IntegrationRunState, PlatformType } from '@crowd/types'

import SequelizeFilterUtils from '../utils/sequelizeFilterUtils'
Expand Down Expand Up @@ -66,10 +67,15 @@ class IntegrationRepository {

const transaction = SequelizeRepository.getTransaction(options)

const qx = SequelizeRepository.getQueryExecutor(options)
const currentSegments = SequelizeRepository.getSegmentIds(options)

const subprojectIds = await getSegmentSubprojectIds(qx, currentSegments)

let record = await options.database.integration.findOne({
where: {
id,
segmentId: SequelizeRepository.getSegmentIds(options),
segmentId: subprojectIds,
},
transaction,
})
Expand Down Expand Up @@ -450,6 +456,10 @@ class IntegrationRepository {
nestedFields: {
sentiment: 'sentiment.sentiment',
},
// QueryParser filters on req.currentSegments directly (e.g., projectGroupId).
// Since integrations are stored per subproject, segment filtering is applied manually below
// after expanding to subprojectIds.
withSegments: false,
},
options,
)
Expand All @@ -461,11 +471,19 @@ class IntegrationRepository {
offset,
})

const qx = SequelizeRepository.getQueryExecutor(options)
const currentSegments = SequelizeRepository.getSegmentIds(options)

const subprojectIds = await getSegmentSubprojectIds(qx, currentSegments)

const segmentWhere = { segmentId: subprojectIds }
const where = parsed.where ? { [Op.and]: [parsed.where, segmentWhere] } : segmentWhere

let {
rows,
count, // eslint-disable-line prefer-const
} = await options.database.integration.findAndCountAll({
...(parsed.where ? { where: parsed.where } : {}),
where,
...(parsed.having ? { having: parsed.having } : {}),
order: parsed.order,
limit: limit ? parsed.limit : undefined,
Expand Down
56 changes: 32 additions & 24 deletions backend/src/database/repositories/memberRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ import {
} from '@crowd/data-access-layer/src/members/segments'
import { IDbMemberData } from '@crowd/data-access-layer/src/members/types'
import { optionsQx } from '@crowd/data-access-layer/src/queryExecutor'
import { fetchManySegments } from '@crowd/data-access-layer/src/segments'
import { fetchManySegments, getSegmentSubprojectIds } from '@crowd/data-access-layer/src/segments'
import { ActivityDisplayService } from '@crowd/integrations'
import {
ALL_PLATFORM_TYPES,
Expand Down Expand Up @@ -148,6 +148,9 @@ class MemberRepository {
)

const qx = SequelizeRepository.getQueryExecutor(options)
const currentSegments = SequelizeRepository.getSegmentIds(options)

const subprojectIds = await getSegmentSubprojectIds(qx, currentSegments)

if (data.identities) {
for (const i of data.identities as IMemberIdentity[]) {
Expand Down Expand Up @@ -182,19 +185,15 @@ class MemberRepository {
}
}

await includeMemberToSegments(
qx,
record.id,
options.currentSegments.map((s) => s.id),
)
await includeMemberToSegments(qx, record.id, subprojectIds)

const memberService = new CommonMemberService(optionsQx(options), options.temporal, options.log)

await memberService.updateMemberOrganizations(
record.id,
data.organizations,
true,
options.currentSegments.map((s) => s.id),
subprojectIds,
options,
)

Expand Down Expand Up @@ -234,10 +233,15 @@ class MemberRepository {

const bulkDeleteMemberSegments = `DELETE FROM "memberSegments" WHERE "memberId" in (:memberIds) and "segmentId" in (:segmentIds);`

const qx = SequelizeRepository.getQueryExecutor(options)
const currentSegments = SequelizeRepository.getSegmentIds(options)

const subprojectIds = await getSegmentSubprojectIds(qx, currentSegments)

await seq.query(bulkDeleteMemberSegments, {
replacements: {
memberIds,
segmentIds: SequelizeRepository.getSegmentIds(options),
segmentIds: subprojectIds,
},
type: QueryTypes.DELETE,
transaction,
Expand Down Expand Up @@ -294,13 +298,12 @@ class MemberRepository {
const HIGH_CONFIDENCE_LOWER_BOUND = 0.9
const MEDIUM_CONFIDENCE_LOWER_BOUND = 0.7

const qx = SequelizeRepository.getQueryExecutor(options)
const currentSegments = SequelizeRepository.getSegmentIds(options)

const segmentIds = (
await new SegmentRepository(options).getSegmentSubprojects(currentSegments)
).map((s) => s.id)
const subprojectIds = await getSegmentSubprojectIds(qx, currentSegments)

if (segmentIds.length === 0) {
if (subprojectIds.length === 0) {
return args.countOnly
? { count: '0' }
: {
Expand Down Expand Up @@ -361,7 +364,7 @@ class MemberRepository {
similarityFilter,
displayNameFilter,
{
segmentIds,
segmentIds: subprojectIds,
displayName: args?.filter?.displayName ? `${args.filter.displayName}%` : undefined,
memberId: args?.filter?.memberId,
},
Expand Down Expand Up @@ -403,7 +406,7 @@ class MemberRepository {
`,
{
replacements: {
segmentIds,
segmentIds: subprojectIds,
limit: args.limit,
offset: args.offset,
displayName: args?.filter?.displayName ? `${args.filter.displayName}%` : undefined,
Expand Down Expand Up @@ -509,7 +512,7 @@ class MemberRepository {
similarityFilter,
displayNameFilter,
{
segmentIds,
segmentIds: subprojectIds,
memberId: args?.filter?.memberId,
displayName: args?.filter?.displayName ? `${args.filter.displayName}%` : undefined,
},
Expand Down Expand Up @@ -888,13 +891,19 @@ class MemberRepository {
!manualChange, // no need to track for audit if it's not a manual change
)

const qx = SequelizeRepository.getQueryExecutor(options)
const subprojectIds = await getSegmentSubprojectIds(
qx,
SequelizeRepository.getSegmentIds(options),
)

const memberService = new CommonMemberService(optionsQx(options), options.temporal, options.log)

await memberService.updateMemberOrganizations(
record.id,
data.organizations,
data.organizationsReplace,
options.currentSegments.map((s) => s.id),
subprojectIds,
options,
)

Expand All @@ -915,11 +924,7 @@ class MemberRepository {
}

if (options.currentSegments && options.currentSegments.length > 0) {
await includeMemberToSegments(
optionsQx(options),
record.id,
options.currentSegments.map((s) => s.id),
)
await includeMemberToSegments(qx, record.id, subprojectIds)
}

// Before upserting identities, check if they already exist
Expand Down Expand Up @@ -998,8 +1003,6 @@ class MemberRepository {
}
}

const qx = SequelizeRepository.getQueryExecutor(options)

if (data.identitiesToCreate && data.identitiesToCreate.length > 0) {
for (const i of data.identitiesToCreate) {
await createMemberIdentity(qx, {
Expand Down Expand Up @@ -1801,6 +1804,11 @@ class MemberRepository {

const where = { [Op.and]: whereAnd }

const qx = SequelizeRepository.getQueryExecutor(options)
const currentSegments = SequelizeRepository.getSegmentIds(options)

const subprojectIds = await getSegmentSubprojectIds(qx, currentSegments)

const records = await options.database.member.findAll({
attributes: ['id', 'displayName', 'attributes'],
where,
Expand All @@ -1816,7 +1824,7 @@ class MemberRepository {
model: options.database.segment,
as: 'segments',
where: {
id: SequelizeRepository.getSegmentIds(options),
id: subprojectIds,
},
},
],
Expand Down
48 changes: 28 additions & 20 deletions backend/src/database/repositories/organizationRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import {
} from '@crowd/data-access-layer/src/organizations'
import { findAttribute } from '@crowd/data-access-layer/src/organizations/attributesConfig'
import { optionsQx } from '@crowd/data-access-layer/src/queryExecutor'
import { findSegmentById } from '@crowd/data-access-layer/src/segments'
import { findSegmentById, getSegmentSubprojectIds } from '@crowd/data-access-layer/src/segments'
import {
IMemberRenderFriendlyRole,
IMemberRoleWithOrganization,
Expand Down Expand Up @@ -163,11 +163,12 @@ class OrganizationRepository {
await OrganizationRepository.setIdentities(record.id, data.identities, options)
}

await addOrgsToSegments(
optionsQx(options),
options.currentSegments.map((s) => s.id),
[record.id],
)
const currentSegments = SequelizeRepository.getSegmentIds(options)

const qx = SequelizeRepository.getQueryExecutor(options)
const subprojectIds = await getSegmentSubprojectIds(qx, currentSegments)

await addOrgsToSegments(qx, subprojectIds, [record.id])

return this.findById(record.id, options)
}
Expand All @@ -182,10 +183,15 @@ class OrganizationRepository {

const bulkDeleteOrganizationSegments = `DELETE FROM "organizationSegments" WHERE "organizationId" in (:organizationIds) and "segmentId" in (:segmentIds);`

const currentSegments = SequelizeRepository.getSegmentIds(options)

const qx = SequelizeRepository.getQueryExecutor(options)
const subprojectIds = await getSegmentSubprojectIds(qx, currentSegments)

await seq.query(bulkDeleteOrganizationSegments, {
replacements: {
organizationIds,
segmentIds: SequelizeRepository.getSegmentIds(options),
segmentIds: subprojectIds,
},
type: QueryTypes.DELETE,
transaction,
Expand Down Expand Up @@ -430,11 +436,12 @@ class OrganizationRepository {
}

if (data.segments) {
await addOrgsToSegments(
optionsQx(options),
options.currentSegments.map((s) => s.id),
[record.id],
)
const qx = SequelizeRepository.getQueryExecutor(options)
const currentSegments = SequelizeRepository.getSegmentIds(options)

const subprojectIds = await getSegmentSubprojectIds(qx, currentSegments)

await addOrgsToSegments(qx, subprojectIds, [record.id])
}

await captureApiChange(
Expand Down Expand Up @@ -842,10 +849,10 @@ class OrganizationRepository {
const HIGH_CONFIDENCE_LOWER_BOUND = 0.9
const MEDIUM_CONFIDENCE_LOWER_BOUND = 0.7

const qx = SequelizeRepository.getQueryExecutor(options)
const currentSegments = SequelizeRepository.getSegmentIds(options)
const segmentIds = (
await new SegmentRepository(options).getSegmentSubprojects(currentSegments)
).map((s) => s.id)

const segmentIds = await getSegmentSubprojectIds(qx, currentSegments)

let similarityFilter = ''
const similarityConditions = []
Expand Down Expand Up @@ -1619,7 +1626,10 @@ class OrganizationRepository {

static async findAllAutocomplete(query, limit, options: IRepositoryOptions) {
const tenant = SequelizeRepository.getCurrentTenant(options)
const segmentIds = SequelizeRepository.getSegmentIds(options)
const qx = SequelizeRepository.getQueryExecutor(options)
const currentSegments = SequelizeRepository.getSegmentIds(options)

const subprojectIds = await getSegmentSubprojectIds(qx, currentSegments)

const records = await options.database.sequelize.query(
`
Expand All @@ -1643,7 +1653,7 @@ class OrganizationRepository {
replacements: {
limit: limit ? Number(limit) : 20,
tenantId: tenant.id,
segmentIds,
segmentIds: subprojectIds,
queryLike: `%${query}%`,
queryExact: query,
uuid: validator.isUUID(query) ? query : null,
Expand Down Expand Up @@ -1758,9 +1768,7 @@ class OrganizationRepository {
const qx = SequelizeRepository.getQueryExecutor(options)
const activityTypes = SegmentRepository.getActivityTypes(options)

const subprojectIds = (
await new SegmentRepository(options).getSegmentSubprojects(currentSegments)
).map((s) => s.id)
const subprojectIds = await getSegmentSubprojectIds(qx, currentSegments)

const result = await queryActivities(
{
Expand Down
Loading
Loading