multiple commands
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
namespace Lucent\Channel;
|
||||
|
||||
|
||||
use Lucent\File\FileService;
|
||||
use Lucent\Channel\Data\UserCommand;
|
||||
use Lucent\Primitive\Collection;
|
||||
use Lucent\Schema\Schema;
|
||||
use Lucent\Schema\SchemaService;
|
||||
@@ -30,11 +30,16 @@ final class ChannelService
|
||||
$schemaService = new SchemaService();
|
||||
$schemasCollection = (new Collection($schemasArray["schemas"] ?? []))->map([$schemaService, 'fromArray']);
|
||||
|
||||
$userCommands = [];
|
||||
foreach (config("lucent.commands") as $signature => $desc) {
|
||||
$userCommands[] = new UserCommand($desc, $signature);
|
||||
}
|
||||
|
||||
$channel = new Channel(
|
||||
name: config("lucent.name") ?? "",
|
||||
url: rtrim(config("lucent.url") ?? "", "/"),
|
||||
previewTarget: rtrim(config("lucent.previewTarget") ?? "", "/"),
|
||||
generateCommand: config("lucent.generateCommand") ?? "",
|
||||
commands: Collection::make($userCommands),
|
||||
schemas: $schemasCollection,
|
||||
imageFilters: config("lucent.imageFilters") ?? [],
|
||||
roles: $schemasArray["roles"] ?? []
|
||||
@@ -64,7 +69,7 @@ final class ChannelService
|
||||
*/
|
||||
public function schemasReadableByRoles(array $roles): array
|
||||
{
|
||||
$schemasAllRead = $this->channel->schemas->filter(fn(Schema $schema) => empty($schema->read))->values()->pluck("name");
|
||||
$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();
|
||||
@@ -77,8 +82,8 @@ 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");
|
||||
$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