Merge pull request #3366 from specklesystems/alessandro/web-943-add-branch-deleted-activity

Activitystream IoC 4 addBranchDeletedActivity
This commit is contained in:
Alessandro Magionami
2024-10-23 09:33:30 +02:00
committed by GitHub
7 changed files with 69 additions and 50 deletions
@@ -11,9 +11,11 @@ import {
} from '@/modules/activitystream/helpers/types'
import { CommentRecord } from '@/modules/comments/helpers/types'
import {
BranchDeleteInput,
BranchUpdateInput,
CommitCreateInput,
CommitUpdateInput,
DeleteModelInput,
MutationCommentArchiveArgs,
ProjectUpdateInput,
StreamUpdateInput,
@@ -280,3 +282,9 @@ export type AddBranchUpdatedActivity = (params: {
oldBranch: BranchRecord
newBranch: BranchRecord
}) => Promise<void>
export type AddBranchDeletedActivity = (params: {
input: BranchDeleteInput | DeleteModelInput
userId: string
branchName: string
}) => Promise<void>
@@ -4,17 +4,12 @@ import {
BranchSubscriptions as BranchPubsubEvents,
PublishSubscription
} from '@/modules/shared/utils/subscriptions'
import {
BranchDeleteInput,
DeleteModelInput,
ProjectModelsUpdatedMessageType
} from '@/modules/core/graph/generated/graphql'
import { ProjectSubscriptions, publish } from '@/modules/shared/utils/subscriptions'
import { ProjectModelsUpdatedMessageType } from '@/modules/core/graph/generated/graphql'
import { ProjectSubscriptions } from '@/modules/shared/utils/subscriptions'
import { isBranchDeleteInput, isBranchUpdateInput } from '@/modules/core/helpers/branch'
import { saveActivityFactory } from '@/modules/activitystream/repositories'
import { db } from '@/db/knex'
import {
AddBranchCreatedActivity,
AddBranchDeletedActivity,
AddBranchUpdatedActivity,
SaveActivity
} from '@/modules/activitystream/domain/operations'
@@ -98,35 +93,39 @@ export const addBranchUpdatedActivityFactory =
])
}
export async function addBranchDeletedActivity(params: {
input: BranchDeleteInput | DeleteModelInput
userId: string
branchName: string
}) {
const { input, userId, branchName } = params
export const addBranchDeletedActivityFactory =
({
saveActivity,
publish
}: {
saveActivity: SaveActivity
publish: PublishSubscription
}): AddBranchDeletedActivity =>
async (params) => {
const { input, userId, branchName } = params
const streamId = isBranchDeleteInput(input) ? input.streamId : input.projectId
await Promise.all([
saveActivityFactory({ db })({
streamId,
resourceType: ResourceTypes.Branch,
resourceId: input.id,
actionType: ActionTypes.Branch.Delete,
userId,
info: { branch: { ...input, name: branchName } },
message: `Branch deleted: '${branchName}' (${input.id})`
}),
pubsub.publish(BranchPubsubEvents.BranchDeleted, {
branchDeleted: input,
streamId
}),
publish(ProjectSubscriptions.ProjectModelsUpdated, {
projectId: streamId,
projectModelsUpdated: {
id: input.id,
type: ProjectModelsUpdatedMessageType.Deleted,
model: null
}
})
])
}
const streamId = isBranchDeleteInput(input) ? input.streamId : input.projectId
await Promise.all([
saveActivity({
streamId,
resourceType: ResourceTypes.Branch,
resourceId: input.id,
actionType: ActionTypes.Branch.Delete,
userId,
info: { branch: { ...input, name: branchName } },
message: `Branch deleted: '${branchName}' (${input.id})`
}),
pubsub.publish(BranchPubsubEvents.BranchDeleted, {
branchDeleted: input,
streamId
}),
publish(ProjectSubscriptions.ProjectModelsUpdated, {
projectId: streamId,
projectModelsUpdated: {
id: input.id,
type: ProjectModelsUpdatedMessageType.Deleted,
model: null
}
})
])
}
@@ -17,8 +17,8 @@ import {
} from '@/modules/core/repositories/branches'
import { db } from '@/db/knex'
import {
addBranchDeletedActivity,
addBranchCreatedActivityFactory,
addBranchDeletedActivityFactory,
addBranchUpdatedActivityFactory
} from '@/modules/activitystream/services/branchActivity'
import {
@@ -57,7 +57,10 @@ const deleteBranchAndNotify = deleteBranchAndNotifyFactory({
getBranchById: getBranchByIdFactory({ db }),
modelsEventsEmitter: ModelsEmitter.emit,
markBranchStreamUpdated,
addBranchDeletedActivity,
addBranchDeletedActivity: addBranchDeletedActivityFactory({
saveActivity: saveActivityFactory({ db }),
publish
}),
deleteBranchById: deleteBranchByIdFactory({ db })
})
const getUser = legacyGetUserFactory({ db })
@@ -52,7 +52,7 @@ import {
import { db } from '@/db/knex'
import {
addBranchCreatedActivityFactory,
addBranchDeletedActivity,
addBranchDeletedActivityFactory,
addBranchUpdatedActivityFactory
} from '@/modules/activitystream/services/branchActivity'
import {
@@ -109,7 +109,10 @@ const deleteBranchAndNotify = deleteBranchAndNotifyFactory({
getBranchById: getBranchByIdFactory({ db }),
modelsEventsEmitter: ModelsEmitter.emit,
markBranchStreamUpdated,
addBranchDeletedActivity,
addBranchDeletedActivity: addBranchDeletedActivityFactory({
saveActivity: saveActivityFactory({ db }),
publish
}),
deleteBranchById: deleteBranchByIdFactory({ db })
})
@@ -1,5 +1,4 @@
import { Roles, isNullOrUndefined } from '@speckle/shared'
import { addBranchDeletedActivity } from '@/modules/activitystream/services/branchActivity'
import {
BranchCreateError,
BranchDeleteError,
@@ -33,6 +32,7 @@ import {
} from '@/modules/core/domain/streams/operations'
import {
AddBranchCreatedActivity,
AddBranchDeletedActivity,
AddBranchUpdatedActivity
} from '@/modules/activitystream/domain/operations'
@@ -115,7 +115,7 @@ export const deleteBranchAndNotifyFactory =
getBranchById: GetBranchById
modelsEventsEmitter: ModelsEventsEmitter
markBranchStreamUpdated: MarkBranchStreamUpdated
addBranchDeletedActivity: typeof addBranchDeletedActivity
addBranchDeletedActivity: AddBranchDeletedActivity
deleteBranchById: DeleteBranchById
}): DeleteBranchAndNotify =>
async (input: BranchDeleteInput | DeleteModelInput, userId: string) => {
@@ -24,8 +24,8 @@ const {
getStreamBranchCountFactory
} = require('@/modules/core/repositories/branches')
const {
addBranchDeletedActivity,
addBranchUpdatedActivityFactory
addBranchUpdatedActivityFactory,
addBranchDeletedActivityFactory
} = require('@/modules/activitystream/services/branchActivity')
const {
getStreamFactory,
@@ -139,7 +139,10 @@ const deleteBranchAndNotify = deleteBranchAndNotifyFactory({
getBranchById: getBranchByIdFactory({ db: knex }),
modelsEventsEmitter: ModelsEmitter.emit,
markBranchStreamUpdated,
addBranchDeletedActivity,
addBranchDeletedActivity: addBranchDeletedActivityFactory({
saveActivity: saveActivityFactory({ db }),
publish
}),
deleteBranchById: deleteBranchByIdFactory({ db: knex })
})
@@ -51,7 +51,6 @@ import {
import { db } from '@/db/knex'
import { deleteBranchAndNotifyFactory } from '@/modules/core/services/branch/management'
import { ModelsEmitter } from '@/modules/core/events/modelsEmitter'
import { addBranchDeletedActivity } from '@/modules/activitystream/services/branchActivity'
import {
createCommitByBranchIdFactory,
createCommitByBranchNameFactory
@@ -105,6 +104,7 @@ import {
import { changeUserRoleFactory } from '@/modules/core/services/users/management'
import { getServerInfoFactory } from '@/modules/core/repositories/server'
import { createObjectFactory } from '@/modules/core/services/objects/management'
import { addBranchDeletedActivityFactory } from '@/modules/activitystream/services/branchActivity'
const getServerInfo = getServerInfoFactory({ db })
const getUser = getUserFactory({ db })
@@ -119,7 +119,10 @@ const deleteBranchAndNotify = deleteBranchAndNotifyFactory({
getBranchById: getBranchByIdFactory({ db }),
modelsEventsEmitter: ModelsEmitter.emit,
markBranchStreamUpdated,
addBranchDeletedActivity,
addBranchDeletedActivity: addBranchDeletedActivityFactory({
saveActivity: saveActivityFactory({ db }),
publish
}),
deleteBranchById: deleteBranchByIdFactory({ db })
})