Add fileshare to groups
continuous-integration/drone/push Build is passing Details

This commit is contained in:
philipp lang 2024-06-29 14:36:35 +02:00
parent 6aaeb75b2a
commit c7fc76466e
8 changed files with 111 additions and 5 deletions

View File

@ -0,0 +1,18 @@
<?php
namespace App\Fileshare\Data;
use Spatie\LaravelData\Attributes\MapInputName;
use Spatie\LaravelData\Attributes\MapOutputName;
use Spatie\LaravelData\Data;
use Spatie\LaravelData\Mappers\SnakeCaseMapper;
#[MapInputName(SnakeCaseMapper::class)]
#[MapOutputName(SnakeCaseMapper::class)]
class FileshareResourceData extends Data
{
public function __construct(public int $connectionId, public string $resource)
{
}
}

View File

@ -2,6 +2,7 @@
namespace App;
use App\Fileshare\Data\FileshareResourceData;
use App\Group\Enums\Level;
use App\Nami\HasNamiField;
use Illuminate\Database\Eloquent\Factories\HasFactory;
@ -14,11 +15,12 @@ class Group extends Model
use HasFactory;
use HasNamiField;
public $fillable = ['nami_id', 'name', 'inner_name', 'level', 'parent_id'];
public $fillable = ['nami_id', 'name', 'inner_name', 'level', 'parent_id', 'fileshare'];
public $timestamps = false;
public $casts = [
'level' => Level::class
'level' => Level::class,
'fileshare' => FileshareResourceData::class,
];
/**

View File

@ -22,6 +22,9 @@ class GroupBulkstoreAction
'*.id' => 'required|integer|exists:groups,id',
'*.inner_name' => 'required|string|max:255',
'*.level' => ['required', 'string', Rule::in(Level::values())],
'*.fileshare' => 'present|nullable',
'*.fileshare.connection_id' => 'nullable|numeric|exists:fileshares,id',
'*.fileshare.resource' => 'nullable|string',
];
}
@ -31,7 +34,7 @@ class GroupBulkstoreAction
public function handle(array $groups): void
{
foreach ($groups as $payload) {
Group::find($payload['id'])->update(['level' => $payload['level'], 'inner_name' => $payload['inner_name']]);
Group::find($payload['id'])->update(['level' => $payload['level'], 'inner_name' => $payload['inner_name'], 'fileshare' => $payload['fileshare']]);
}
}

View File

@ -30,6 +30,7 @@ class GroupResource extends JsonResource
'id' => $this->id,
'level' => $this->level?->value,
'children_count' => $this->children_count,
'fileshare' => $this->fileshare,
'links' => [
'children' => route('api.group', ['group' => $this->id]),
]

View File

@ -0,0 +1,32 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('groups', function (Blueprint $table) {
$table->json('fileshare')->after('inner_name')->nullable();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('groups', function (Blueprint $table) {
$table->dropColumn('fileshare');
});
}
};

View File

@ -19,6 +19,7 @@
<th>NaMi-Name</th>
<th>Interner Name</th>
<th>Ebene</th>
<th>Remote</th>
</thead>
<tr v-for="child in editing.children" :key="child.id">
<td>
@ -30,6 +31,9 @@
<td>
<f-select :id="`level-${child.id}`" v-model="child.level" label="" size="sm" :name="`level-${child.id}`" :options="meta.levels"></f-select>
</td>
<td>
<ui-remote-resource :id="`fileshare-${child.id}`" v-model="child.fileshare" size="sm" label=""></ui-remote-resource>
</td>
</tr>
</table>
</div>
@ -108,7 +112,8 @@ async function edit(parent) {
async function store() {
await axios.post(meta.value.links.bulkstore, [editing.value.parent, ...editing.value.children]);
children[editing.value.parent.id] = (await axios.get(editing.value.parent.links.children)).data.data;
await toggle(editing.value.parent);
await toggle(editing.value.parent);
editing.value = null;
}
</script>

View File

@ -2,6 +2,8 @@
namespace Tests\Feature\Group;
use App\Fileshare\ConnectionTypes\OwncloudConnection;
use App\Fileshare\Models\Fileshare;
use App\Group;
use App\Group\Enums\Level;
use Illuminate\Foundation\Testing\DatabaseTransactions;
@ -18,13 +20,37 @@ class BulkstoreTest extends TestCase
$group = Group::factory()->for(Group::first(), 'parent')->create(['inner_name' => 'Gruppe', 'level' => Level::REGION]);
$this->postJson(route('group.bulkstore'), [
['id' => $group->id, 'inner_name' => 'Abc', 'level' => Level::FEDERATION->value]
['id' => $group->id, 'inner_name' => 'Abc', 'level' => Level::FEDERATION->value, 'fileshare' => null]
])->assertOk();
$this->assertNull($group->fresh()->fileshare);
$this->assertDatabaseHas('groups', [
'id' => $group->id,
'inner_name' => 'Abc',
'level' => 'Diözese',
'fileshare' => null,
]);
}
public function testItStoresFileconnection(): void
{
$this->login()->loginNami()->withoutExceptionHandling();
$connection = Fileshare::factory()
->type(OwncloudConnection::from(['user' => 'badenpowell', 'password' => 'secret', 'base_url' => env('TEST_OWNCLOUD_DOMAIN')]))
->name('lokaler Server')
->create();
$group = Group::factory()->for(Group::first(), 'parent')->create(['inner_name' => 'Gruppe', 'level' => Level::REGION]);
$this->postJson(route('group.bulkstore'), [
['id' => $group->id, 'inner_name' => 'Abc', 'level' => Level::FEDERATION->value, 'fileshare' => [
'connection_id' => $connection->id,
'resource' => '/abc',
]]
])->assertOk();
$this->assertEquals($connection->id, $group->fresh()->fileshare->connectionId);
$this->assertEquals('/abc', $group->fresh()->fileshare->resource);
}
}

View File

@ -2,6 +2,8 @@
namespace Tests\Feature\Group;
use App\Fileshare\ConnectionTypes\OwncloudConnection;
use App\Fileshare\Models\Fileshare;
use App\Group;
use App\Group\Enums\Level;
use Illuminate\Foundation\Testing\DatabaseTransactions;
@ -73,4 +75,21 @@ class IndexTest extends TestCase
$this->get('/api/group/' . Group::first()->id)->assertJsonPath('data.0.id', $group->id);
}
public function testItDisplaysFileshare(): void
{
$this->login()->loginNami()->withoutExceptionHandling();
$connection = Fileshare::factory()
->type(OwncloudConnection::from(['user' => 'badenpowell', 'password' => 'secret', 'base_url' => env('TEST_OWNCLOUD_DOMAIN')]))
->name('lokaler Server')
->create();
Group::factory()->for(Group::first(), 'parent')->create(['level' => null, 'fileshare' => [
'connection_id' => $connection->id,
'resource' => '/abc',
]]);
$this->get('/api/group/' . Group::first()->id)->assertJsonPath('data.0.fileshare.resource', '/abc');
}
}