Skip to content

Commit

Permalink
Merge pull request #558 from NFDI4Chem/development
Browse files Browse the repository at this point in the history
fix: enabled nmrium data versioning defaults to 3
  • Loading branch information
NishaSharma14 authored Nov 4, 2022
2 parents f3af0b8 + 04ba04f commit a8c3656
Show file tree
Hide file tree
Showing 20 changed files with 219 additions and 31 deletions.
3 changes: 3 additions & 0 deletions app/Actions/Fortify/UpdateUserProfileInformation.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public function update($user, array $input)
{
Validator::make($input, [
'first_name' => ['required', 'string', 'max:255'],
'name' => ['nullable', 'string', 'max:255'],
'last_name' => ['required', 'string', 'max:255'],
'email' => ['required', 'email', 'max:255', Rule::unique('users')->ignore($user->id)],
'username' => ['required', 'string', 'max:255', Rule::unique('users')->ignore($user->id)],
Expand All @@ -38,6 +39,7 @@ public function update($user, array $input)
'first_name' => $input['first_name'],
'last_name' => $input['last_name'],
'username' => $input['username'],
'name' => $input['username'] ? $input['username'] : $user->name,
'email' => $input['email'],
])->save();
}
Expand All @@ -55,6 +57,7 @@ protected function updateVerifiedUser($user, array $input)
$user->forceFill([
'first_name' => $input['first_name'],
'last_name' => $input['last_name'],
'name' => $input['name'] ? $input['name'] : $user->name,
'username' => $input['username'],
'email' => $input['email'],
'email_verified_at' => null,
Expand Down
2 changes: 1 addition & 1 deletion app/Actions/Project/UpdateProject.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ public function update(Project $project, array $input)

$draft = $project->draft;

if($draft){
if ($draft) {
$draft->name = $project->name;
$draft->slug = $project->slug;
$draft->description = $project->description;
Expand Down
2 changes: 1 addition & 1 deletion app/Console/Commands/AssignIdentifiers.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function handle(DOIService $doiService)
{
return DB::transaction(function () use ($doiService) {
$projects = Project::where([
['is_public', true]
['is_public', true],
])->get();
foreach ($projects as $project) {
$projectIdentifier = $project->identifier ? $project->identifier : null;
Expand Down
5 changes: 5 additions & 0 deletions app/Http/Controllers/DatasetController.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public function nmriumInfo(Request $request, Dataset $dataset)
$nmriumInfo = $spectra;
$molecules = $request->get('molecules');
$molecularInfo = $molecules;
$version = $request->get('version');

$nmrium = $dataset->nmrium;
if ($nmrium) {
Expand All @@ -60,6 +61,10 @@ public function nmriumInfo(Request $request, Dataset $dataset)
$nmriumData['molecules'] = $molecularInfo;
}

if ($version && ! empty($version)) {
$nmriumData['version'] = $version;
}

if (! empty($nmriumData)) {
if ($nmrium) {
$nmrium->nmrium_info = $nmriumData;
Expand Down
3 changes: 2 additions & 1 deletion app/Http/Middleware/HandleInertiaRequests.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use App\Models\Announcement;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Schema;
use Inertia\Middleware;

class HandleInertiaRequests extends Middleware
Expand Down Expand Up @@ -61,7 +62,7 @@ public function share(Request $request)
'twitter' => (env('TWITTER_CLIENT_ID') !== null && env('TWITTER_CLIENT_ID') !== ''),
'github' => (env('GITHUB_CLIENT_ID') !== null && env('GITHUB_CLIENT_ID') !== ''),
'orcid' => (env('ORCID_CLIENT_ID') !== null && env('ORCID_CLIENT_ID') !== ''),
'config.announcements' => Announcement::active(),
'config.announcements' => Schema::hasTable('announcements') ? Announcement::active() : null,
'url' => env('APP_URL'),
'nmriumURL' => env('NMRIUM_URL'),
'team' => $user ? $user->currentTeam : null,
Expand Down
2 changes: 1 addition & 1 deletion app/Providers/JetstreamServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public function boot()
*/
protected function configurePermissions()
{
Jetstream::defaultApiTokenPermissions(['read']);
Jetstream::defaultApiTokenPermissions(['project:read']);

Jetstream::role('owner', 'Owner', [
'project:create',
Expand Down
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
"tightenco/ziggy": "^1.0"
},
"require-dev": {
"brianium/paratest": "^6.6",
"fakerphp/faker": "^1.9.1",
"laravel/pint": "^1.0",
"laravel/sail": "^1.15",
Expand Down
154 changes: 153 additions & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions database/factories/UserFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,11 @@ public function definition()
{
return [
'name' => $this->faker->name(),
'first_name' => $this->faker->firstName(),
'last_name' => $this->faker->lastName(),
'email' => $this->faker->unique()->safeEmail(),
'email_verified_at' => now(),
'username' => $this->faker->userName(),
'password' => '$2y$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi', // password
'remember_token' => Str::random(10),
];
Expand Down
4 changes: 2 additions & 2 deletions phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
<server name="APP_ENV" value="testing"/>
<server name="BCRYPT_ROUNDS" value="4"/>
<server name="CACHE_DRIVER" value="array"/>
<server name="DB_CONNECTION" value="sqlite"/>
<server name="DB_DATABASE" value=":memory:"/>
<env name="DB_CONNECTION" value="pgsql"/>
<env name="DB_DATABASE" value="testing"/>
<server name="MAIL_MAILER" value="array"/>
<server name="QUEUE_CONNECTION" value="sync"/>
<server name="SESSION_DRIVER" value="array"/>
Expand Down
8 changes: 8 additions & 0 deletions resources/js/Shared/SpectraEditor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,7 @@ export default {
currentMolecules: [],
reset: false,
info: null,
version: null,
};
},
computed: {
Expand Down Expand Up @@ -395,6 +396,7 @@ export default {
this.saveStudyPreview(e.data.data.data);
}
}
this.version = e.data.data.version;
if (e.data.type == "nmr-wrapper:data-change") {
let actionType = e.data.data.actionType;
// console.log(actionType);
Expand Down Expand Up @@ -479,6 +481,10 @@ export default {
if (spectra && spectra.length <= 0) {
this.loadFromURL(url);
} else {
let nmriumVersion = 3;
if (nmrium_info && nmrium_info["version"]) {
nmriumVersion = nmrium_info["version"]
}
let mols = [];
if (this.isString(nmrium_info.molecules)) {
mols = JSON.parse(nmrium_info.molecules);
Expand All @@ -496,6 +502,7 @@ export default {
data: {
spectra: spectra,
molecules: mols,
version: nmriumVersion
},
type: "nmrium",
};
Expand Down Expand Up @@ -547,6 +554,7 @@ export default {
{
spectra: this.selectedSpectraData,
molecules: this.currentMolecules,
version: this.version ? this.version : 3
}
)
.catch((err) => {
Expand Down
6 changes: 5 additions & 1 deletion resources/js/Shared/SpectraViewer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,10 @@ export default {
nmrium_info = JSON.parse(
response.data.nmrium_info
);
let nmriumVersion = 3;
if (nmrium_info && nmrium_info["version"]) {
nmriumVersion = nmrium_info["version"]
}
if (nmrium_info && nmrium_info["spectra"]) {
if (this.isString(nmrium_info["spectra"])) {
spectra = JSON.parse(
Expand Down Expand Up @@ -378,11 +382,11 @@ export default {
"\n" + mol.molfile + "\n";
});
}
let data = {
data: {
spectra: spectra,
molecules: mols,
version: nmriumVersion
},
type: "nmrium",
};
Expand Down
6 changes: 4 additions & 2 deletions routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -220,8 +220,10 @@
Route::put('users/edit/{user}/password', [UsersController::class, 'updatePassword'])
->name('console.users.update-password');

Route::put('users/edit/{user}/role', [UsersController::class, 'updateRole'])
->name('console.users.update-role');
Route::group(['middleware' => ['permission:manage roles']], function () {
Route::put('users/edit/{user}/role', [UsersController::class, 'updateRole'])
->name('console.users.update-role');
});

Route::delete('users/edit/{user}/photo', [UsersController::class, 'destroyPhoto'])
->name('console.users.destroy-photo');
Expand Down
11 changes: 5 additions & 6 deletions tests/Feature/ApiTokenPermissionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,18 @@ public function test_api_token_permissions_can_be_updated()
$token = $user->tokens()->create([
'name' => 'Test Token',
'token' => Str::random(40),
'abilities' => ['create', 'read'],
'abilities' => ['project:create', 'project:read'],
]);

$response = $this->put('/user/api-tokens/'.$token->id, [
'name' => $token->name,
'permissions' => [
'delete',
'missing-permission',
'project:delete',
],
]);

$this->assertTrue($user->fresh()->tokens->first()->can('delete'));
$this->assertFalse($user->fresh()->tokens->first()->can('read'));
$this->assertFalse($user->fresh()->tokens->first()->can('missing-permission'));
$this->assertTrue($user->fresh()->tokens->first()->can('project:delete'));
$this->assertFalse($user->fresh()->tokens->first()->can('project:read'));
$this->assertFalse($user->fresh()->tokens->first()->can('project:missing-permission'));
}
}
Loading

0 comments on commit a8c3656

Please sign in to comment.