-
Notifications
You must be signed in to change notification settings - Fork 2
Full Delete Course #479
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
Open
frasermuller
wants to merge
3
commits into
main
Choose a base branch
from
fraser/full-delete-course
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Full Delete Course #479
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
60 changes: 60 additions & 0 deletions
60
packages/frontend/app/(dashboard)/components/DeleteCourse.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| import { API } from '@/app/api' | ||
| import { getErrorMessage } from '@/app/utils/generalUtils' | ||
| import { | ||
| GetOrganizationResponse, | ||
| OrganizationCourseResponse, | ||
| } from '@koh/common' | ||
| import { Button, message, Popconfirm } from 'antd' | ||
| import { useRouter } from 'next/navigation' | ||
|
|
||
| type DeleteCourseProps = { | ||
| courseData: OrganizationCourseResponse | ||
| organization: GetOrganizationResponse | ||
| } | ||
|
|
||
| const DeleteCourse: React.FC<DeleteCourseProps> = ({ | ||
| courseData, | ||
| organization, | ||
| }) => { | ||
| const router = useRouter() | ||
|
|
||
| const handleDelete = async () => { | ||
| await API.organizations | ||
| .deleteCourse(organization.id, Number(courseData.courseId)) | ||
| .then(() => { | ||
| message.success('Course deleted') | ||
| router.push('/courses') | ||
| }) | ||
| .catch((error) => { | ||
| const errorMessage = getErrorMessage(error) | ||
| message.error(errorMessage) | ||
| }) | ||
| } | ||
|
|
||
| return ( | ||
| <div className="flex flex-col items-center md:flex-row"> | ||
| <div className="mb-2 w-full md:mr-4 md:w-5/6 md:text-left"> | ||
| <strong className="text-red-600">Permanently Delete Course</strong> | ||
| <div className="mb-0"> | ||
| This will permanently delete the course and all associated data | ||
| (queues, questions, chatbot data, etc). This cannot be undone. Only | ||
| use this if you accidentally created the course. | ||
| </div> | ||
| </div> | ||
| <Popconfirm | ||
| title="Are you sure you want to permanently delete this course?" | ||
| description="This action cannot be undone." | ||
| onConfirm={handleDelete} | ||
| okText="Yes, Delete" | ||
| cancelText="Cancel" | ||
| okButtonProps={{ danger: true }} | ||
| > | ||
| <Button danger type="primary" className="w-full md:w-auto"> | ||
| Delete Course | ||
| </Button> | ||
| </Popconfirm> | ||
| </div> | ||
| ) | ||
| } | ||
|
|
||
| export default DeleteCourse | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
160 changes: 160 additions & 0 deletions
160
packages/server/migration/1769000000000-add-course-delete-cascade.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,160 @@ | ||
| import { MigrationInterface, QueryRunner } from 'typeorm'; | ||
|
|
||
| export class AddCourseDeleteCascade1769000000000 implements MigrationInterface { | ||
| public async up(queryRunner: QueryRunner): Promise<void> { | ||
| //chaging all connected tables to course_model with ON DELETE NO ACTION to ON DELETE CASCADE so that when a course is deleted, all related records in these tables will also get deleted. | ||
|
|
||
| // alert_model | ||
| await queryRunner.query( | ||
| `ALTER TABLE "alert_model" DROP CONSTRAINT "FK_71566c4e2836bea0d62bb7b4db2"`, | ||
| ); | ||
| await queryRunner.query( | ||
| `ALTER TABLE "alert_model" ADD CONSTRAINT "FK_71566c4e2836bea0d62bb7b4db2" FOREIGN KEY ("courseId") REFERENCES "course_model"("id") ON DELETE CASCADE`, | ||
| ); | ||
|
|
||
| // async_question_model | ||
| await queryRunner.query( | ||
| `ALTER TABLE "async_question_model" DROP CONSTRAINT "FK_faac87edafc4297437ed4a12d0e"`, | ||
| ); | ||
| await queryRunner.query( | ||
| `ALTER TABLE "async_question_model" ADD CONSTRAINT "FK_faac87edafc4297437ed4a12d0e" FOREIGN KEY ("courseId") REFERENCES "course_model"("id") ON DELETE CASCADE`, | ||
| ); | ||
|
|
||
| // calendar_model | ||
| await queryRunner.query( | ||
| `ALTER TABLE "calendar_model" DROP CONSTRAINT "FK_b47c12b782d3e463acdf841bbf7"`, | ||
| ); | ||
| await queryRunner.query( | ||
| `ALTER TABLE "calendar_model" ADD CONSTRAINT "FK_b47c12b782d3e463acdf841bbf7" FOREIGN KEY ("course") REFERENCES "course_model"("id") ON DELETE CASCADE`, | ||
| ); | ||
|
|
||
| // chatbot_interactions_model | ||
| await queryRunner.query( | ||
| `ALTER TABLE "chatbot_interactions_model" DROP CONSTRAINT "FK_7df3546203b677c555f27974c25"`, | ||
| ); | ||
| await queryRunner.query( | ||
| `ALTER TABLE "chatbot_interactions_model" ADD CONSTRAINT "FK_7df3546203b677c555f27974c25" FOREIGN KEY ("course") REFERENCES "course_model"("id") ON DELETE CASCADE`, | ||
| ); | ||
|
|
||
| // course_chatbot_settings_model | ||
| await queryRunner.query( | ||
| `ALTER TABLE "course_chatbot_settings_model" DROP CONSTRAINT "FK_47403ceb85db02238d9c63bd73f"`, | ||
| ); | ||
| await queryRunner.query( | ||
| `ALTER TABLE "course_chatbot_settings_model" ADD CONSTRAINT "FK_47403ceb85db02238d9c63bd73f" FOREIGN KEY ("courseId") REFERENCES "course_model"("id") ON DELETE CASCADE`, | ||
| ); | ||
|
|
||
| // event_model | ||
| await queryRunner.query( | ||
| `ALTER TABLE "event_model" DROP CONSTRAINT "FK_4b2c20ac04a24393fff2d974024"`, | ||
| ); | ||
| await queryRunner.query( | ||
| `ALTER TABLE "event_model" ADD CONSTRAINT "FK_4b2c20ac04a24393fff2d974024" FOREIGN KEY ("courseId") REFERENCES "course_model"("id") ON DELETE CASCADE`, | ||
| ); | ||
|
|
||
| // lms_course_integration_model | ||
| await queryRunner.query( | ||
| `ALTER TABLE "lms_course_integration_model" DROP CONSTRAINT "FK_594c79fce72d04560c3a4465ea6"`, | ||
| ); | ||
| await queryRunner.query( | ||
| `ALTER TABLE "lms_course_integration_model" ADD CONSTRAINT "FK_594c79fce72d04560c3a4465ea6" FOREIGN KEY ("courseId") REFERENCES "course_model"("id") ON DELETE CASCADE`, | ||
| ); | ||
|
|
||
| // organization_course_model | ||
| await queryRunner.query( | ||
| `ALTER TABLE "organization_course_model" DROP CONSTRAINT "FK_4fef22be04e7b58e8728a24b207"`, | ||
| ); | ||
| await queryRunner.query( | ||
| `ALTER TABLE "organization_course_model" ADD CONSTRAINT "FK_4fef22be04e7b58e8728a24b207" FOREIGN KEY ("courseId") REFERENCES "course_model"("id") ON DELETE CASCADE`, | ||
| ); | ||
|
|
||
| // queue_model | ||
| await queryRunner.query( | ||
| `ALTER TABLE "queue_model" DROP CONSTRAINT "FK_a35e40a16b61a6e191ad097ccdc"`, | ||
| ); | ||
| await queryRunner.query( | ||
| `ALTER TABLE "queue_model" ADD CONSTRAINT "FK_a35e40a16b61a6e191ad097ccdc" FOREIGN KEY ("courseId") REFERENCES "course_model"("id") ON DELETE CASCADE`, | ||
| ); | ||
|
|
||
| // user_course_model | ||
| await queryRunner.query( | ||
| `ALTER TABLE "user_course_model" DROP CONSTRAINT "FK_3f38d8a85115b61789f02fc5c3b"`, | ||
| ); | ||
| await queryRunner.query( | ||
| `ALTER TABLE "user_course_model" ADD CONSTRAINT "FK_3f38d8a85115b61789f02fc5c3b" FOREIGN KEY ("courseId") REFERENCES "course_model"("id") ON DELETE CASCADE`, | ||
| ); | ||
| } | ||
|
|
||
| public async down(queryRunner: QueryRunner): Promise<void> { | ||
| // undo all changes (back to NO ACTION) | ||
| await queryRunner.query( | ||
| `ALTER TABLE "alert_model" DROP CONSTRAINT "FK_71566c4e2836bea0d62bb7b4db2"`, | ||
| ); | ||
| await queryRunner.query( | ||
| `ALTER TABLE "alert_model" ADD CONSTRAINT "FK_71566c4e2836bea0d62bb7b4db2" FOREIGN KEY ("courseId") REFERENCES "course_model"("id") ON DELETE NO ACTION`, | ||
| ); | ||
|
|
||
| await queryRunner.query( | ||
| `ALTER TABLE "async_question_model" DROP CONSTRAINT "FK_faac87edafc4297437ed4a12d0e"`, | ||
| ); | ||
| await queryRunner.query( | ||
| `ALTER TABLE "async_question_model" ADD CONSTRAINT "FK_faac87edafc4297437ed4a12d0e" FOREIGN KEY ("courseId") REFERENCES "course_model"("id") ON DELETE NO ACTION`, | ||
| ); | ||
|
|
||
| await queryRunner.query( | ||
| `ALTER TABLE "calendar_model" DROP CONSTRAINT "FK_b47c12b782d3e463acdf841bbf7"`, | ||
| ); | ||
| await queryRunner.query( | ||
| `ALTER TABLE "calendar_model" ADD CONSTRAINT "FK_b47c12b782d3e463acdf841bbf7" FOREIGN KEY ("course") REFERENCES "course_model"("id") ON DELETE NO ACTION`, | ||
| ); | ||
|
|
||
| await queryRunner.query( | ||
| `ALTER TABLE "chatbot_interactions_model" DROP CONSTRAINT "FK_7df3546203b677c555f27974c25"`, | ||
| ); | ||
| await queryRunner.query( | ||
| `ALTER TABLE "chatbot_interactions_model" ADD CONSTRAINT "FK_7df3546203b677c555f27974c25" FOREIGN KEY ("course") REFERENCES "course_model"("id") ON DELETE NO ACTION`, | ||
| ); | ||
|
|
||
| await queryRunner.query( | ||
| `ALTER TABLE "course_chatbot_settings_model" DROP CONSTRAINT "FK_47403ceb85db02238d9c63bd73f"`, | ||
| ); | ||
| await queryRunner.query( | ||
| `ALTER TABLE "course_chatbot_settings_model" ADD CONSTRAINT "FK_47403ceb85db02238d9c63bd73f" FOREIGN KEY ("courseId") REFERENCES "course_model"("id") ON DELETE NO ACTION`, | ||
| ); | ||
|
|
||
| await queryRunner.query( | ||
| `ALTER TABLE "event_model" DROP CONSTRAINT "FK_4b2c20ac04a24393fff2d974024"`, | ||
| ); | ||
| await queryRunner.query( | ||
| `ALTER TABLE "event_model" ADD CONSTRAINT "FK_4b2c20ac04a24393fff2d974024" FOREIGN KEY ("courseId") REFERENCES "course_model"("id") ON DELETE NO ACTION`, | ||
| ); | ||
|
|
||
| await queryRunner.query( | ||
| `ALTER TABLE "lms_course_integration_model" DROP CONSTRAINT "FK_594c79fce72d04560c3a4465ea6"`, | ||
| ); | ||
| await queryRunner.query( | ||
| `ALTER TABLE "lms_course_integration_model" ADD CONSTRAINT "FK_594c79fce72d04560c3a4465ea6" FOREIGN KEY ("courseId") REFERENCES "course_model"("id") ON DELETE NO ACTION`, | ||
| ); | ||
|
|
||
| await queryRunner.query( | ||
| `ALTER TABLE "organization_course_model" DROP CONSTRAINT "FK_4fef22be04e7b58e8728a24b207"`, | ||
| ); | ||
| await queryRunner.query( | ||
| `ALTER TABLE "organization_course_model" ADD CONSTRAINT "FK_4fef22be04e7b58e8728a24b207" FOREIGN KEY ("courseId") REFERENCES "course_model"("id") ON DELETE NO ACTION`, | ||
| ); | ||
|
|
||
| await queryRunner.query( | ||
| `ALTER TABLE "queue_model" DROP CONSTRAINT "FK_a35e40a16b61a6e191ad097ccdc"`, | ||
| ); | ||
| await queryRunner.query( | ||
| `ALTER TABLE "queue_model" ADD CONSTRAINT "FK_a35e40a16b61a6e191ad097ccdc" FOREIGN KEY ("courseId") REFERENCES "course_model"("id") ON DELETE NO ACTION`, | ||
| ); | ||
|
|
||
| await queryRunner.query( | ||
| `ALTER TABLE "user_course_model" DROP CONSTRAINT "FK_3f38d8a85115b61789f02fc5c3b"`, | ||
| ); | ||
| await queryRunner.query( | ||
| `ALTER TABLE "user_course_model" ADD CONSTRAINT "FK_3f38d8a85115b61789f02fc5c3b" FOREIGN KEY ("courseId") REFERENCES "course_model"("id") ON DELETE NO ACTION`, | ||
| ); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -641,6 +641,30 @@ export class OrganizationController { | |
| }); | ||
| } | ||
|
|
||
| // For permanently deleting a course | ||
| @Delete(':oid/delete_course/:cid') | ||
| @UseGuards(JwtAuthGuard, OrganizationRolesGuard, EmailVerifiedGuard) | ||
| @OrgRoles(OrganizationRole.ADMIN) | ||
| async deleteCourse( | ||
|
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. in this instance, I would probably want to add some tests for this. Stuff like
|
||
| @Res() res: Response, | ||
| @Param('oid', ParseIntPipe) oid: number, | ||
| @Param('cid', ParseIntPipe) cid: number, | ||
| ): Promise<Response<void>> { | ||
| const course = await CourseModel.findOne({ where: { id: cid } }); | ||
|
|
||
| if (!course) { | ||
| return res.status(HttpStatus.NOT_FOUND).send({ | ||
| message: ERROR_MESSAGES.courseController.courseNotFound, | ||
| }); | ||
| } | ||
|
|
||
| await course.remove(); | ||
|
|
||
| return res.status(HttpStatus.OK).send({ | ||
| message: 'Course deleted successfully', | ||
| }); | ||
| } | ||
|
|
||
| @Get(':oid/get_course/:cid') | ||
| @UseGuards(JwtAuthGuard, EmailVerifiedGuard, OrgOrCourseRolesGuard) | ||
| @CourseRoles(Role.PROFESSOR, Role.TA) | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
if we wanted to get really fancy with it we could have them re-type out the name of the course or something, but meh