Skip to content

Commit

Permalink
Merge pull request #973 from NFDI4Chem/issue-#971
Browse files Browse the repository at this point in the history
feat: enable sharing of private projects
  • Loading branch information
CS76 authored Jan 25, 2024
2 parents 1e3c098 + a95e1fb commit 3d2c84f
Show file tree
Hide file tree
Showing 22 changed files with 402 additions and 100 deletions.
2 changes: 1 addition & 1 deletion app/Actions/Project/CreateNewProject.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function create(array $input)
'color' => array_key_exists('color', $input) ? $input['color'] : null,
'starred' => array_key_exists('starred', $input) ? $input['starred'] : null,
'location' => array_key_exists('location', $input) ? $input['location'] : null,
'url' => Str::random(40),
'obfuscationcode' => Str::random(40),
'type' => array_key_exists('type', $input) ? $input['type'] : null,
'uuid' => Str::uuid(),
'access' => array_key_exists('access', $input) ? $input['access'] : 'restricted',
Expand Down
2 changes: 1 addition & 1 deletion app/Actions/Study/CreateNewStudy.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function create(array $input)
'color' => array_key_exists('color', $input) ? $input['color'] : null,
'starred' => array_key_exists('starred', $input) ? $input['starred'] : null,
'location' => array_key_exists('location', $input) ? $input['location'] : null,
'url' => Str::random(40),
'obfuscationcode' => Str::random(40),
'type' => array_key_exists('type', $input) ? $input['type'] : null,
'uuid' => Str::uuid(),
'access' => array_key_exists('access', $input) ? $input['access'] : 'restricted',
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 @@ -33,7 +33,7 @@ public function update(Study $study, array $input)
'color' => array_key_exists('color', $input) ? $input['color'] : $study->color,
'starred' => array_key_exists('starred', $input) ? $input['starred'] : $study->starred,
'location' => array_key_exists('location', $input) ? $input['location'] : $study->location,
'url' => array_key_exists('url', $input) ? $input['url'] : $study->url,
'obfuscationcode' => array_key_exists('obfuscationcode', $input) ? $input['obfuscationcode'] : $study->obfuscationcode,
'type' => array_key_exists('type', $input) ? $input['type'] : $study->type,
'species' => array_key_exists('species', $input) ? $input['species'] : $study->species,
'access' => array_key_exists('access', $input) ? $input['access'] : 'restricted',
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/DatasetController.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ public function publicDatasetsView(Request $request)
]);
}

public function preview(Request $request, Dataset $dataset)
public function snapshot(Request $request, Dataset $dataset)
{
$content = $request->get('img');
$study = $dataset->study;
Expand Down
10 changes: 5 additions & 5 deletions app/Http/Controllers/DraftController.php
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ public function process(Request $request, Draft $draft)
'name' => $draft->name,
'slug' => Str::slug($draft->name, '-'),
'description' => $draft->description,
'url' => Str::random(40),
'obfuscationcode' => Str::random(40),
'uuid' => Str::uuid(),
'team_id' => $team_id ? $team_id : null,
'owner_id' => $user_id,
Expand Down Expand Up @@ -296,7 +296,7 @@ public function process(Request $request, Draft $draft)
'name' => $folder->name,
'slug' => Str::slug($folder->name, '-'),
'description' => '',
'url' => Str::random(40),
'obfuscationcode' => Str::random(40),
'uuid' => Str::uuid(),
'team_id' => $project->team_id,
'owner_id' => $project->owner_id,
Expand Down Expand Up @@ -338,7 +338,7 @@ public function process(Request $request, Draft $draft)
'name' => $sChild->name,
'slug' => Str::slug($sChild->name, '-'),
'description' => $sChild->name,
'url' => Str::random(40),
'obfuscationcode' => Str::random(40),
'uuid' => Str::uuid(),
'team_id' => $project->team_id,
'owner_id' => $project->owner_id,
Expand Down Expand Up @@ -375,7 +375,7 @@ public function process(Request $request, Draft $draft)
'name' => 'Untitled',
'slug' => Str::slug('Untitled', '-'),
'description' => '',
'url' => Str::random(40),
'obfuscationcode' => Str::random(40),
'uuid' => Str::uuid(),
'team_id' => $project->team_id,
'owner_id' => $project->owner_id,
Expand Down Expand Up @@ -407,7 +407,7 @@ public function process(Request $request, Draft $draft)
'name' => $folder->name,
'slug' => Str::slug($folder->name, '-'),
'description' => '',
'url' => Str::random(40),
'obfuscationcode' => Str::random(40),
'uuid' => Str::uuid(),
'team_id' => $project->team_id,
'owner_id' => $project->owner_id,
Expand Down
40 changes: 40 additions & 0 deletions app/Http/Controllers/ProjectController.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,46 @@ public function show(Request $request, Project $project, GetLicense $getLicense)
]);
}

public function review(Request $request, $obfuscationCode, GetLicense $getLicense)
{
$project = Project::where([['is_archived', false], ['obfuscationcode', $obfuscationCode]])->firstOrFail();
$project->load('projectInvitations', 'tags', 'authors', 'citations', 'owner');
if (! $project->is_public) {
$license = null;
if ($project->license_id) {
$license = $getLicense->getLicensebyId($project->license_id);
}

return Inertia::render('Project/Show', [
'project' => $project,
'team' => null,
'members' => $project->allUsers(),
'availableRoles' => array_values(Jetstream::$roles),
'role' => 'reviewer',
'teamRole' => null,
'license' => $license ? $license[0] : null,
'projectPermissions' => [
'canDeleteProject' => false,
'canUpdateProject' => false,
],
'preview' => true,
]);
} else {
$identifier = explode(':', $project->identifier)[1];

return redirect()->route('public', $identifier);
}

}

public function reviewerStudies(Request $request, $obfuscationCode)
{
$project = Project::where([['is_archived', false], ['obfuscationcode', $obfuscationCode]])->firstOrFail();
if ($project) {
return StudyResource::collection(Study::where('project_id', $project->id)->filter($request->only('search', 'sort', 'mode'))->paginate(9)->withQueryString());
}
}

public function studies(Request $request, Project $project)
{
if (! Gate::forUser($request->user())->check('viewProject', $project)) {
Expand Down
147 changes: 99 additions & 48 deletions app/Http/Controllers/StudyController.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use App\Models\FileSystemObject;
use App\Models\Molecule;
use App\Models\NMRium;
use App\Models\Project;
use App\Models\Sample;
use App\Models\Study;
use Auth;
Expand Down Expand Up @@ -86,19 +87,7 @@ public function show(Request $request, Study $study, GetLicense $getLicense)
$license = $getLicense->getLicensebyId($study->license_id);
}

return Inertia::render('Study/About', [
'study' => $study->load('users', 'owner', 'studyInvitations', 'tags', 'sample.molecules'),
'team' => $team ? $team->load('users', 'owner') : null,
'project' => $project ? $project->load('users', 'owner') : null,
'members' => $study->allUsers(),
'availableRoles' => array_values(Jetstream::$roles),
'studyRole' => $study->userStudyRole(Auth::user()->email),
'license' => $license ? $license[0] : null,
'studyPermissions' => [
'canDeleteStudy' => Gate::check('deleteStudy', $study),
'canUpdateStudy' => Gate::check('updateStudy', $study),
],
]);
return $this->renderTabView('About', $study, $team, $project, $license, null, false);
}

public function protocols(Request $request, Study $study)
Expand All @@ -118,18 +107,101 @@ public function datasets(Request $request, Study $study)
$project = $study->project;
$team = $project->team;

return Inertia::render('Study/Datasets', [
'study' => $study->load('users', 'owner', 'studyInvitations', 'datasets'),
'team' => $team ? $team->load('users', 'owner') : null,
'project' => $project ? $project->load('users', 'owner') : null,
'members' => $study->allUsers(),
'availableRoles' => array_values(Jetstream::$roles),
'studyRole' => $study->userStudyRole(Auth::user()->email),
'studyPermissions' => [
'canDeleteStudy' => Gate::check('deleteStudy', $study),
'canUpdateStudy' => Gate::check('updateStudy', $study),
],
]);
return $this->renderTabView('Datasets', $study, $team, $project, null, null, false);
}

public function preview2(Request $request, $obfuscationCode, Study $study, $model, GetLicense $getLicense)
{
switch ($model) {
case 'study':
$project = Project::where([['is_archived', false], ['obfuscationcode', $obfuscationCode]])->firstOrFail();
$team = $project->nonPersonalTeam;
$license = null;
if ($study->license_id) {
$license = $getLicense->getLicensebyId($study->license_id);
}

return $this->renderTabView('About', $study, $team, $project, $license, null, true);

break;
case 'files':
$project = Project::where([['is_archived', false], ['obfuscationcode', $obfuscationCode]])->firstOrFail();
$team = $project->nonPersonalTeam;
$studyFSObject = $study->fsObject;

return $this->renderTabView('Files', $study, $team, $project, null, $studyFSObject, true);

break;
case 'datasets':
$project = Project::where([['is_archived', false], ['obfuscationcode', $obfuscationCode]])->firstOrFail();
$team = $project->nonPersonalTeam;

return $this->renderTabView('Datasets', $study, $team, $project, null, null, true);

break;
}
}

public function renderTabView($tab, $study, $team, $project, $license, $studyFSObject, $preview)
{
switch ($tab) {
case 'About':
return Inertia::render('Study/About', [
'study' => $study->load('users', 'owner', 'studyInvitations', 'tags', 'sample.molecules'),
'team' => $team ? $team->load('users', 'owner') : null,
'project' => $project ? $project->load('users', 'owner') : null,
'members' => $study->allUsers(),
'preview' => $preview,
'availableRoles' => array_values(Jetstream::$roles),
'studyRole' => $preview ? null : $study->userStudyRole(Auth::user()->email),
'license' => $license ? $license[0] : null,
'studyPermissions' => [
'canDeleteStudy' => Gate::check('deleteStudy', $study),
'canUpdateStudy' => Gate::check('updateStudy', $study),
],
]);
break;
case 'Files':
return Inertia::render('Study/Files', [
'study' => $study->load('users', 'owner', 'studyInvitations'),
'team' => $team ? $team->load('users', 'owner') : null,
'project' => $project ? $project->load('users', 'owner') : null,
'members' => $study->allUsers(),
'preview' => $preview,
'availableRoles' => array_values(Jetstream::$roles),
'studyRole' => $preview ? null : $study->userStudyRole(Auth::user()->email),
'studyPermissions' => [
'canDeleteStudy' => Gate::check('deleteStudy', $study),
'canUpdateStudy' => Gate::check('updateStudy', $study),
],
'file' => [
'name' => '/',
'children' => FileSystemObject::with('children')
->where([
['study_id', $study->id],
['level', $studyFSObject->level],
])
->orderBy('type')
->get(),
],
]);
break;
case 'Datasets':
return Inertia::render('Study/Datasets', [
'study' => $study->load('users', 'owner', 'studyInvitations', 'datasets'),
'team' => $team ? $team->load('users', 'owner') : null,
'project' => $project ? $project->load('users', 'owner') : null,
'members' => $study->allUsers(),
'preview' => $preview,
'availableRoles' => array_values(Jetstream::$roles),
'studyRole' => $preview ? null : $study->userStudyRole(Auth::user()->email),
'studyPermissions' => [
'canDeleteStudy' => Gate::check('deleteStudy', $study),
'canUpdateStudy' => Gate::check('updateStudy', $study),
],
]);
break;
}
}

public function moleculeStore(Request $request, Study $study)
Expand Down Expand Up @@ -301,28 +373,7 @@ public function files(Request $request, Study $study)
$team = $project->nonPersonalTeam;
$studyFSObject = $study->fsObject;

return Inertia::render('Study/Files', [
'study' => $study->load('users', 'owner', 'studyInvitations'),
'team' => $team ? $team->load('users', 'owner') : null,
'project' => $project ? $project->load('users', 'owner') : null,
'members' => $study->allUsers(),
'availableRoles' => array_values(Jetstream::$roles),
'studyRole' => $study->userStudyRole(Auth::user()->email),
'studyPermissions' => [
'canDeleteStudy' => Gate::check('deleteStudy', $study),
'canUpdateStudy' => Gate::check('updateStudy', $study),
],
'file' => [
'name' => '/',
'children' => FileSystemObject::with('children')
->where([
['study_id', $study->id],
['level', $studyFSObject->level],
])
->orderBy('type')
->get(),
],
]);
return $this->renderTabView('Files', $study, $team, $project, null, $studyFSObject, false);
}

public function annotations(Request $request, Study $study)
Expand Down Expand Up @@ -477,7 +528,7 @@ public function toggleStarred(Request $request, Study $study)
return Bookmark::toggle($study, $request->user());
}

public function preview(Request $request, Study $study)
public function snapshot(Request $request, Study $study)
{
$content = $request->get('img');
if ($content) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::table('projects', function (Blueprint $table) {
$table->renameColumn('url', 'obfuscationCode');
});
}

/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('projects', function (Blueprint $table) {
$table->renameColumn('obfuscationCode', 'url');
});
}
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::table('studies', function (Blueprint $table) {
$table->renameColumn('url', 'obfuscationCode');
});
}

/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('studies', function (Blueprint $table) {
$table->renameColumn('obfuscationCode', 'url');
});
}
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::table('datasets', function (Blueprint $table) {
$table->renameColumn('url', 'obfuscationCode');
});
}

/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('datasets', function (Blueprint $table) {
$table->renameColumn('url', 'obfuscationCode');
});
}
};
Loading

0 comments on commit 3d2c84f

Please sign in to comment.