boboko lulnar
This commit is contained in:
@@ -2,7 +2,6 @@
|
||||
|
||||
namespace Lucent\Channel;
|
||||
|
||||
|
||||
use Lucent\Channel\Data\UserCommand;
|
||||
use Lucent\Primitive\Collection;
|
||||
use Lucent\Schema\Schema;
|
||||
@@ -13,12 +12,7 @@ final class ChannelService
|
||||
{
|
||||
public Channel $channel;
|
||||
|
||||
private function __construct(
|
||||
public SchemaService $schemaService,
|
||||
)
|
||||
{
|
||||
|
||||
}
|
||||
private function __construct(public SchemaService $schemaService) {}
|
||||
|
||||
public static function fromConfig(): ChannelService
|
||||
{
|
||||
@@ -28,7 +22,10 @@ final class ChannelService
|
||||
$schemasArray = json_decode($schemasJson, true);
|
||||
}
|
||||
$schemaService = new SchemaService();
|
||||
$schemasCollection = (new Collection($schemasArray["schemas"] ?? []))->map([$schemaService, 'fromArray']);
|
||||
$schemasCollection = new Collection($schemasArray["schemas"] ?? []);
|
||||
$schemasCollection = $schemasCollection->map(
|
||||
$schemaService->fromArray(...),
|
||||
);
|
||||
|
||||
$userCommands = [];
|
||||
foreach (config("lucent.commands") ?? [] as $signature => $desc) {
|
||||
@@ -42,7 +39,7 @@ final class ChannelService
|
||||
commands: Collection::make($userCommands),
|
||||
schemas: $schemasCollection,
|
||||
imageFilters: config("lucent.imageFilters") ?? [],
|
||||
roles: $schemasArray["roles"] ?? []
|
||||
roles: $schemasArray["roles"] ?? [],
|
||||
);
|
||||
|
||||
$channelService = new ChannelService($schemaService);
|
||||
@@ -69,11 +66,32 @@ final class ChannelService
|
||||
*/
|
||||
public function schemasReadableByRoles(array $roles): array
|
||||
{
|
||||
$schemasAllRead = $this->channel->schemas->filter(fn(Schema $schema) => empty($schema->read))->values()->pluck("name");
|
||||
$schemasCanRead = $this->channel->schemas->filter(fn(Schema $schema) => count(array_intersect($schema->read ?? [], $roles)) > 0)->values()->pluck("name");
|
||||
$schemasCanWrite = $this->channel->schemas->filter(fn(Schema $schema) => count(array_intersect($schema->write ?? [], $roles)) > 0)->values()->pluck("name");
|
||||
return $schemasAllRead->merge($schemasCanRead)->merge($schemasCanWrite)->unique()->values()->toArray();
|
||||
|
||||
$schemasAllRead = $this->channel->schemas
|
||||
->filter(fn(Schema $schema) => empty($schema->read))
|
||||
->values()
|
||||
->pluck("name");
|
||||
$schemasCanRead = $this->channel->schemas
|
||||
->filter(
|
||||
fn(Schema $schema) => count(
|
||||
array_intersect($schema->read ?? [], $roles),
|
||||
) > 0,
|
||||
)
|
||||
->values()
|
||||
->pluck("name");
|
||||
$schemasCanWrite = $this->channel->schemas
|
||||
->filter(
|
||||
fn(Schema $schema) => count(
|
||||
array_intersect($schema->write ?? [], $roles),
|
||||
) > 0,
|
||||
)
|
||||
->values()
|
||||
->pluck("name");
|
||||
return $schemasAllRead
|
||||
->merge($schemasCanRead)
|
||||
->merge($schemasCanWrite)
|
||||
->unique()
|
||||
->values()
|
||||
->toArray();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -82,9 +100,22 @@ final class ChannelService
|
||||
*/
|
||||
public function schemasWritableByRoles(array $roles): array
|
||||
{
|
||||
$schemasAllRead = $this->channel->schemas->filter(fn(Schema $schema) => empty($schema->write ?? []))->values()->pluck("name");
|
||||
$schemasCanWrite = $this->channel->schemas->filter(fn(Schema $schema) => count(array_intersect($schema->write ?? [], $roles)) > 0)->values()->pluck("name");
|
||||
return $schemasAllRead->merge($schemasCanWrite)->unique()->values()->toArray();
|
||||
$schemasAllRead = $this->channel->schemas
|
||||
->filter(fn(Schema $schema) => empty($schema->write ?? []))
|
||||
->values()
|
||||
->pluck("name");
|
||||
$schemasCanWrite = $this->channel->schemas
|
||||
->filter(
|
||||
fn(Schema $schema) => count(
|
||||
array_intersect($schema->write ?? [], $roles),
|
||||
) > 0,
|
||||
)
|
||||
->values()
|
||||
->pluck("name");
|
||||
return $schemasAllRead
|
||||
->merge($schemasCanWrite)
|
||||
->unique()
|
||||
->values()
|
||||
->toArray();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user