-
Notifications
You must be signed in to change notification settings - Fork 0
Ncto 179 HUB add forking of project #20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -74,3 +74,4 @@ yarn.lock | |
| # Project specific | ||
| config.json | ||
| config/webrtc.json | ||
| generated_client/* | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| -- AlterTable | ||
| ALTER TABLE "Project" ADD COLUMN "forked_from_id" INTEGER; | ||
|
|
||
| -- AddForeignKey | ||
| ALTER TABLE "Project" ADD CONSTRAINT "Project_forked_from_id_fkey" FOREIGN KEY ("forked_from_id") REFERENCES "Project"("id") ON DELETE SET NULL ON UPDATE CASCADE; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -487,4 +487,77 @@ export class ProjectService { | |
| } | ||
| }); | ||
| } | ||
|
|
||
| async fork(sourceProjectId: number, userId: number): Promise<ProjectEx> { | ||
| const sourceProject = await this.prisma.project.findUnique({ | ||
| where: { id: sourceProjectId } | ||
| }); | ||
|
|
||
| if (!sourceProject) { | ||
| throw new NotFoundException( | ||
| `Project with ID ${sourceProjectId} not found` | ||
| ); | ||
| } | ||
|
|
||
| if (sourceProject.status !== "COMPLETED") { | ||
| throw new BadRequestException( | ||
| "Only published projects can be forked" | ||
| ); | ||
| } | ||
|
Comment on lines
+491
to
+506
|
||
|
|
||
| const user = await this.prisma.user.findUnique({ | ||
| where: { id: userId } | ||
| }); | ||
|
|
||
| if (!user) { | ||
| throw new NotFoundException(`User with ID ${userId} not found`); | ||
| } | ||
|
Comment on lines
+508
to
+514
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Whose userId is this ?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. True, doesn't make sense. Please do the necessary changes |
||
|
|
||
| const newProject = await this.prisma.project.create({ | ||
| data: { | ||
| name: `Fork of ${sourceProject.name}`, | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What would happen if someone forks a project that was already forked ? Would it be named "Fork of Fork of |
||
| shortDesc: sourceProject.shortDesc, | ||
| longDesc: sourceProject.longDesc, | ||
| forkedFrom: { connect: { id: sourceProjectId } }, | ||
| creator: { connect: { id: userId } }, | ||
| collaborators: { connect: [{ id: userId }] } | ||
| }, | ||
|
Comment on lines
+516
to
+524
|
||
| include: { | ||
| collaborators: { | ||
| select: ProjectService.COLLABORATOR_SELECT | ||
| }, | ||
| creator: { | ||
| select: ProjectService.CREATOR_SELECT | ||
| } | ||
| } | ||
| }) as ProjectEx; | ||
|
|
||
| // Copy the release content as the first save for the forked project | ||
| const releaseContent = await this.s3Service.downloadFile({ | ||
| key: `release/${sourceProjectId}` | ||
| }); | ||
| await this.s3Service.uploadFile({ | ||
| file: releaseContent, | ||
| keyName: `save/${newProject.id}/${Date.now()}` | ||
| }); | ||
|
|
||
| // Copy project image if it exists | ||
| try { | ||
| const imageKey = `projects/${sourceProjectId}/image`; | ||
| const imageExists = await this.s3Service.fileExists(imageKey); | ||
| if (imageExists) { | ||
| const imageFile = await this.s3Service.downloadFile({ key: imageKey }); | ||
| const newImageKey = `projects/${newProject.id}/image`; | ||
| await this.s3Service.uploadFile({ | ||
| file: imageFile, | ||
| keyName: newImageKey | ||
| }); | ||
| await this.s3Service.setObjectPublicRead(newImageKey); | ||
| } | ||
| } catch { | ||
| // Image copy failure is non-critical | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't really like this: In which case would this happen? catching and doing nothing hides nasty bugs, so please avoid doing this |
||
| } | ||
|
Comment on lines
+545
to
+559
|
||
|
|
||
| return newProject; | ||
| } | ||
| } | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please remove this file from this PR, this will make my merge easier on my end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this a list of projects that forked from this one?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no it's a list of project that forked the current project