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"
/>
+
No projects available.
+