Add fileshare to groups
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
This commit is contained in:
parent
6aaeb75b2a
commit
c7fc76466e
|
@ -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)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
namespace App;
|
namespace App;
|
||||||
|
|
||||||
|
use App\Fileshare\Data\FileshareResourceData;
|
||||||
use App\Group\Enums\Level;
|
use App\Group\Enums\Level;
|
||||||
use App\Nami\HasNamiField;
|
use App\Nami\HasNamiField;
|
||||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||||
|
@ -14,11 +15,12 @@ class Group extends Model
|
||||||
use HasFactory;
|
use HasFactory;
|
||||||
use HasNamiField;
|
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 $timestamps = false;
|
||||||
|
|
||||||
public $casts = [
|
public $casts = [
|
||||||
'level' => Level::class
|
'level' => Level::class,
|
||||||
|
'fileshare' => FileshareResourceData::class,
|
||||||
];
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -22,6 +22,9 @@ class GroupBulkstoreAction
|
||||||
'*.id' => 'required|integer|exists:groups,id',
|
'*.id' => 'required|integer|exists:groups,id',
|
||||||
'*.inner_name' => 'required|string|max:255',
|
'*.inner_name' => 'required|string|max:255',
|
||||||
'*.level' => ['required', 'string', Rule::in(Level::values())],
|
'*.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
|
public function handle(array $groups): void
|
||||||
{
|
{
|
||||||
foreach ($groups as $payload) {
|
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']]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -30,6 +30,7 @@ class GroupResource extends JsonResource
|
||||||
'id' => $this->id,
|
'id' => $this->id,
|
||||||
'level' => $this->level?->value,
|
'level' => $this->level?->value,
|
||||||
'children_count' => $this->children_count,
|
'children_count' => $this->children_count,
|
||||||
|
'fileshare' => $this->fileshare,
|
||||||
'links' => [
|
'links' => [
|
||||||
'children' => route('api.group', ['group' => $this->id]),
|
'children' => route('api.group', ['group' => $this->id]),
|
||||||
]
|
]
|
||||||
|
|
|
@ -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');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
|
@ -19,6 +19,7 @@
|
||||||
<th>NaMi-Name</th>
|
<th>NaMi-Name</th>
|
||||||
<th>Interner Name</th>
|
<th>Interner Name</th>
|
||||||
<th>Ebene</th>
|
<th>Ebene</th>
|
||||||
|
<th>Remote</th>
|
||||||
</thead>
|
</thead>
|
||||||
<tr v-for="child in editing.children" :key="child.id">
|
<tr v-for="child in editing.children" :key="child.id">
|
||||||
<td>
|
<td>
|
||||||
|
@ -30,6 +31,9 @@
|
||||||
<td>
|
<td>
|
||||||
<f-select :id="`level-${child.id}`" v-model="child.level" label="" size="sm" :name="`level-${child.id}`" :options="meta.levels"></f-select>
|
<f-select :id="`level-${child.id}`" v-model="child.level" label="" size="sm" :name="`level-${child.id}`" :options="meta.levels"></f-select>
|
||||||
</td>
|
</td>
|
||||||
|
<td>
|
||||||
|
<ui-remote-resource :id="`fileshare-${child.id}`" v-model="child.fileshare" size="sm" label=""></ui-remote-resource>
|
||||||
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
|
@ -108,7 +112,8 @@ async function edit(parent) {
|
||||||
|
|
||||||
async function store() {
|
async function store() {
|
||||||
await axios.post(meta.value.links.bulkstore, [editing.value.parent, ...editing.value.children]);
|
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;
|
editing.value = null;
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
|
@ -2,6 +2,8 @@
|
||||||
|
|
||||||
namespace Tests\Feature\Group;
|
namespace Tests\Feature\Group;
|
||||||
|
|
||||||
|
use App\Fileshare\ConnectionTypes\OwncloudConnection;
|
||||||
|
use App\Fileshare\Models\Fileshare;
|
||||||
use App\Group;
|
use App\Group;
|
||||||
use App\Group\Enums\Level;
|
use App\Group\Enums\Level;
|
||||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
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]);
|
$group = Group::factory()->for(Group::first(), 'parent')->create(['inner_name' => 'Gruppe', 'level' => Level::REGION]);
|
||||||
|
|
||||||
$this->postJson(route('group.bulkstore'), [
|
$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();
|
])->assertOk();
|
||||||
|
|
||||||
|
$this->assertNull($group->fresh()->fileshare);
|
||||||
$this->assertDatabaseHas('groups', [
|
$this->assertDatabaseHas('groups', [
|
||||||
'id' => $group->id,
|
'id' => $group->id,
|
||||||
'inner_name' => 'Abc',
|
'inner_name' => 'Abc',
|
||||||
'level' => 'Diözese',
|
'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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,8 @@
|
||||||
|
|
||||||
namespace Tests\Feature\Group;
|
namespace Tests\Feature\Group;
|
||||||
|
|
||||||
|
use App\Fileshare\ConnectionTypes\OwncloudConnection;
|
||||||
|
use App\Fileshare\Models\Fileshare;
|
||||||
use App\Group;
|
use App\Group;
|
||||||
use App\Group\Enums\Level;
|
use App\Group\Enums\Level;
|
||||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
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);
|
$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');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue