permissions
This commit is contained in:
@@ -22,24 +22,23 @@ final class ChannelService
|
||||
public static function fromConfig(): ChannelService
|
||||
{
|
||||
$schemasArray = [];
|
||||
if(file_exists(schemas_path())){
|
||||
if (file_exists(schemas_path())) {
|
||||
$schemasJson = file_get_contents(schemas_path());
|
||||
$schemasArray = json_decode($schemasJson, true);
|
||||
}
|
||||
|
||||
|
||||
$schemaService = new SchemaService();
|
||||
$schemasCollection = (new Collection($schemasArray))->map([$schemaService, 'fromArray']);
|
||||
|
||||
$schemasCollection = (new Collection($schemasArray["schemas"] ?? []))->map([$schemaService, 'fromArray']);
|
||||
|
||||
$channel = new Channel(
|
||||
name: config("lucent.name") ?? "",
|
||||
url: rtrim( config("lucent.url") ?? "", "/"),
|
||||
previewTarget: rtrim( config("lucent.previewTarget") ?? "", "/"),
|
||||
url: rtrim(config("lucent.url") ?? "", "/"),
|
||||
previewTarget: rtrim(config("lucent.previewTarget") ?? "", "/"),
|
||||
generateCommand: config("lucent.generateCommand") ?? "",
|
||||
schemas: $schemasCollection,
|
||||
imageFilters: config("lucent.imageFilters") ?? [],
|
||||
roles: $schemasArray["roles"] ?? []
|
||||
);
|
||||
|
||||
$channelService = new ChannelService($schemaService);
|
||||
$channelService->channel = $channel;
|
||||
return $channelService;
|
||||
@@ -58,4 +57,28 @@ final class ChannelService
|
||||
return some($schema);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string> $roles
|
||||
* @return array<string>
|
||||
*/
|
||||
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();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string> $roles
|
||||
* @return array<string>
|
||||
*/
|
||||
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();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user