diff --git a/apiserver/plane/app/views/module/issue.py b/apiserver/plane/app/views/module/issue.py index 3e79e7ec7..879ab7e47 100644 --- a/apiserver/plane/app/views/module/issue.py +++ b/apiserver/plane/app/views/module/issue.py @@ -198,46 +198,66 @@ class ModuleIssueViewSet(BaseViewSet): ] return Response({"message": "success"}, status=status.HTTP_201_CREATED) - # create multiple module inside an issue + # add multiple module inside an issue and remove multiple modules from an issue def create_issue_modules(self, request, slug, project_id, issue_id): modules = request.data.get("modules", []) - if not modules: - return Response( - {"error": "Modules are required"}, - status=status.HTTP_400_BAD_REQUEST, - ) - + removed_modules = request.data.get("removed_modules", []) project = Project.objects.get(pk=project_id) - _ = ModuleIssue.objects.bulk_create( - [ - ModuleIssue( + + + if modules: + _ = ModuleIssue.objects.bulk_create( + [ + ModuleIssue( + issue_id=issue_id, + module_id=module, + project_id=project_id, + workspace_id=project.workspace_id, + created_by=request.user, + updated_by=request.user, + ) + for module in modules + ], + batch_size=10, + ignore_conflicts=True, + ) + # Bulk Update the activity + _ = [ + issue_activity.delay( + type="module.activity.created", + requested_data=json.dumps({"module_id": module}), + actor_id=str(request.user.id), issue_id=issue_id, - module_id=module, project_id=project_id, - workspace_id=project.workspace_id, - created_by=request.user, - updated_by=request.user, + current_instance=None, + epoch=int(timezone.now().timestamp()), + notification=True, + origin=request.META.get("HTTP_ORIGIN"), ) for module in modules - ], - batch_size=10, - ignore_conflicts=True, - ) - # Bulk Update the activity - _ = [ - issue_activity.delay( - type="module.activity.created", - requested_data=json.dumps({"module_id": module}), - actor_id=str(request.user.id), - issue_id=issue_id, + ] + + for module_id in removed_modules: + module_issue = ModuleIssue.objects.get( + workspace__slug=slug, project_id=project_id, - current_instance=None, + module_id=module_id, + issue_id=issue_id, + ) + issue_activity.delay( + type="module.activity.deleted", + requested_data=json.dumps({"module_id": str(module_id)}), + actor_id=str(request.user.id), + issue_id=str(issue_id), + project_id=str(project_id), + current_instance=json.dumps( + {"module_name": module_issue.module.name} + ), epoch=int(timezone.now().timestamp()), notification=True, origin=request.META.get("HTTP_ORIGIN"), ) - for module in modules - ] + module_issue.delete() return Response({"message": "success"}, status=status.HTTP_201_CREATED) diff --git a/web/services/module.service.ts b/web/services/module.service.ts index ec330cf95..eb5758873 100644 --- a/web/services/module.service.ts +++ b/web/services/module.service.ts @@ -97,7 +97,7 @@ export class ModuleService extends APIService { workspaceSlug: string, projectId: string, issueId: string, - data: { modules: string[] } + data: { modules: string[]; removed_modules?: string[] } ): Promise { return this.post(`/api/workspaces/${workspaceSlug}/projects/${projectId}/issues/${issueId}/modules/`, data) .then((response) => response?.data) diff --git a/web/store/issue/module/issue.store.ts b/web/store/issue/module/issue.store.ts index 35066a052..8a04d90b8 100644 --- a/web/store/issue/module/issue.store.ts +++ b/web/store/issue/module/issue.store.ts @@ -431,15 +431,11 @@ export class ModuleIssues extends IssueHelperStore implements IModuleIssues { this.rootStore.issues.updateIssue(issueId, { module_ids: uniq(currentModuleIds) }); } - //Perform API calls - if (!isEmpty(addModuleIds)) { - await this.moduleService.addModulesToIssue(workspaceSlug, projectId, issueId, { - modules: addModuleIds, - }); - } - if (!isEmpty(removeModuleIds)) { - await this.moduleService.removeModulesFromIssueBulk(workspaceSlug, projectId, issueId, removeModuleIds); - } + //Perform API call + await this.moduleService.addModulesToIssue(workspaceSlug, projectId, issueId, { + modules: addModuleIds, + removed_modules: removeModuleIds, + }); } catch (error) { // revert the issue back to its original module ids set(this.rootStore.issues.issuesMap, [issueId, "module_ids"], originalModuleIds);