Skip to content

Commit

Permalink
feat: enable metadata edit of published projects and samples
Browse files Browse the repository at this point in the history
fixes:  #1173
  • Loading branch information
NRayya committed Oct 19, 2024
1 parent 4fee4a6 commit f2e9acd
Show file tree
Hide file tree
Showing 14 changed files with 159 additions and 66 deletions.
3 changes: 2 additions & 1 deletion app/Actions/Project/UpdateProject.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public function update(Project $project, array $input)
Validator::make($input, [
'name' => ['required', 'string', 'max:255', Rule::unique('projects')
->where('owner_id', $project->owner_id)->ignore($project->id), ],
'description' => ['required_if:is_public,"true"', 'min:20'],
'license' => ['required_if:is_public,"true"'],
], $errorMessages)->validate();

Expand Down Expand Up @@ -107,7 +108,7 @@ public function update(Project $project, array $input)
$validation = $project->validation;

if (! $validation) {
$validation = new Validation();
$validation = new Validation;
$validation->save();
$project->validation()->associate($validation);
$project->save();
Expand Down
2 changes: 1 addition & 1 deletion app/Actions/Study/UpdateStudy.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public function update(Study $study, array $input)
$license_id = $licenseExists ? $input['license_id'] : $study->license_id;

if ($is_public == true) {
$release_date = Carbon::now()->timestamp;
$release_date = $study->release_date;

$sample = $study->sample;
$sampleIdentifier = $sample->identifier ? $sample->identifier : null;
Expand Down
32 changes: 30 additions & 2 deletions app/Http/Controllers/ProjectController.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use App\Models\Study;
use App\Models\User;
use App\Models\Validation;
use App\Services\DOI\DOIService;
use Auth;
use Illuminate\Auth\Access\AuthorizationException;
use Illuminate\Contracts\Auth\StatefulGuard;
Expand All @@ -31,6 +32,29 @@

class ProjectController extends Controller
{
/**
* The DOI service instance.
*
* @var \App\Services\DOI\DOIService
*/
protected $doiService;

/**
* Create a new class instance.
*
* @return void
*/
/**
* Create a new class instance.
*
* @return void
*/
public function __construct(DOIService $doiService)
{
// Assign the DOI service instance
$this->doiService = $doiService;
}

public function publicProjectView(Request $request, $owner, $slug)
{
$user = User::where('username', $owner)->firstOrFail();
Expand Down Expand Up @@ -274,7 +298,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();
Expand Down Expand Up @@ -302,7 +326,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();
Expand Down Expand Up @@ -414,6 +438,10 @@ public function update(Request $request, UpdateProject $updater, Project $projec
}

$updater->update($project, $request->all());
if ($project->is_public) {
$project->updateDOIMetadata($this->doiService);
$project->addRelatedIdentifiers($this->doiService);
}

return $request->wantsJson() ? new JsonResponse('', 200) : back()->with('success', 'Project updated successfully');
}
Expand Down
28 changes: 28 additions & 0 deletions app/Http/Controllers/StudyController.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use App\Models\Project;
use App\Models\Sample;
use App\Models\Study;
use App\Services\DOI\DOIService;
use Auth;
use Illuminate\Auth\Access\AuthorizationException;
use Illuminate\Contracts\Auth\StatefulGuard;
Expand All @@ -28,6 +29,29 @@

class StudyController extends Controller
{
/**
* The DOI service instance.
*
* @var \App\Services\DOI\DOIService
*/
protected $doiService;

/**
* Create a new class instance.
*
* @return void
*/
/**
* Create a new class instance.
*
* @return void
*/
public function __construct(DOIService $doiService)
{
// Assign the DOI service instance
$this->doiService = $doiService;
}

public function publicStudiesView(Request $request)
{
$moleculeId = $request->get('compound');
Expand Down Expand Up @@ -68,6 +92,10 @@ public function update(Request $request, UpdateStudy $updater, Study $study)
$study = $study->fresh();

$study->load(['datasets', 'sample.molecules', 'tags']);
if ($study->is_public) {
$study->updateDOIMetadata($this->doiService);
$study->addRelatedIdentifiers($this->doiService);
}

return $request->wantsJson()
? new JsonResponse($study, 200)
Expand Down
4 changes: 4 additions & 0 deletions app/Models/HasDOI.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,10 @@ public function getMetadata()
if ($this->project) {
$authors = $this->project->authors ? $this->project->authors : [];
$citations = $this->project->citations ? $this->project->citations : [];
foreach ($this->tags as &$tag) {
$keyword = $tag->name;
array_push($keywords, $keyword);
}
}

} elseif ($this instanceof Dataset) {
Expand Down
2 changes: 1 addition & 1 deletion app/Policies/ProjectPolicy.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public function createProject(User $user)
*/
public function updateProject(User $user, Project $project)
{
if ($project->is_public || $project->is_archived || $project->is_deleted || $project->is_published) {
if ($project->is_archived || $project->is_deleted) {
return false;
}

Expand Down
2 changes: 1 addition & 1 deletion app/Policies/StudyPolicy.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public function createStudy(User $user)
*/
public function updateStudy(User $user, Study $study)
{
if ($study->is_public || $study->is_archived || $study->is_deleted || $study->is_published || (! $study->is_published && $study->doi)) {
if ($study->is_archived || $study->is_deleted) {
return false;
}

Expand Down
70 changes: 25 additions & 45 deletions resources/js/Pages/Project/Partials/Details.vue
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@
"
/>
</div>
<fieldset>
<!-- <fieldset>
<legend
class="text-sm font-medium text-gray-900"
>
Expand Down Expand Up @@ -388,7 +388,7 @@
</div>
</div>
</div>
</fieldset>
</fieldset> -->
</div>
<div>
<div v-if="form.is_public">
Expand Down Expand Up @@ -698,7 +698,7 @@
form.license
"
:disabled="
!canUpdateProject
project.is_public
"
label="License"
:items="
Expand All @@ -713,8 +713,16 @@
"
class="mt-2"
/>
<div
class="mt-2 flex text-xs"
>
You can't change the
licence once the project
is public
</div>
</div>
<div class="mt-6 flex text-sm">

<!-- <div class="mt-6 flex text-sm">
<a
target="_blank"
href="https://docs.nmrxiv.org/submission-guides/sharing.html"
Expand All @@ -729,7 +737,7 @@
sharing
</span>
</a>
</div>
</div> -->
<div
class="mt-4 flex text-sm mb-6"
>
Expand All @@ -756,36 +764,8 @@
</div>
</div>
</div>
<!--Footer-->
<div
v-if="!form.is_public"
class="flex-shrink-0 px-4 py-4 flex justify-end"
>
<jet-action-message
:on="form.recentlySuccessful"
class="mr-3 py-2 text-green-200"
>
Saved.
</jet-action-message>
<jet-secondary-button
type="button"
class="bg-white py-2 px-4 border border-gray-300 rounded-md shadow-sm text-sm font-medium text-gray-700 hover:bg-gray-50 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-gray-500"
@click="open = false"
>
Cancel
</jet-secondary-button>
<jet-button
v-if="canUpdateProject"
type="submit"
class="ml-4 inline-flex justify-center py-2 px-4 border border-transparent shadow-sm text-sm font-medium rounded-md text-white bg-gray-600 hover:bg-gray-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-gray-500"
@click="updateProject"
>
Save
</jet-button>
</div>
<!--Footer with confirmation-->

<div
v-if="form.is_public && canUpdateProject"
class="flex-shrink-0 px-4 py-4 flex justify-end"
>
<div class="flex items-center h-5">
Expand All @@ -802,11 +782,11 @@
<label
for="confirm"
class="font-small text-red-700"
>I understand, if the project is
made public then all the underlying
studies and dataset will also be
made public and this version is no
longer editable.
>I understand, if the project
metadata is updated, the project
will keep its same doi, but the doi
will have new metadata and
therefore, a new metadata version.
</label>
</div>
<jet-secondary-button
Expand Down Expand Up @@ -1053,12 +1033,12 @@ export default defineComponent({
if (this.form.license) {
this.form.license_id = this.form.license.id;
}
if (this.linkAccess) {
this.form.access = "link";
this.form.access_type = this.selectedAccessType.value;
} else {
this.form.access = "restricted";
}
// if (this.linkAccess) {
// this.form.access = "link";
// this.form.access_type = this.selectedAccessType.value;
// } else {
// this.form.access = "restricted";
// }
this.form.tags_array = this.form.tags.map((t) => t.text);
if (this.form.tag != "") {
let tags = this.form.tag.split(",");
Expand Down
9 changes: 3 additions & 6 deletions resources/js/Pages/Project/Show.vue
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
<button
v-if="canUpdateProject"
type="button"
class="inline-flex items-center shadow-sm px-4 py-1.5 text-sm leading-5 font-medium rounded-full text-gray-700 bg-white hover:bg-gray-50 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-teal-500"
class="inline-flex items-center shadow-sm px-4 py-1.5 ml-2 text-sm leading-5 font-medium rounded-full text-gray-700 bg-white hover:bg-gray-50 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-teal-500"
@click="toggleDetails"
>
<svg
Expand Down Expand Up @@ -306,10 +306,7 @@
</span>
</div>
</div>
<div
v-if="!canUpdateProject"
class="flex-nowrap right ml-auto"
>
<div class="flex-nowrap right ml-auto">
<img
v-if="project.project_photo_url"
:src="project.project_photo_url"
Expand Down Expand Up @@ -921,7 +918,7 @@
License
</span>
<button
v-if="canUpdateProject"
v-if="canUpdateProject && !project.is_public"
type="button"
class="inline-flex items-center shadow-sm px-4 py-1.5 border border-gray-300 text-sm leading-5 font-medium rounded-full text-gray-700 bg-white hover:bg-gray-50 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-teal-500"
@click="toggleDetails"
Expand Down
2 changes: 1 addition & 1 deletion resources/js/Pages/Study/About.vue
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@
License
</span>
<button
v-if="canUpdateStudy"
v-if="canUpdateStudy && !study.is_public"
type="button"
class="inline-flex items-center shadow-sm px-4 py-1.5 border border-gray-300 text-sm leading-5 font-medium rounded-full text-gray-700 bg-white hover:bg-gray-50 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-teal-500"
@click="openStudyDetailsPane"
Expand Down
2 changes: 1 addition & 1 deletion resources/js/Pages/Study/Layout.vue
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@
<button
v-if="canUpdateStudy"
type="button"
class="inline-flex items-center shadow-sm px-4 py-1.5 text-sm leading-5 font-medium rounded-full text-gray-700 bg-white hover:bg-gray-50 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-teal-500"
class="inline-flex items-center shadow-sm px-4 py-1.5 ml-2 text-sm leading-5 font-medium rounded-full text-gray-700 bg-white hover:bg-gray-50 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-teal-500"
@click="toggleDetails"
>
<svg
Expand Down
Loading

0 comments on commit f2e9acd

Please sign in to comment.