From 6b0d8891f1d368358b6bfc72fd98ced673265a11 Mon Sep 17 00:00:00 2001 From: NRayya <82588017+NRayya@users.noreply.github.com> Date: Fri, 1 Nov 2024 21:44:58 +0100 Subject: [PATCH 1/2] feat: add new samples to public projects fixes #1167 --- app/Http/Controllers/ProjectController.php | 22 ++- app/Http/Controllers/UserController.php | 28 ++++ app/Jobs/ProcessSubmission.php | 29 +++- resources/js/Pages/Publish.vue | 30 ++++ resources/js/Shared/ManageProject.vue | 154 +++++++++++++++++++++ resources/js/Shared/SelectRich.vue | 4 +- routes/web.php | 2 + 7 files changed, 258 insertions(+), 11 deletions(-) create mode 100644 app/Http/Controllers/UserController.php create mode 100644 resources/js/Shared/ManageProject.vue diff --git a/app/Http/Controllers/ProjectController.php b/app/Http/Controllers/ProjectController.php index b8267610..090da985 100644 --- a/app/Http/Controllers/ProjectController.php +++ b/app/Http/Controllers/ProjectController.php @@ -274,7 +274,7 @@ public function validation(Request $request, Project $project) $validation = $project->validation; if (! $validation) { - $validation = new Validation(); + $validation = new Validation; $validation->save(); $project->validation()->associate($validation); $project->save(); @@ -302,7 +302,7 @@ public function validationReport(Request $request, Project $project) $validation = $project->validation; if (! $validation) { - $validation = new Validation(); + $validation = new Validation; $validation->save(); $project->validation()->associate($validation); $project->save(); @@ -327,7 +327,13 @@ public function publish(Request $request, Project $project, PublishProject $publ if ($project) { $input = $request->all(); $release_date = $input['release_date']; - $enableProjectMode = $request->get('enableProjectMode'); + $selected_project_id = $input['selected_project_id']; + $selected_project_license_id = $input['license_id']; + if ($selected_project_id) { + $enableProjectMode = false; + } else { + $enableProjectMode = $request->get('enableProjectMode'); + } if ($enableProjectMode) { $validation = $project->validation; $validation->process(); @@ -363,10 +369,15 @@ public function publish(Request $request, Project $project, PublishProject $publ $validation = $validation->fresh(); foreach ($project->studies as $study) { - $study->license_id = $project->license_id; + if ($selected_project_id) { + $study->location = $selected_project_id; + $study->license_id = $selected_project_license_id; + } else { + $study->license_id = $project->license_id; + } $study->save(); foreach ($study->datasets as $dataset) { - $dataset->license_id = $project->license_id; + $dataset->license_id = $study->license_id; $dataset->save(); } } @@ -380,6 +391,7 @@ public function publish(Request $request, Project $project, PublishProject $publ } // add license check if ($status) { + ProcessSubmission::dispatch($project); return response()->json([ diff --git a/app/Http/Controllers/UserController.php b/app/Http/Controllers/UserController.php new file mode 100644 index 00000000..55d7107c --- /dev/null +++ b/app/Http/Controllers/UserController.php @@ -0,0 +1,28 @@ +id) + ->where('is_public', true) + ->get(['id', 'name', 'description', 'license_id']) + ->map(function ($project) { + return [ + 'id' => $project->id, + 'name' => $project->name, + 'description' => $project->description, + 'license_id' => $project->license_id, + ]; + }) + ->toArray(); + } +} diff --git a/app/Jobs/ProcessSubmission.php b/app/Jobs/ProcessSubmission.php index b939d3b6..63c169a3 100644 --- a/app/Jobs/ProcessSubmission.php +++ b/app/Jobs/ProcessSubmission.php @@ -37,6 +37,7 @@ class ProcessSubmission implements ShouldBeUnique, ShouldQueue public function __construct(Project $project) { $this->project = $project; + } /** @@ -45,7 +46,6 @@ public function __construct(Project $project) public function handle(AssignIdentifier $assigner, UpdateDOI $updater, PublishProject $projectPublisher, PublishStudy $studyPublisher) { $project = $this->project; - $project->status = 'processing'; $project->save(); @@ -117,16 +117,19 @@ public function handle(AssignIdentifier $assigner, UpdateDOI $updater, PublishPr $logs = 'Moving files in progress'; if ($project) { + $_studies = $project->studies; if ($draft) { $environment = env('APP_ENV', 'local'); foreach ($_studies as $study) { // $study->users()->sync($project->user()->getDictionary()); + $studyPath = preg_replace( '~//+~', '/', $environment.'/samples/'.$study->uuid + ); $studyFSObjects = FileSystemObject::with('children') @@ -154,11 +157,15 @@ public function handle(AssignIdentifier $assigner, UpdateDOI $updater, PublishPr } $study->process_logs = $process_logs; $study->draft_id = null; - $study->project_id = null; + if ($study->location) { + $study->project_id = $study->location; + } else { + $study->project_id = null; + } foreach ($study->datasets as $dataset) { $dataset->draft_id = null; - $dataset->project_id = null; + $dataset->project_id = $study->project_id; $dataset->save(); } @@ -167,7 +174,14 @@ public function handle(AssignIdentifier $assigner, UpdateDOI $updater, PublishPr } } $assigner->assign($_studies); + $release_date = Carbon::parse($project->release_date); + foreach ($_studies as $study) { + if ($study->location) { + $release_date = Carbon::now(); + $study->release_date = $release_date; + } + } if ($release_date->isPast()) { foreach ($_studies as $study) { @@ -176,7 +190,14 @@ public function handle(AssignIdentifier $assigner, UpdateDOI $updater, PublishPr } $updater->update($_studies); //Notification::send($this->prepareSendList($project), new StudyPublishNotification($_studies)); - event(new StudyPublish($_studies, $this->prepareSendList($project))); + + if ($study->location) { + $selected_project = Project::where([['id', $study->location]])->firstOrFail(); + event(new StudyPublish($_studies, $this->prepareSendList($selected_project))); + $study->location = null; + } else { + event(new StudyPublish($_studies, $this->prepareSendList($project))); + } $project->delete(); $draft->delete(); diff --git a/resources/js/Pages/Publish.vue b/resources/js/Pages/Publish.vue index 01a091e0..df19c798 100644 --- a/resources/js/Pages/Publish.vue +++ b/resources/js/Pages/Publish.vue @@ -83,6 +83,14 @@ @blur="updateDraft" /> + + {{ "+ Add to existing project" }} + +
@@ -677,6 +685,11 @@ ref="manageCitationElement" :project="project" /> +
@@ -790,6 +803,7 @@ import Validation from "@/Shared/Validation.vue"; import Datepicker from "@vuepic/vue-datepicker"; import "@vuepic/vue-datepicker/dist/main.css"; import ManageAuthor from "@/Shared/ManageAuthor.vue"; +import ManageProject from "@/Shared/ManageProject.vue"; import ToolTip from "@/Shared/ToolTip.vue"; import ManageCitation from "@/Shared/ManageCitation.vue"; import Citation from "@/Shared/Citation.vue"; @@ -856,15 +870,19 @@ export default { CitationCard, JetConfirmationModal, JetSuccessButton, + ManageProject, }, props: ["user", "team", "project", "teamRole", "draft"], setup() { const manageAuthorElement = ref(null); const manageCitationElement = ref(null); + const manageProjectElement = ref(null); + return { manageAuthorElement, manageCitationElement, + manageProjectElement, }; }, @@ -886,6 +904,7 @@ export default { terms: false, enableProjectMode: false, release_date: this.setReleaseDate(), + selected_project_id: null, }), licenses: null, license: null, @@ -1121,6 +1140,9 @@ export default { toggleManageCitation() { this.manageCitationElement.toggleDialog(); }, + toggleManageProject() { + this.manageProjectElement.toggleDialog(); + }, publish() { this.showPublishConfirmationModal = false; if (this.publishForm.conditions && this.publishForm.terms) { @@ -1149,6 +1171,14 @@ export default { return true; } }, + + handleProjectSelected(selected_project) { + this.publishForm.selected_project_id = selected_project.id; + this.publishForm.license_id = selected_project.license_id; + this.publishForm.conditions = true; + this.publishForm.terms = true; + this.publish(); + }, // trackProject() { // axios // .get("/projects/status/" + this.project.id + "/queue") diff --git a/resources/js/Shared/ManageProject.vue b/resources/js/Shared/ManageProject.vue new file mode 100644 index 00000000..653a4ff8 --- /dev/null +++ b/resources/js/Shared/ManageProject.vue @@ -0,0 +1,154 @@ + + + diff --git a/resources/js/Shared/SelectRich.vue b/resources/js/Shared/SelectRich.vue index 891c9a95..de7dbeec 100644 --- a/resources/js/Shared/SelectRich.vue +++ b/resources/js/Shared/SelectRich.vue @@ -10,7 +10,7 @@ class="relative w-full bg-white border border-gray-300 rounded-md shadow-sm pl-3 pr-10 py-2 text-left cursor-default focus:outline-none focus:ring-1 focus:ring-teal-500 focus:border-teal-500 sm:text-sm" > {{ - selected.title + selected.title || selected.name }} --Select-- - {{ item.title }}
+ {{ item.title || item.name }}
name('embed'); +Route::get('{user}/public-projects', [UserController::class, 'retrieveProjects'])->name('user.publicProjects'); From 07b70ec72d52e4e4d6b027704fa6e40c36d95530 Mon Sep 17 00:00:00 2001 From: NRayya <82588017+NRayya@users.noreply.github.com> Date: Sat, 2 Nov 2024 20:51:46 +0100 Subject: [PATCH 2/2] fix: update related identifiers of the published projects (datacite) --- app/Jobs/ProcessSubmission.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/Jobs/ProcessSubmission.php b/app/Jobs/ProcessSubmission.php index 63c169a3..ee69149b 100644 --- a/app/Jobs/ProcessSubmission.php +++ b/app/Jobs/ProcessSubmission.php @@ -188,15 +188,16 @@ public function handle(AssignIdentifier $assigner, UpdateDOI $updater, PublishPr $studyPublisher->publish($study); } } - $updater->update($_studies); //Notification::send($this->prepareSendList($project), new StudyPublishNotification($_studies)); if ($study->location) { $selected_project = Project::where([['id', $study->location]])->firstOrFail(); + $updater->update($selected_project); event(new StudyPublish($_studies, $this->prepareSendList($selected_project))); $study->location = null; } else { event(new StudyPublish($_studies, $this->prepareSendList($project))); + $updater->update($_studies); } $project->delete();