chore(server): refactor activityStream invocations - batch #4 - commits
This commit is contained in:
@@ -0,0 +1,195 @@
|
||||
import {
|
||||
AddCommitCreatedActivity,
|
||||
AddCommitDeletedActivity,
|
||||
AddCommitUpdatedActivity,
|
||||
SaveActivity
|
||||
} from '@/modules/activitystream/domain/operations'
|
||||
import { ActionTypes, ResourceTypes } from '@/modules/activitystream/helpers/types'
|
||||
import { VersionEvents } from '@/modules/core/domain/commits/events'
|
||||
import { CommitCreateInput } from '@/modules/core/graph/generated/graphql'
|
||||
import { CommitRecord } from '@/modules/core/helpers/types'
|
||||
import { EventBusListen } from '@/modules/shared/services/eventBus'
|
||||
import { MaybeNullOrUndefined } from '@speckle/shared'
|
||||
|
||||
/**
|
||||
* Save "new commit created" activity item
|
||||
*/
|
||||
const addCommitCreatedActivityFactory =
|
||||
({ saveActivity }: { saveActivity: SaveActivity }): AddCommitCreatedActivity =>
|
||||
async (params: {
|
||||
commitId: string
|
||||
streamId: string
|
||||
userId: string
|
||||
input: CommitCreateInput
|
||||
branchName: string
|
||||
modelId: string
|
||||
commit: CommitRecord
|
||||
}) => {
|
||||
const { commitId, input, streamId, userId, branchName, commit, modelId } = params
|
||||
await saveActivity({
|
||||
streamId,
|
||||
resourceType: ResourceTypes.Commit,
|
||||
resourceId: commitId,
|
||||
actionType: ActionTypes.Commit.Create,
|
||||
userId,
|
||||
info: {
|
||||
id: commitId,
|
||||
commit: {
|
||||
...input,
|
||||
projectId: streamId,
|
||||
modelId,
|
||||
versionId: commit.id
|
||||
}
|
||||
},
|
||||
message: `Commit created on branch ${branchName}: ${commitId} (${input.message})`
|
||||
})
|
||||
}
|
||||
|
||||
const addCommitUpdatedActivityFactory =
|
||||
({ saveActivity }: { saveActivity: SaveActivity }): AddCommitUpdatedActivity =>
|
||||
async (params) => {
|
||||
const { commitId, streamId, userId, originalCommit, update } = params
|
||||
|
||||
await saveActivity({
|
||||
streamId,
|
||||
resourceType: ResourceTypes.Commit,
|
||||
resourceId: commitId,
|
||||
actionType: ActionTypes.Commit.Update,
|
||||
userId,
|
||||
info: { old: originalCommit, new: update },
|
||||
message: `Commit updated: ${commitId}`
|
||||
})
|
||||
}
|
||||
|
||||
const addCommitMovedActivityFactory =
|
||||
({ saveActivity }: { saveActivity: SaveActivity }) =>
|
||||
async (params: {
|
||||
commitId: string
|
||||
streamId: string
|
||||
userId: string
|
||||
originalBranchId: string
|
||||
newBranchId: string
|
||||
commit: CommitRecord
|
||||
}) => {
|
||||
const { commitId, streamId, userId, originalBranchId, newBranchId } = params
|
||||
await saveActivity({
|
||||
streamId,
|
||||
resourceType: ResourceTypes.Commit,
|
||||
resourceId: commitId,
|
||||
actionType: ActionTypes.Commit.Move,
|
||||
userId,
|
||||
info: { originalBranchId, newBranchId },
|
||||
message: `Commit moved: ${commitId}`
|
||||
})
|
||||
}
|
||||
|
||||
const addCommitDeletedActivityFactory =
|
||||
({ saveActivity }: { saveActivity: SaveActivity }): AddCommitDeletedActivity =>
|
||||
async (params: {
|
||||
commitId: string
|
||||
streamId: string
|
||||
userId: string
|
||||
commit: CommitRecord
|
||||
branchId: string
|
||||
}) => {
|
||||
const { commitId, streamId, userId, commit } = params
|
||||
await saveActivity({
|
||||
streamId,
|
||||
resourceType: ResourceTypes.Commit,
|
||||
resourceId: commitId,
|
||||
actionType: ActionTypes.Commit.Delete,
|
||||
userId,
|
||||
info: { commit },
|
||||
message: `Commit deleted: ${commitId}`
|
||||
})
|
||||
}
|
||||
|
||||
const addCommitReceivedActivityFactory =
|
||||
({ saveActivity }: { saveActivity: SaveActivity }) =>
|
||||
async (params: {
|
||||
streamId: string
|
||||
commitId: string
|
||||
userId: string
|
||||
sourceApplication: string
|
||||
message: MaybeNullOrUndefined<string>
|
||||
}) => {
|
||||
const { streamId, commitId, userId, sourceApplication, message } = params
|
||||
await saveActivity({
|
||||
streamId,
|
||||
resourceType: ResourceTypes.Commit,
|
||||
resourceId: commitId,
|
||||
actionType: ActionTypes.Commit.Receive,
|
||||
userId,
|
||||
info: {
|
||||
sourceApplication,
|
||||
message
|
||||
},
|
||||
message: `Commit $commitId} was received by user ${userId}`
|
||||
})
|
||||
}
|
||||
|
||||
export const reportCommitActivityFactory =
|
||||
(deps: { eventListen: EventBusListen; saveActivity: SaveActivity }) => () => {
|
||||
const addCommitCreatedActivity = addCommitCreatedActivityFactory(deps)
|
||||
const addCommitUpdatedActivity = addCommitUpdatedActivityFactory(deps)
|
||||
const addCommitMovedActivity = addCommitMovedActivityFactory(deps)
|
||||
const addCommitDeletedActivity = addCommitDeletedActivityFactory(deps)
|
||||
const addCommitReceivedActivity = addCommitReceivedActivityFactory(deps)
|
||||
|
||||
const quitters = [
|
||||
deps.eventListen(VersionEvents.Created, async ({ payload }) => {
|
||||
await addCommitCreatedActivity({
|
||||
commitId: payload.version.id,
|
||||
streamId: payload.projectId,
|
||||
userId: payload.userId,
|
||||
input: payload.input,
|
||||
branchName: payload.modelName,
|
||||
modelId: payload.modelId,
|
||||
commit: payload.version
|
||||
})
|
||||
}),
|
||||
deps.eventListen(VersionEvents.Updated, async ({ payload }) => {
|
||||
await addCommitUpdatedActivity({
|
||||
commitId: payload.versionId,
|
||||
streamId: payload.projectId,
|
||||
userId: payload.userId,
|
||||
originalCommit: payload.oldVersion,
|
||||
update: payload.update,
|
||||
newCommit: payload.newVersion,
|
||||
branchId: payload.modelId
|
||||
})
|
||||
}),
|
||||
deps.eventListen(VersionEvents.MovedModel, async ({ payload }) => {
|
||||
await addCommitMovedActivity({
|
||||
commitId: payload.version.id,
|
||||
streamId: payload.projectId,
|
||||
userId: payload.userId,
|
||||
originalBranchId: payload.originalModelId,
|
||||
newBranchId: payload.newModelId,
|
||||
commit: payload.version
|
||||
})
|
||||
}),
|
||||
deps.eventListen(VersionEvents.Deleted, async ({ payload }) => {
|
||||
await addCommitDeletedActivity({
|
||||
commitId: payload.versionId,
|
||||
streamId: payload.projectId,
|
||||
userId: payload.userId,
|
||||
commit: payload.version,
|
||||
branchId: payload.modelId
|
||||
})
|
||||
}),
|
||||
deps.eventListen(VersionEvents.Received, async ({ payload }) => {
|
||||
await addCommitReceivedActivity({
|
||||
streamId: payload.projectId,
|
||||
commitId: payload.versionId,
|
||||
userId: payload.userId,
|
||||
sourceApplication: payload.sourceApplication,
|
||||
message: payload.message
|
||||
})
|
||||
})
|
||||
]
|
||||
|
||||
return () => {
|
||||
quitters.forEach((q) => q())
|
||||
}
|
||||
}
|
||||
@@ -29,6 +29,7 @@ import { ProjectEvents } from '@/modules/core/domain/projects/events'
|
||||
import { reportUserActivityFactory } from '@/modules/activitystream/events/userListeners'
|
||||
import { reportAccessRequestActivityFactory } from '@/modules/activitystream/events/accessRequestListeners'
|
||||
import { reportBranchActivityFactory } from '@/modules/activitystream/events/branchListeners'
|
||||
import { reportCommitActivityFactory } from '@/modules/activitystream/events/commitListeners'
|
||||
|
||||
let scheduledTask: ReturnType<ScheduleExecution> | null = null
|
||||
let quitEventListeners: Optional<() => void> = undefined
|
||||
@@ -57,11 +58,16 @@ const initializeEventListeners = ({
|
||||
eventListen: eventBus.listen,
|
||||
saveActivity
|
||||
})
|
||||
const reportCommitActivity = reportCommitActivityFactory({
|
||||
eventListen: eventBus.listen,
|
||||
saveActivity
|
||||
})
|
||||
|
||||
const quitCbs = [
|
||||
reportUserActivity(),
|
||||
reportAccessRequestActivity(),
|
||||
reportBranchActivity(),
|
||||
reportCommitActivity(),
|
||||
eventBus.listen(ServerInvitesEvents.Created, async ({ payload }) => {
|
||||
if (!isProjectResourceTarget(payload.invite.resource)) return
|
||||
await onServerInviteCreatedFactory({
|
||||
|
||||
@@ -1,214 +0,0 @@
|
||||
import { ActionTypes, ResourceTypes } from '@/modules/activitystream/helpers/types'
|
||||
import {
|
||||
CommitSubscriptions as CommitPubsubEvents,
|
||||
PublishSubscription
|
||||
} from '@/modules/shared/utils/subscriptions'
|
||||
import {
|
||||
CommitCreateInput,
|
||||
CommitUpdateInput,
|
||||
ProjectVersionsUpdatedMessageType,
|
||||
UpdateVersionInput
|
||||
} from '@/modules/core/graph/generated/graphql'
|
||||
import { CommitRecord } from '@/modules/core/helpers/types'
|
||||
import { ProjectSubscriptions } from '@/modules/shared/utils/subscriptions'
|
||||
import { has } from 'lodash'
|
||||
import {
|
||||
AddCommitCreatedActivity,
|
||||
AddCommitDeletedActivity,
|
||||
AddCommitUpdatedActivity,
|
||||
SaveActivity
|
||||
} from '@/modules/activitystream/domain/operations'
|
||||
|
||||
/**
|
||||
* Save "new commit created" activity item
|
||||
*/
|
||||
export const addCommitCreatedActivityFactory =
|
||||
({
|
||||
saveActivity,
|
||||
publish
|
||||
}: {
|
||||
saveActivity: SaveActivity
|
||||
publish: PublishSubscription
|
||||
}): AddCommitCreatedActivity =>
|
||||
async (params: {
|
||||
commitId: string
|
||||
streamId: string
|
||||
userId: string
|
||||
input: CommitCreateInput
|
||||
branchName: string
|
||||
modelId: string
|
||||
commit: CommitRecord
|
||||
}) => {
|
||||
const { commitId, input, streamId, userId, branchName, commit, modelId } = params
|
||||
await Promise.all([
|
||||
saveActivity({
|
||||
streamId,
|
||||
resourceType: ResourceTypes.Commit,
|
||||
resourceId: commitId,
|
||||
actionType: ActionTypes.Commit.Create,
|
||||
userId,
|
||||
info: {
|
||||
id: commitId,
|
||||
commit: {
|
||||
...input,
|
||||
projectId: streamId,
|
||||
modelId,
|
||||
versionId: commit.id
|
||||
}
|
||||
},
|
||||
message: `Commit created on branch ${branchName}: ${commitId} (${input.message})`
|
||||
}),
|
||||
publish(CommitPubsubEvents.CommitCreated, {
|
||||
commitCreated: { ...input, id: commitId, authorId: userId },
|
||||
streamId
|
||||
}),
|
||||
publish(ProjectSubscriptions.ProjectVersionsUpdated, {
|
||||
projectId: streamId,
|
||||
projectVersionsUpdated: {
|
||||
id: commit.id,
|
||||
version: { ...commit, streamId },
|
||||
type: ProjectVersionsUpdatedMessageType.Created,
|
||||
modelId
|
||||
}
|
||||
})
|
||||
])
|
||||
}
|
||||
|
||||
const isOldVersionUpdateInput = (
|
||||
i: CommitUpdateInput | UpdateVersionInput
|
||||
): i is CommitUpdateInput => has(i, 'streamId')
|
||||
|
||||
export const addCommitUpdatedActivityFactory =
|
||||
({
|
||||
saveActivity,
|
||||
publish
|
||||
}: {
|
||||
saveActivity: SaveActivity
|
||||
publish: PublishSubscription
|
||||
}): AddCommitUpdatedActivity =>
|
||||
async (params: {
|
||||
commitId: string
|
||||
streamId: string
|
||||
userId: string
|
||||
originalCommit: CommitRecord
|
||||
update: CommitUpdateInput | UpdateVersionInput
|
||||
newCommit: CommitRecord
|
||||
branchId: string
|
||||
}) => {
|
||||
const { commitId, streamId, userId, originalCommit, update, newCommit, branchId } =
|
||||
params
|
||||
const legacyUpdateStruct: CommitUpdateInput = isOldVersionUpdateInput(update)
|
||||
? update
|
||||
: {
|
||||
id: update.versionId,
|
||||
message: update.message,
|
||||
streamId
|
||||
}
|
||||
|
||||
await Promise.all([
|
||||
saveActivity({
|
||||
streamId,
|
||||
resourceType: ResourceTypes.Commit,
|
||||
resourceId: commitId,
|
||||
actionType: ActionTypes.Commit.Update,
|
||||
userId,
|
||||
info: { old: originalCommit, new: update },
|
||||
message: `Commit updated: ${commitId}`
|
||||
}),
|
||||
publish(CommitPubsubEvents.CommitUpdated, {
|
||||
commitUpdated: { ...legacyUpdateStruct },
|
||||
streamId,
|
||||
commitId
|
||||
}),
|
||||
publish(ProjectSubscriptions.ProjectVersionsUpdated, {
|
||||
projectId: streamId,
|
||||
projectVersionsUpdated: {
|
||||
id: commitId,
|
||||
version: { ...newCommit, streamId },
|
||||
type: ProjectVersionsUpdatedMessageType.Updated,
|
||||
modelId: branchId
|
||||
}
|
||||
})
|
||||
])
|
||||
}
|
||||
|
||||
export const addCommitMovedActivityFactory =
|
||||
({
|
||||
saveActivity,
|
||||
publish
|
||||
}: {
|
||||
saveActivity: SaveActivity
|
||||
publish: PublishSubscription
|
||||
}) =>
|
||||
async (params: {
|
||||
commitId: string
|
||||
streamId: string
|
||||
userId: string
|
||||
originalBranchId: string
|
||||
newBranchId: string
|
||||
commit: CommitRecord
|
||||
}) => {
|
||||
const { commitId, streamId, userId, originalBranchId, newBranchId, commit } = params
|
||||
await Promise.all([
|
||||
saveActivity({
|
||||
streamId,
|
||||
resourceType: ResourceTypes.Commit,
|
||||
resourceId: commitId,
|
||||
actionType: ActionTypes.Commit.Move,
|
||||
userId,
|
||||
info: { originalBranchId, newBranchId },
|
||||
message: `Commit moved: ${commitId}`
|
||||
}),
|
||||
publish(ProjectSubscriptions.ProjectVersionsUpdated, {
|
||||
projectId: streamId,
|
||||
projectVersionsUpdated: {
|
||||
id: commitId,
|
||||
version: { ...commit, streamId },
|
||||
type: ProjectVersionsUpdatedMessageType.Updated,
|
||||
modelId: newBranchId
|
||||
}
|
||||
})
|
||||
])
|
||||
}
|
||||
|
||||
export const addCommitDeletedActivityFactory =
|
||||
({
|
||||
saveActivity,
|
||||
publish
|
||||
}: {
|
||||
saveActivity: SaveActivity
|
||||
publish: PublishSubscription
|
||||
}): AddCommitDeletedActivity =>
|
||||
async (params: {
|
||||
commitId: string
|
||||
streamId: string
|
||||
userId: string
|
||||
commit: CommitRecord
|
||||
branchId: string
|
||||
}) => {
|
||||
const { commitId, streamId, userId, commit, branchId } = params
|
||||
await Promise.all([
|
||||
saveActivity({
|
||||
streamId,
|
||||
resourceType: ResourceTypes.Commit,
|
||||
resourceId: commitId,
|
||||
actionType: ActionTypes.Commit.Delete,
|
||||
userId,
|
||||
info: { commit },
|
||||
message: `Commit deleted: ${commitId}`
|
||||
}),
|
||||
publish(CommitPubsubEvents.CommitDeleted, {
|
||||
commitDeleted: { ...commit, streamId, branchId },
|
||||
streamId
|
||||
}),
|
||||
publish(ProjectSubscriptions.ProjectVersionsUpdated, {
|
||||
projectId: streamId,
|
||||
projectVersionsUpdated: {
|
||||
id: commitId,
|
||||
type: ProjectVersionsUpdatedMessageType.Deleted,
|
||||
version: null,
|
||||
modelId: branchId
|
||||
}
|
||||
})
|
||||
])
|
||||
}
|
||||
@@ -53,7 +53,6 @@ import {
|
||||
import { validateInputAttachmentsFactory } from '@/modules/comments/services/commentTextService'
|
||||
import { getBlobsFactory } from '@/modules/blobstorage/repositories'
|
||||
import { createCommitByBranchIdFactory } from '@/modules/core/services/commit/management'
|
||||
import { addCommitCreatedActivityFactory } from '@/modules/activitystream/services/commitActivity'
|
||||
import { saveActivityFactory } from '@/modules/activitystream/repositories'
|
||||
import { publish } from '@/modules/shared/utils/subscriptions'
|
||||
import { getUserFactory } from '@/modules/core/repositories/users'
|
||||
@@ -178,10 +177,7 @@ const command: CommandModule<
|
||||
markCommitStreamUpdated,
|
||||
markCommitBranchUpdated: markCommitBranchUpdatedFactory({ db: projectDb }),
|
||||
emitEvent: getEventBus().emit,
|
||||
addCommitCreatedActivity: addCommitCreatedActivityFactory({
|
||||
saveActivity: saveActivityFactory({ db: mainDb }),
|
||||
publish
|
||||
})
|
||||
publishSub: publish
|
||||
})
|
||||
|
||||
const createObject = createObjectFactory({
|
||||
|
||||
@@ -59,7 +59,6 @@ import { getBlobsFactory } from '@/modules/blobstorage/repositories'
|
||||
import { validateInputAttachmentsFactory } from '@/modules/comments/services/commentTextService'
|
||||
import { saveActivityFactory } from '@/modules/activitystream/repositories'
|
||||
import { publish } from '@/modules/shared/utils/subscriptions'
|
||||
import { addCommitCreatedActivityFactory } from '@/modules/activitystream/services/commitActivity'
|
||||
import { getUserFactory } from '@/modules/core/repositories/users'
|
||||
import { createObjectFactory } from '@/modules/core/services/objects/management'
|
||||
import { authorizeResolver } from '@/modules/shared'
|
||||
@@ -202,10 +201,7 @@ const command: CommandModule<
|
||||
markCommitStreamUpdated,
|
||||
markCommitBranchUpdated: markCommitBranchUpdatedFactory({ db: projectDb }),
|
||||
emitEvent: getEventBus().emit,
|
||||
addCommitCreatedActivity: addCommitCreatedActivityFactory({
|
||||
saveActivity: saveActivityFactory({ db: mainDb }),
|
||||
publish
|
||||
})
|
||||
publishSub: publish
|
||||
})
|
||||
|
||||
const getUser = getUserFactory({ db })
|
||||
|
||||
@@ -80,11 +80,7 @@ const {
|
||||
buildCoreInviteEmailContentsFactory
|
||||
} = require('@/modules/serverinvites/services/coreEmailContents')
|
||||
const { getEventBus } = require('@/modules/shared/services/eventBus')
|
||||
const { saveActivityFactory } = require('@/modules/activitystream/repositories')
|
||||
const { publish } = require('@/modules/shared/utils/subscriptions')
|
||||
const {
|
||||
addCommitCreatedActivityFactory
|
||||
} = require('@/modules/activitystream/services/commitActivity')
|
||||
const {
|
||||
getUsersFactory,
|
||||
getUserFactory,
|
||||
@@ -145,10 +141,7 @@ const createCommitByBranchId = createCommitByBranchIdFactory({
|
||||
markCommitStreamUpdated,
|
||||
markCommitBranchUpdated: markCommitBranchUpdatedFactory({ db }),
|
||||
emitEvent: getEventBus().emit,
|
||||
addCommitCreatedActivity: addCommitCreatedActivityFactory({
|
||||
saveActivity: saveActivityFactory({ db }),
|
||||
publish
|
||||
})
|
||||
publishSub: publish
|
||||
})
|
||||
|
||||
const createCommitByBranchName = createCommitByBranchNameFactory({
|
||||
|
||||
@@ -87,9 +87,7 @@ import {
|
||||
import { collectAndValidateCoreTargetsFactory } from '@/modules/serverinvites/services/coreResourceCollection'
|
||||
import { buildCoreInviteEmailContentsFactory } from '@/modules/serverinvites/services/coreEmailContents'
|
||||
import { getEventBus } from '@/modules/shared/services/eventBus'
|
||||
import { saveActivityFactory } from '@/modules/activitystream/repositories'
|
||||
import { publish } from '@/modules/shared/utils/subscriptions'
|
||||
import { addCommitCreatedActivityFactory } from '@/modules/activitystream/services/commitActivity'
|
||||
import {
|
||||
getUsersFactory,
|
||||
getUserFactory,
|
||||
@@ -187,10 +185,7 @@ const createCommitByBranchId = createCommitByBranchIdFactory({
|
||||
markCommitStreamUpdated,
|
||||
markCommitBranchUpdated: markCommitBranchUpdatedFactory({ db }),
|
||||
emitEvent: getEventBus().emit,
|
||||
addCommitCreatedActivity: addCommitCreatedActivityFactory({
|
||||
saveActivity: saveActivityFactory({ db }),
|
||||
publish
|
||||
})
|
||||
publishSub: publish
|
||||
})
|
||||
|
||||
const createCommitByBranchName = createCommitByBranchNameFactory({
|
||||
|
||||
@@ -1,11 +1,59 @@
|
||||
import { Version } from '@/modules/core/domain/commits/types'
|
||||
import {
|
||||
CommitCreateInput,
|
||||
CommitUpdateInput,
|
||||
UpdateVersionInput
|
||||
} from '@/modules/core/graph/generated/graphql'
|
||||
import { MaybeNullOrUndefined } from '@speckle/shared'
|
||||
|
||||
export const versionEventsNamespace = 'versions' as const
|
||||
|
||||
export const VersionEvents = {
|
||||
Created: `${versionEventsNamespace}.created`
|
||||
Created: `${versionEventsNamespace}.created`,
|
||||
Updated: `${versionEventsNamespace}.updated`,
|
||||
MovedModel: `${versionEventsNamespace}.movedModel`,
|
||||
Deleted: `${versionEventsNamespace}.deleted`,
|
||||
Received: `${versionEventsNamespace}.received`
|
||||
} as const
|
||||
|
||||
export type VersionEventsPayloads = {
|
||||
[VersionEvents.Created]: { projectId: string; modelId: string; version: Version }
|
||||
[VersionEvents.Created]: {
|
||||
projectId: string
|
||||
modelId: string
|
||||
version: Version
|
||||
userId: string
|
||||
modelName: string
|
||||
input: CommitCreateInput
|
||||
}
|
||||
[VersionEvents.Updated]: {
|
||||
projectId: string
|
||||
modelId: string
|
||||
versionId: string
|
||||
newVersion: Version
|
||||
oldVersion: Version
|
||||
userId: string
|
||||
update: CommitUpdateInput | UpdateVersionInput
|
||||
}
|
||||
[VersionEvents.MovedModel]: {
|
||||
projectId: string
|
||||
versionId: string
|
||||
userId: string
|
||||
version: Version
|
||||
originalModelId: string
|
||||
newModelId: string
|
||||
}
|
||||
[VersionEvents.Deleted]: {
|
||||
projectId: string
|
||||
versionId: string
|
||||
modelId: string
|
||||
userId: string
|
||||
version: Version
|
||||
}
|
||||
[VersionEvents.Received]: {
|
||||
projectId: string
|
||||
versionId: string
|
||||
userId: string
|
||||
sourceApplication: string
|
||||
message: MaybeNullOrUndefined<string>
|
||||
}
|
||||
}
|
||||
|
||||
@@ -70,9 +70,6 @@ export type CreateCommitByBranchId = (
|
||||
sourceApplication: Nullable<string>
|
||||
totalChildrenCount?: MaybeNullOrUndefined<number>
|
||||
parents: Nullable<string[]>
|
||||
}>,
|
||||
options?: Partial<{
|
||||
notify: boolean
|
||||
}>
|
||||
) => Promise<CommitWithStreamBranchId>
|
||||
|
||||
@@ -86,9 +83,6 @@ export type CreateCommitByBranchName = (
|
||||
sourceApplication: Nullable<string>
|
||||
totalChildrenCount?: MaybeNullOrUndefined<number>
|
||||
parents: Nullable<string[]>
|
||||
}>,
|
||||
options?: Partial<{
|
||||
notify: boolean
|
||||
}>
|
||||
) => Promise<Commit>
|
||||
|
||||
|
||||
@@ -65,15 +65,8 @@ import {
|
||||
getStreamBranchByNameFactory,
|
||||
createBranchFactory
|
||||
} from '@/modules/core/repositories/branches'
|
||||
import {
|
||||
addCommitCreatedActivityFactory,
|
||||
addCommitUpdatedActivityFactory,
|
||||
addCommitMovedActivityFactory,
|
||||
addCommitDeletedActivityFactory
|
||||
} from '@/modules/activitystream/services/commitActivity'
|
||||
import { getObjectFactory } from '@/modules/core/repositories/objects'
|
||||
import { validateStreamAccessFactory } from '@/modules/core/services/streams/access'
|
||||
import { saveActivityFactory } from '@/modules/activitystream/repositories'
|
||||
import { Resolvers } from '@/modules/core/graph/generated/graphql'
|
||||
import { CommitGraphQLReturn } from '@/modules/core/helpers/graphTypes'
|
||||
import {
|
||||
@@ -350,10 +343,7 @@ export = {
|
||||
markCommitStreamUpdated: markCommitStreamUpdatedFactory({ db: projectDb }),
|
||||
markCommitBranchUpdated: markCommitBranchUpdatedFactory({ db: projectDb }),
|
||||
emitEvent: getEventBus().emit,
|
||||
addCommitCreatedActivity: addCommitCreatedActivityFactory({
|
||||
saveActivity: saveActivityFactory({ db }),
|
||||
publish
|
||||
})
|
||||
publishSub: publish
|
||||
})
|
||||
|
||||
const createCommitByBranchName = createCommitByBranchNameFactory({
|
||||
@@ -388,10 +378,8 @@ export = {
|
||||
getCommitBranch: getCommitBranchFactory({ db: projectDb }),
|
||||
switchCommitBranch: switchCommitBranchFactory({ db: projectDb }),
|
||||
updateCommit: updateCommitFactory({ db: projectDb }),
|
||||
addCommitUpdatedActivity: addCommitUpdatedActivityFactory({
|
||||
saveActivity: saveActivityFactory({ db }),
|
||||
publish
|
||||
}),
|
||||
publishSub: publish,
|
||||
emitEvent: getEventBus().emit,
|
||||
markCommitStreamUpdated: markCommitStreamUpdatedFactory({ db: projectDb }),
|
||||
markCommitBranchUpdated: markCommitBranchUpdatedFactory({ db: projectDb })
|
||||
})
|
||||
@@ -410,7 +398,7 @@ export = {
|
||||
const projectDb = await getProjectDbClient({ projectId: args.input.streamId })
|
||||
await markCommitReceivedAndNotifyFactory({
|
||||
getCommit: getCommitFactory({ db: projectDb }),
|
||||
saveActivity: saveActivityFactory({ db })
|
||||
emitEvent: getEventBus().emit
|
||||
})({
|
||||
input: args.input,
|
||||
userId: context.userId!
|
||||
@@ -433,10 +421,8 @@ export = {
|
||||
markCommitStreamUpdated: markCommitStreamUpdatedFactory({ db: projectDb }),
|
||||
markCommitBranchUpdated: markCommitBranchUpdatedFactory({ db: projectDb }),
|
||||
deleteCommit: deleteCommitFactory({ db: projectDb }),
|
||||
addCommitDeletedActivity: addCommitDeletedActivityFactory({
|
||||
saveActivity: saveActivityFactory({ db }),
|
||||
publish
|
||||
})
|
||||
publishSub: publish,
|
||||
emitEvent: getEventBus().emit
|
||||
})
|
||||
const deleted = await deleteCommitAndNotify(
|
||||
args.commit.id,
|
||||
@@ -455,10 +441,8 @@ export = {
|
||||
getStreamBranchByName: getStreamBranchByNameFactory({ db: projectDb }),
|
||||
createBranch: createBranchFactory({ db: projectDb }),
|
||||
moveCommitsToBranch: moveCommitsToBranchFactory({ db: projectDb }),
|
||||
addCommitMovedActivity: addCommitMovedActivityFactory({
|
||||
saveActivity: saveActivityFactory({ db }),
|
||||
publish
|
||||
})
|
||||
publishSub: publish,
|
||||
emitEvent: getEventBus().emit
|
||||
})
|
||||
await batchMoveCommits(args.input, ctx.userId!)
|
||||
return true
|
||||
@@ -471,10 +455,8 @@ export = {
|
||||
getCommits: getCommitsFactory({ db: projectDb }),
|
||||
getStreams,
|
||||
deleteCommits: deleteCommitsFactory({ db: projectDb }),
|
||||
addCommitDeletedActivity: addCommitDeletedActivityFactory({
|
||||
saveActivity: saveActivityFactory({ db }),
|
||||
publish
|
||||
})
|
||||
publishSub: publish,
|
||||
emitEvent: getEventBus().emit
|
||||
})
|
||||
await batchDeleteCommits(args.input, ctx.userId!)
|
||||
return true
|
||||
|
||||
@@ -34,7 +34,6 @@ import {
|
||||
switchCommitBranchFactory,
|
||||
updateCommitFactory
|
||||
} from '@/modules/core/repositories/commits'
|
||||
import { db } from '@/db/knex'
|
||||
import {
|
||||
createBranchFactory,
|
||||
getBranchByIdFactory,
|
||||
@@ -47,14 +46,7 @@ import {
|
||||
getStreamsFactory,
|
||||
markCommitStreamUpdatedFactory
|
||||
} from '@/modules/core/repositories/streams'
|
||||
import {
|
||||
addCommitCreatedActivityFactory,
|
||||
addCommitDeletedActivityFactory,
|
||||
addCommitMovedActivityFactory,
|
||||
addCommitUpdatedActivityFactory
|
||||
} from '@/modules/activitystream/services/commitActivity'
|
||||
import { getObjectFactory } from '@/modules/core/repositories/objects'
|
||||
import { saveActivityFactory } from '@/modules/activitystream/repositories'
|
||||
import { getProjectDbClient } from '@/modules/multiregion/utils/dbSelector'
|
||||
import coreModule from '@/modules/core'
|
||||
import { getEventBus } from '@/modules/shared/services/eventBus'
|
||||
@@ -113,10 +105,8 @@ export = {
|
||||
getStreamBranchByName: getStreamBranchByNameFactory({ db: projectDb }),
|
||||
createBranch: createBranchFactory({ db: projectDb }),
|
||||
moveCommitsToBranch: moveCommitsToBranchFactory({ db: projectDb }),
|
||||
addCommitMovedActivity: addCommitMovedActivityFactory({
|
||||
saveActivity: saveActivityFactory({ db }),
|
||||
publish
|
||||
})
|
||||
publishSub: publish,
|
||||
emitEvent: getEventBus().emit
|
||||
})
|
||||
return await batchMoveCommits(args.input, ctx.userId!)
|
||||
},
|
||||
@@ -128,10 +118,8 @@ export = {
|
||||
getCommits: getCommitsFactory({ db: projectDb }),
|
||||
getStreams: getStreamsFactory({ db: projectDb }),
|
||||
deleteCommits: deleteCommitsFactory({ db: projectDb }),
|
||||
addCommitDeletedActivity: addCommitDeletedActivityFactory({
|
||||
saveActivity: saveActivityFactory({ db }),
|
||||
publish
|
||||
})
|
||||
publishSub: publish,
|
||||
emitEvent: getEventBus().emit
|
||||
})
|
||||
await batchDeleteCommits(args.input, ctx.userId!)
|
||||
return true
|
||||
@@ -161,10 +149,8 @@ export = {
|
||||
getCommitBranch: getCommitBranchFactory({ db: projectDb }),
|
||||
switchCommitBranch: switchCommitBranchFactory({ db: projectDb }),
|
||||
updateCommit: updateCommitFactory({ db: projectDb }),
|
||||
addCommitUpdatedActivity: addCommitUpdatedActivityFactory({
|
||||
saveActivity: saveActivityFactory({ db }),
|
||||
publish
|
||||
}),
|
||||
publishSub: publish,
|
||||
emitEvent: getEventBus().emit,
|
||||
markCommitStreamUpdated: markCommitStreamUpdatedFactory({ db: projectDb }),
|
||||
markCommitBranchUpdated: markCommitBranchUpdatedFactory({ db: projectDb })
|
||||
})
|
||||
@@ -198,10 +184,7 @@ export = {
|
||||
markCommitStreamUpdated: markCommitStreamUpdatedFactory({ db: projectDb }),
|
||||
markCommitBranchUpdated: markCommitBranchUpdatedFactory({ db: projectDb }),
|
||||
emitEvent: getEventBus().emit,
|
||||
addCommitCreatedActivity: addCommitCreatedActivityFactory({
|
||||
saveActivity: saveActivityFactory({ db }),
|
||||
publish
|
||||
})
|
||||
publishSub: publish
|
||||
})
|
||||
|
||||
const commit = await createCommitByBranchId({
|
||||
@@ -228,7 +211,7 @@ export = {
|
||||
|
||||
await markCommitReceivedAndNotifyFactory({
|
||||
getCommit: getCommitFactory({ db: projectDb }),
|
||||
saveActivity: saveActivityFactory({ db })
|
||||
emitEvent: getEventBus().emit
|
||||
})({
|
||||
input: args.input,
|
||||
userId: ctx.userId!
|
||||
|
||||
@@ -1,11 +1,8 @@
|
||||
import {
|
||||
AddCommitDeletedActivity,
|
||||
AddCommitMovedActivity
|
||||
} from '@/modules/activitystream/domain/operations'
|
||||
import {
|
||||
GetStreamBranchByName,
|
||||
StoreBranch
|
||||
} from '@/modules/core/domain/branches/operations'
|
||||
import { VersionEvents } from '@/modules/core/domain/commits/events'
|
||||
import {
|
||||
DeleteCommits,
|
||||
GetCommits,
|
||||
@@ -22,10 +19,17 @@ import {
|
||||
CommitsDeleteInput,
|
||||
CommitsMoveInput,
|
||||
DeleteVersionsInput,
|
||||
MoveVersionsInput
|
||||
MoveVersionsInput,
|
||||
ProjectVersionsUpdatedMessageType
|
||||
} from '@/modules/core/graph/generated/graphql'
|
||||
import { Roles } from '@/modules/core/helpers/mainConstants'
|
||||
import { CommitPubsubEvents } from '@/modules/shared'
|
||||
import { ensureError } from '@/modules/shared/helpers/errorHelper'
|
||||
import { EventBusEmit } from '@/modules/shared/services/eventBus'
|
||||
import {
|
||||
ProjectSubscriptions,
|
||||
PublishSubscription
|
||||
} from '@/modules/shared/utils/subscriptions'
|
||||
import { difference, groupBy, has, keyBy } from 'lodash'
|
||||
|
||||
type OldBatchInput = CommitsMoveInput | CommitsDeleteInput
|
||||
@@ -153,7 +157,8 @@ export const batchMoveCommitsFactory =
|
||||
deps: ValidateCommitsMoveDeps & {
|
||||
createBranch: StoreBranch
|
||||
moveCommitsToBranch: MoveCommitsToBranch
|
||||
addCommitMovedActivity: AddCommitMovedActivity
|
||||
emitEvent: EventBusEmit
|
||||
publishSub: PublishSubscription
|
||||
}
|
||||
): ValidateAndBatchMoveCommits =>
|
||||
async (params: CommitsMoveInput | MoveVersionsInput, userId: string) => {
|
||||
@@ -177,16 +182,31 @@ export const batchMoveCommitsFactory =
|
||||
|
||||
await deps.moveCommitsToBranch(commitIds, finalBranch.id)
|
||||
await Promise.all(
|
||||
commitsWithStreams.map(({ commit, stream }) =>
|
||||
deps.addCommitMovedActivity({
|
||||
commitId: commit.id,
|
||||
streamId: stream.id,
|
||||
userId,
|
||||
commit,
|
||||
originalBranchId: commit.branchId,
|
||||
newBranchId: finalBranch.id
|
||||
})
|
||||
)
|
||||
commitsWithStreams.map(async ({ commit, stream }) => {
|
||||
await Promise.all([
|
||||
deps.emitEvent({
|
||||
eventName: VersionEvents.MovedModel,
|
||||
payload: {
|
||||
versionId: commit.id,
|
||||
projectId: stream.id,
|
||||
userId,
|
||||
originalModelId: commit.branchId,
|
||||
newModelId: finalBranch.id,
|
||||
version: commit
|
||||
}
|
||||
}),
|
||||
// TODO: Move to event bus listeners
|
||||
deps.publishSub(ProjectSubscriptions.ProjectVersionsUpdated, {
|
||||
projectId: stream.id,
|
||||
projectVersionsUpdated: {
|
||||
id: commit.id,
|
||||
version: { ...commit, streamId: stream.id },
|
||||
type: ProjectVersionsUpdatedMessageType.Updated,
|
||||
modelId: finalBranch.id
|
||||
}
|
||||
})
|
||||
])
|
||||
})
|
||||
)
|
||||
return finalBranch
|
||||
} catch (e) {
|
||||
@@ -202,7 +222,8 @@ export const batchDeleteCommitsFactory =
|
||||
(
|
||||
deps: ValidateBatchBaseRulesDeps & {
|
||||
deleteCommits: DeleteCommits
|
||||
addCommitDeletedActivity: AddCommitDeletedActivity
|
||||
emitEvent: EventBusEmit
|
||||
publishSub: PublishSubscription
|
||||
}
|
||||
): ValidateAndBatchDeleteCommits =>
|
||||
async (params: CommitsDeleteInput | DeleteVersionsInput, userId: string) => {
|
||||
@@ -216,15 +237,38 @@ export const batchDeleteCommitsFactory =
|
||||
try {
|
||||
await deps.deleteCommits(commitIds)
|
||||
await Promise.all(
|
||||
commitsWithStreams.map(({ commit, stream }) =>
|
||||
deps.addCommitDeletedActivity({
|
||||
commitId: commit.id,
|
||||
streamId: stream.id,
|
||||
userId,
|
||||
commit,
|
||||
branchId: commit.branchId
|
||||
})
|
||||
)
|
||||
commitsWithStreams.map(async ({ commit, stream }) => {
|
||||
await Promise.all([
|
||||
deps.emitEvent({
|
||||
eventName: VersionEvents.Deleted,
|
||||
payload: {
|
||||
projectId: stream.id,
|
||||
modelId: commit.branchId,
|
||||
versionId: commit.id,
|
||||
userId,
|
||||
version: commit
|
||||
}
|
||||
}),
|
||||
// TODO: Move to event bus listeners
|
||||
deps.publishSub(CommitPubsubEvents.CommitDeleted, {
|
||||
commitDeleted: {
|
||||
...commit,
|
||||
streamId: stream.id,
|
||||
branchId: commit.branchId
|
||||
},
|
||||
streamId: stream.id
|
||||
}),
|
||||
deps.publishSub(ProjectSubscriptions.ProjectVersionsUpdated, {
|
||||
projectId: stream.id,
|
||||
projectVersionsUpdated: {
|
||||
id: commit.id,
|
||||
type: ProjectVersionsUpdatedMessageType.Deleted,
|
||||
version: null,
|
||||
modelId: commit.branchId
|
||||
}
|
||||
})
|
||||
])
|
||||
})
|
||||
)
|
||||
} catch (e) {
|
||||
const err = ensureError(e)
|
||||
|
||||
@@ -1,10 +1,3 @@
|
||||
import {
|
||||
AddCommitCreatedActivity,
|
||||
AddCommitDeletedActivity,
|
||||
AddCommitUpdatedActivity,
|
||||
SaveActivity
|
||||
} from '@/modules/activitystream/domain/operations'
|
||||
import { ActionTypes, ResourceTypes } from '@/modules/activitystream/helpers/types'
|
||||
import {
|
||||
GetBranchById,
|
||||
GetStreamBranchByName,
|
||||
@@ -41,15 +34,21 @@ import {
|
||||
CommitReceivedInput,
|
||||
CommitUpdateInput,
|
||||
MarkReceivedVersionInput,
|
||||
ProjectVersionsUpdatedMessageType,
|
||||
UpdateVersionInput
|
||||
} from '@/modules/core/graph/generated/graphql'
|
||||
import { BranchRecord, CommitRecord } from '@/modules/core/helpers/types'
|
||||
import { CommitPubsubEvents } from '@/modules/shared'
|
||||
import { EventBusEmit } from '@/modules/shared/services/eventBus'
|
||||
import {
|
||||
ProjectSubscriptions,
|
||||
PublishSubscription
|
||||
} from '@/modules/shared/utils/subscriptions'
|
||||
import { ensureError, Roles } from '@speckle/shared'
|
||||
import { has } from 'lodash'
|
||||
|
||||
export const markCommitReceivedAndNotifyFactory =
|
||||
({ getCommit, saveActivity }: { getCommit: GetCommit; saveActivity: SaveActivity }) =>
|
||||
({ getCommit, emitEvent }: { getCommit: GetCommit; emitEvent: EventBusEmit }) =>
|
||||
async (params: {
|
||||
input: MarkReceivedVersionInput | CommitReceivedInput
|
||||
userId: string
|
||||
@@ -75,17 +74,15 @@ export const markCommitReceivedAndNotifyFactory =
|
||||
)
|
||||
}
|
||||
|
||||
await saveActivity({
|
||||
streamId: oldInput.streamId,
|
||||
resourceType: ResourceTypes.Commit,
|
||||
resourceId: oldInput.commitId,
|
||||
actionType: ActionTypes.Commit.Receive,
|
||||
userId,
|
||||
info: {
|
||||
sourceApplication: input.sourceApplication,
|
||||
message: input.message
|
||||
},
|
||||
message: `Commit ${oldInput.commitId} was received by user ${userId}`
|
||||
await emitEvent({
|
||||
eventName: VersionEvents.Received,
|
||||
payload: {
|
||||
projectId: oldInput.streamId,
|
||||
versionId: oldInput.commitId,
|
||||
userId,
|
||||
sourceApplication: oldInput.sourceApplication,
|
||||
message: oldInput.message
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
@@ -98,10 +95,10 @@ export const createCommitByBranchIdFactory =
|
||||
insertBranchCommits: InsertBranchCommits
|
||||
markCommitStreamUpdated: MarkCommitStreamUpdated
|
||||
markCommitBranchUpdated: MarkCommitBranchUpdated
|
||||
addCommitCreatedActivity: AddCommitCreatedActivity
|
||||
emitEvent: EventBusEmit
|
||||
publishSub: PublishSubscription
|
||||
}): CreateCommitByBranchId =>
|
||||
async (params, options) => {
|
||||
async (params) => {
|
||||
const {
|
||||
streamId,
|
||||
branchId,
|
||||
@@ -111,7 +108,6 @@ export const createCommitByBranchIdFactory =
|
||||
sourceApplication,
|
||||
parents
|
||||
} = params
|
||||
const { notify = true } = options || {}
|
||||
|
||||
// If no total children count is passed in, get it from the original object
|
||||
// that this commit references.
|
||||
@@ -148,6 +144,10 @@ export const createCommitByBranchIdFactory =
|
||||
deps.insertStreamCommits([{ streamId, commitId: id }])
|
||||
])
|
||||
|
||||
const input = {
|
||||
...params,
|
||||
branchName: branch.name
|
||||
}
|
||||
await Promise.all([
|
||||
deps.markCommitStreamUpdated(id),
|
||||
deps.markCommitBranchUpdated(id),
|
||||
@@ -156,27 +156,26 @@ export const createCommitByBranchIdFactory =
|
||||
payload: {
|
||||
projectId: streamId,
|
||||
modelId: branchId,
|
||||
version: commit
|
||||
version: commit,
|
||||
input,
|
||||
modelName: branch.name,
|
||||
userId: authorId
|
||||
}
|
||||
}),
|
||||
...(notify
|
||||
? [
|
||||
deps.addCommitCreatedActivity({
|
||||
commitId: commit.id,
|
||||
streamId,
|
||||
userId: authorId,
|
||||
branchName: branch.name,
|
||||
input: {
|
||||
...commit,
|
||||
branchName: branch.name,
|
||||
objectId,
|
||||
streamId
|
||||
},
|
||||
modelId: branch.id,
|
||||
commit
|
||||
})
|
||||
]
|
||||
: [])
|
||||
// TODO: Move to event bus listeners
|
||||
deps.publishSub(CommitPubsubEvents.CommitCreated, {
|
||||
commitCreated: { ...input, id, authorId },
|
||||
streamId
|
||||
}),
|
||||
deps.publishSub(ProjectSubscriptions.ProjectVersionsUpdated, {
|
||||
projectId: streamId,
|
||||
projectVersionsUpdated: {
|
||||
id: commit.id,
|
||||
version: { ...commit, streamId },
|
||||
type: ProjectVersionsUpdatedMessageType.Created,
|
||||
modelId: branchId
|
||||
}
|
||||
})
|
||||
])
|
||||
|
||||
return { ...commit, streamId, branchId }
|
||||
@@ -188,7 +187,7 @@ export const createCommitByBranchNameFactory =
|
||||
getStreamBranchByName: GetStreamBranchByName
|
||||
getBranchById: GetBranchById
|
||||
}): CreateCommitByBranchName =>
|
||||
async (params, options) => {
|
||||
async (params) => {
|
||||
const {
|
||||
streamId,
|
||||
objectId,
|
||||
@@ -198,9 +197,6 @@ export const createCommitByBranchNameFactory =
|
||||
parents,
|
||||
totalChildrenCount
|
||||
} = params
|
||||
|
||||
const { notify = true } = options || {}
|
||||
|
||||
const branchName = params.branchName.toLowerCase()
|
||||
let myBranch = await deps.getStreamBranchByName(streamId, branchName)
|
||||
if (!myBranch) {
|
||||
@@ -215,19 +211,16 @@ export const createCommitByBranchNameFactory =
|
||||
)
|
||||
}
|
||||
|
||||
const commit = await deps.createCommitByBranchId(
|
||||
{
|
||||
streamId,
|
||||
branchId: myBranch.id,
|
||||
objectId,
|
||||
authorId,
|
||||
message,
|
||||
sourceApplication,
|
||||
totalChildrenCount,
|
||||
parents
|
||||
},
|
||||
{ notify }
|
||||
)
|
||||
const commit = await deps.createCommitByBranchId({
|
||||
streamId,
|
||||
branchId: myBranch.id,
|
||||
objectId,
|
||||
authorId,
|
||||
message,
|
||||
sourceApplication,
|
||||
totalChildrenCount,
|
||||
parents
|
||||
})
|
||||
|
||||
return commit
|
||||
}
|
||||
@@ -245,9 +238,10 @@ export const updateCommitAndNotifyFactory =
|
||||
getCommitBranch: GetCommitBranch
|
||||
switchCommitBranch: SwitchCommitBranch
|
||||
updateCommit: UpdateCommit
|
||||
addCommitUpdatedActivity: AddCommitUpdatedActivity
|
||||
markCommitStreamUpdated: MarkCommitStreamUpdated
|
||||
markCommitBranchUpdated: MarkCommitBranchUpdated
|
||||
emitEvent: EventBusEmit
|
||||
publishSub: PublishSubscription
|
||||
}): UpdateCommitAndNotify =>
|
||||
async (params: CommitUpdateInput | UpdateVersionInput, userId: string) => {
|
||||
const {
|
||||
@@ -323,19 +317,43 @@ export const updateCommitAndNotifyFactory =
|
||||
}
|
||||
|
||||
if (commit) {
|
||||
await deps.addCommitUpdatedActivity({
|
||||
commitId,
|
||||
streamId: stream.id,
|
||||
userId,
|
||||
originalCommit: commit,
|
||||
update: params,
|
||||
newCommit,
|
||||
branchId: branch!.id
|
||||
})
|
||||
|
||||
const legacyUpdateStruct: CommitUpdateInput = isOldVersionUpdateInput(params)
|
||||
? params
|
||||
: {
|
||||
id: params.versionId,
|
||||
message: params.message,
|
||||
streamId: stream.id
|
||||
}
|
||||
const [updatedBranch] = await Promise.all([
|
||||
deps.markCommitBranchUpdated(commit.id),
|
||||
deps.markCommitStreamUpdated(commit.id)
|
||||
deps.markCommitStreamUpdated(commit.id),
|
||||
deps.emitEvent({
|
||||
eventName: VersionEvents.Updated,
|
||||
payload: {
|
||||
projectId: stream.id,
|
||||
modelId: branch!.id,
|
||||
versionId: commitId,
|
||||
newVersion: newCommit,
|
||||
oldVersion: commit,
|
||||
userId,
|
||||
update: params
|
||||
}
|
||||
}),
|
||||
// TODO: Move to event bus listeners
|
||||
deps.publishSub(CommitPubsubEvents.CommitUpdated, {
|
||||
commitUpdated: { ...legacyUpdateStruct },
|
||||
streamId: stream.id,
|
||||
commitId
|
||||
}),
|
||||
deps.publishSub(ProjectSubscriptions.ProjectVersionsUpdated, {
|
||||
projectId: stream.id,
|
||||
projectVersionsUpdated: {
|
||||
id: commitId,
|
||||
version: { ...newCommit, streamId: stream.id },
|
||||
type: ProjectVersionsUpdatedMessageType.Updated,
|
||||
modelId: branch!.id
|
||||
}
|
||||
})
|
||||
])
|
||||
branch = updatedBranch
|
||||
}
|
||||
@@ -349,7 +367,8 @@ export const deleteCommitAndNotifyFactory =
|
||||
markCommitStreamUpdated: MarkCommitStreamUpdated
|
||||
markCommitBranchUpdated: MarkCommitBranchUpdated
|
||||
deleteCommit: DeleteCommit
|
||||
addCommitDeletedActivity: AddCommitDeletedActivity
|
||||
emitEvent: EventBusEmit
|
||||
publishSub: PublishSubscription
|
||||
}): DeleteCommitAndNotify =>
|
||||
async (commitId: string, streamId: string, userId: string) => {
|
||||
const commit = await deps.getCommit(commitId)
|
||||
@@ -372,13 +391,32 @@ export const deleteCommitAndNotifyFactory =
|
||||
|
||||
const isDeleted = await deps.deleteCommit(commitId)
|
||||
if (isDeleted) {
|
||||
await deps.addCommitDeletedActivity({
|
||||
commitId,
|
||||
streamId,
|
||||
userId,
|
||||
commit,
|
||||
branchId: updatedBranch.id
|
||||
})
|
||||
await Promise.all([
|
||||
deps.emitEvent({
|
||||
eventName: VersionEvents.Deleted,
|
||||
payload: {
|
||||
projectId: streamId,
|
||||
modelId: updatedBranch.id,
|
||||
versionId: commitId,
|
||||
userId,
|
||||
version: commit
|
||||
}
|
||||
}),
|
||||
// TODO: Move to event bus listeners
|
||||
deps.publishSub(CommitPubsubEvents.CommitDeleted, {
|
||||
commitDeleted: { ...commit, streamId, branchId: updatedBranch.id },
|
||||
streamId
|
||||
}),
|
||||
deps.publishSub(ProjectSubscriptions.ProjectVersionsUpdated, {
|
||||
projectId: streamId,
|
||||
projectVersionsUpdated: {
|
||||
id: commitId,
|
||||
type: ProjectVersionsUpdatedMessageType.Deleted,
|
||||
version: null,
|
||||
modelId: updatedBranch.id
|
||||
}
|
||||
})
|
||||
])
|
||||
}
|
||||
|
||||
return isDeleted
|
||||
|
||||
@@ -58,9 +58,7 @@ import {
|
||||
import { collectAndValidateCoreTargetsFactory } from '@/modules/serverinvites/services/coreResourceCollection'
|
||||
import { buildCoreInviteEmailContentsFactory } from '@/modules/serverinvites/services/coreEmailContents'
|
||||
import { getEventBus } from '@/modules/shared/services/eventBus'
|
||||
import { saveActivityFactory } from '@/modules/activitystream/repositories'
|
||||
import { publish } from '@/modules/shared/utils/subscriptions'
|
||||
import { addCommitCreatedActivityFactory } from '@/modules/activitystream/services/commitActivity'
|
||||
import {
|
||||
getUsersFactory,
|
||||
getUserFactory,
|
||||
@@ -121,10 +119,7 @@ const createCommitByBranchId = createCommitByBranchIdFactory({
|
||||
markCommitStreamUpdated,
|
||||
markCommitBranchUpdated: markCommitBranchUpdatedFactory({ db }),
|
||||
emitEvent: getEventBus().emit,
|
||||
addCommitCreatedActivity: addCommitCreatedActivityFactory({
|
||||
saveActivity: saveActivityFactory({ db }),
|
||||
publish
|
||||
})
|
||||
publishSub: publish
|
||||
})
|
||||
|
||||
const createCommitByBranchName = createCommitByBranchNameFactory({
|
||||
|
||||
@@ -39,11 +39,6 @@ import {
|
||||
createStreamFactory,
|
||||
markCommitStreamUpdatedFactory
|
||||
} from '@/modules/core/repositories/streams'
|
||||
import {
|
||||
addCommitUpdatedActivityFactory,
|
||||
addCommitDeletedActivityFactory,
|
||||
addCommitCreatedActivityFactory
|
||||
} from '@/modules/activitystream/services/commitActivity'
|
||||
import {
|
||||
getObjectFactory,
|
||||
storeSingleObjectIfNotFoundFactory,
|
||||
@@ -64,7 +59,6 @@ import {
|
||||
import { collectAndValidateCoreTargetsFactory } from '@/modules/serverinvites/services/coreResourceCollection'
|
||||
import { buildCoreInviteEmailContentsFactory } from '@/modules/serverinvites/services/coreEmailContents'
|
||||
import { getEventBus } from '@/modules/shared/services/eventBus'
|
||||
import { saveActivityFactory } from '@/modules/activitystream/repositories'
|
||||
import { publish } from '@/modules/shared/utils/subscriptions'
|
||||
import {
|
||||
getUsersFactory,
|
||||
@@ -112,10 +106,8 @@ const deleteCommitAndNotify = deleteCommitAndNotifyFactory({
|
||||
markCommitStreamUpdated,
|
||||
markCommitBranchUpdated: markCommitBranchUpdatedFactory({ db }),
|
||||
deleteCommit: deleteCommitFactory({ db }),
|
||||
addCommitDeletedActivity: addCommitDeletedActivityFactory({
|
||||
saveActivity: saveActivityFactory({ db }),
|
||||
publish
|
||||
})
|
||||
publishSub: publish,
|
||||
emitEvent: getEventBus().emit
|
||||
})
|
||||
|
||||
const getObject = getObjectFactory({ db })
|
||||
@@ -128,10 +120,7 @@ const createCommitByBranchId = createCommitByBranchIdFactory({
|
||||
markCommitStreamUpdated,
|
||||
markCommitBranchUpdated: markCommitBranchUpdatedFactory({ db }),
|
||||
emitEvent: getEventBus().emit,
|
||||
addCommitCreatedActivity: addCommitCreatedActivityFactory({
|
||||
saveActivity: saveActivityFactory({ db }),
|
||||
publish
|
||||
})
|
||||
publishSub: publish
|
||||
})
|
||||
|
||||
const createCommitByBranchName = createCommitByBranchNameFactory({
|
||||
@@ -148,10 +137,8 @@ const updateCommitAndNotify = updateCommitAndNotifyFactory({
|
||||
getCommitBranch: getCommitBranchFactory({ db }),
|
||||
switchCommitBranch: switchCommitBranchFactory({ db }),
|
||||
updateCommit: updateCommitFactory({ db }),
|
||||
addCommitUpdatedActivity: addCommitUpdatedActivityFactory({
|
||||
saveActivity: saveActivityFactory({ db }),
|
||||
publish
|
||||
}),
|
||||
publishSub: publish,
|
||||
emitEvent: getEventBus().emit,
|
||||
markCommitStreamUpdated,
|
||||
markCommitBranchUpdated: markCommitBranchUpdatedFactory({ db })
|
||||
})
|
||||
|
||||
@@ -1,10 +1,6 @@
|
||||
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||
import { db } from '@/db/knex'
|
||||
import { saveActivityFactory } from '@/modules/activitystream/repositories'
|
||||
import {
|
||||
addCommitDeletedActivityFactory,
|
||||
addCommitUpdatedActivityFactory
|
||||
} from '@/modules/activitystream/services/commitActivity'
|
||||
import {
|
||||
addStreamDeletedActivityFactory,
|
||||
addStreamInviteAcceptedActivityFactory,
|
||||
@@ -185,10 +181,8 @@ const buildDeleteVersion = async (params: { projectId: string }) => {
|
||||
getCommits: getCommitsFactory({ db: projectDb }),
|
||||
getStreams: getStreamsFactory({ db: projectDb }),
|
||||
deleteCommits: deleteCommitsFactory({ db: projectDb }),
|
||||
addCommitDeletedActivity: addCommitDeletedActivityFactory({
|
||||
saveActivity: saveActivityFactory({ db }),
|
||||
publish
|
||||
})
|
||||
publishSub: publish,
|
||||
emitEvent: getEventBus().emit
|
||||
})
|
||||
return batchDeleteCommits
|
||||
}
|
||||
@@ -204,10 +198,8 @@ const buildUpdateVersion = async (params: { projectId: string }) => {
|
||||
getCommitBranch: getCommitBranchFactory({ db: projectDb }),
|
||||
switchCommitBranch: switchCommitBranchFactory({ db: projectDb }),
|
||||
updateCommit: updateCommitFactory({ db: projectDb }),
|
||||
addCommitUpdatedActivity: addCommitUpdatedActivityFactory({
|
||||
saveActivity: saveActivityFactory({ db }),
|
||||
publish
|
||||
}),
|
||||
publishSub: publish,
|
||||
emitEvent: getEventBus().emit,
|
||||
markCommitStreamUpdated: markCommitStreamUpdatedFactory({ db: projectDb }),
|
||||
markCommitBranchUpdated: markCommitBranchUpdatedFactory({ db: projectDb })
|
||||
})
|
||||
|
||||
@@ -59,7 +59,6 @@ import {
|
||||
insertBranchCommitsFactory,
|
||||
insertStreamCommitsFactory
|
||||
} from '@/modules/core/repositories/commits'
|
||||
import { addCommitCreatedActivityFactory } from '@/modules/activitystream/services/commitActivity'
|
||||
import {
|
||||
getObjectFactory,
|
||||
storeClosuresIfNotFoundFactory,
|
||||
@@ -127,10 +126,7 @@ const createCommitByBranchId = createCommitByBranchIdFactory({
|
||||
markCommitStreamUpdated,
|
||||
markCommitBranchUpdated: markCommitBranchUpdatedFactory({ db }),
|
||||
emitEvent: getEventBus().emit,
|
||||
addCommitCreatedActivity: addCommitCreatedActivityFactory({
|
||||
saveActivity: saveActivityFactory({ db }),
|
||||
publish
|
||||
})
|
||||
publishSub: publish
|
||||
})
|
||||
|
||||
const createCommitByBranchName = createCommitByBranchNameFactory({
|
||||
|
||||
@@ -60,9 +60,7 @@ import {
|
||||
import { collectAndValidateCoreTargetsFactory } from '@/modules/serverinvites/services/coreResourceCollection'
|
||||
import { buildCoreInviteEmailContentsFactory } from '@/modules/serverinvites/services/coreEmailContents'
|
||||
import { getEventBus } from '@/modules/shared/services/eventBus'
|
||||
import { saveActivityFactory } from '@/modules/activitystream/repositories'
|
||||
import { publish } from '@/modules/shared/utils/subscriptions'
|
||||
import { addCommitCreatedActivityFactory } from '@/modules/activitystream/services/commitActivity'
|
||||
import {
|
||||
getUsersFactory,
|
||||
getUserFactory,
|
||||
@@ -137,10 +135,7 @@ const createCommitByBranchId = createCommitByBranchIdFactory({
|
||||
markCommitStreamUpdated,
|
||||
markCommitBranchUpdated: markCommitBranchUpdatedFactory({ db }),
|
||||
emitEvent: getEventBus().emit,
|
||||
addCommitCreatedActivity: addCommitCreatedActivityFactory({
|
||||
saveActivity: saveActivityFactory({ db }),
|
||||
publish
|
||||
})
|
||||
publishSub: publish
|
||||
})
|
||||
|
||||
const createCommitByBranchName = createCommitByBranchNameFactory({
|
||||
|
||||
@@ -5,7 +5,6 @@ import {
|
||||
addCommentCreatedActivityFactory,
|
||||
addReplyAddedActivityFactory
|
||||
} from '@/modules/activitystream/services/commentActivity'
|
||||
import { addCommitCreatedActivityFactory } from '@/modules/activitystream/services/commitActivity'
|
||||
import { getBlobsFactory } from '@/modules/blobstorage/repositories'
|
||||
import {
|
||||
getCommentFactory,
|
||||
@@ -154,10 +153,7 @@ const crossServerSyncModule: SpeckleModule = {
|
||||
markCommitStreamUpdated,
|
||||
markCommitBranchUpdated: markCommitBranchUpdatedFactory({ db }),
|
||||
emitEvent: getEventBus().emit,
|
||||
addCommitCreatedActivity: addCommitCreatedActivityFactory({
|
||||
saveActivity: saveActivityFactory({ db }),
|
||||
publish
|
||||
})
|
||||
publishSub: publish
|
||||
})
|
||||
|
||||
const createObject = createObjectFactory({
|
||||
|
||||
@@ -473,19 +473,16 @@ const saveNewCommitFactory =
|
||||
const sourceApplication = commit.sourceApplication || null
|
||||
const totalChildrenCount = commit.totalChildrenCount
|
||||
|
||||
const newCommit = await deps.createCommitByBranchId(
|
||||
{
|
||||
streamId,
|
||||
branchId: targetBranch.id,
|
||||
objectId,
|
||||
authorId: owner.id,
|
||||
message,
|
||||
sourceApplication,
|
||||
totalChildrenCount,
|
||||
parents: parents.length ? parents : null
|
||||
},
|
||||
{ notify: true }
|
||||
)
|
||||
const newCommit = await deps.createCommitByBranchId({
|
||||
streamId,
|
||||
branchId: targetBranch.id,
|
||||
objectId,
|
||||
authorId: owner.id,
|
||||
message,
|
||||
sourceApplication,
|
||||
totalChildrenCount,
|
||||
parents: parents.length ? parents : null
|
||||
})
|
||||
const id = newCommit.id
|
||||
|
||||
return id
|
||||
|
||||
@@ -50,9 +50,7 @@ import {
|
||||
import { collectAndValidateCoreTargetsFactory } from '@/modules/serverinvites/services/coreResourceCollection'
|
||||
import { buildCoreInviteEmailContentsFactory } from '@/modules/serverinvites/services/coreEmailContents'
|
||||
import { getEventBus } from '@/modules/shared/services/eventBus'
|
||||
import { saveActivityFactory } from '@/modules/activitystream/repositories'
|
||||
import { publish } from '@/modules/shared/utils/subscriptions'
|
||||
import { addCommitCreatedActivityFactory } from '@/modules/activitystream/services/commitActivity'
|
||||
import {
|
||||
countAdminUsersFactory,
|
||||
getUserFactory,
|
||||
@@ -95,10 +93,7 @@ const createCommitByBranchId = createCommitByBranchIdFactory({
|
||||
markCommitStreamUpdated,
|
||||
markCommitBranchUpdated: markCommitBranchUpdatedFactory({ db }),
|
||||
emitEvent: getEventBus().emit,
|
||||
addCommitCreatedActivity: addCommitCreatedActivityFactory({
|
||||
saveActivity: saveActivityFactory({ db }),
|
||||
publish
|
||||
})
|
||||
publishSub: publish
|
||||
})
|
||||
|
||||
const createCommitByBranchName = createCommitByBranchNameFactory({
|
||||
|
||||
@@ -1,6 +1,3 @@
|
||||
import { db } from '@/db/knex'
|
||||
import { saveActivityFactory } from '@/modules/activitystream/repositories'
|
||||
import { addCommitCreatedActivityFactory } from '@/modules/activitystream/services/commitActivity'
|
||||
import {
|
||||
getBranchByIdFactory,
|
||||
getStreamBranchByNameFactory,
|
||||
@@ -127,10 +124,7 @@ export async function createTestCommits(
|
||||
markCommitStreamUpdated,
|
||||
markCommitBranchUpdated: markCommitBranchUpdatedFactory({ db: projectDb }),
|
||||
emitEvent: getEventBus().emit,
|
||||
addCommitCreatedActivity: addCommitCreatedActivityFactory({
|
||||
saveActivity: saveActivityFactory({ db }),
|
||||
publish
|
||||
})
|
||||
publishSub: publish
|
||||
})
|
||||
|
||||
const createCommitByBranchName = createCommitByBranchNameFactory({
|
||||
|
||||
Reference in New Issue
Block a user