permissions

This commit is contained in:
2023-10-17 22:57:25 +03:00
parent 4b9e9cb4f6
commit 632684f514
29 changed files with 370 additions and 223 deletions
+66 -24
View File
@@ -6,7 +6,6 @@ use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Lucent\Account\AccountService;
use Lucent\Account\AuthService;
use Lucent\Account\UserRepo;
use Lucent\Channel\ChannelService;
use Lucent\LucentException;
use Lucent\Query\Operator;
@@ -28,7 +27,6 @@ class RecordController extends Controller
private readonly AuthService $authService,
private readonly ChannelService $channelService,
private readonly Svelte $svelte,
private readonly UserRepo $userRepo,
private readonly Query $query,
private readonly Manager $recordManager
)
@@ -38,11 +36,21 @@ class RecordController extends Controller
public function index(Request $request)
{
$schemaName = $request->route("schemaName");
if(!in_array($schemaName,$this->accountService->currentReadableSchemas())){
return $this->svelte->render(
layout: "channel",
view: "recordNotFound",
title: "Schema Not Found",
);
}
$users = $this->accountService->all();
$schema = $this->channelService->getSchema($schemaName)->get();
$urlParams = $request->all();
$sort = data_get($urlParams, "sort") ?? "-_sys.updatedAt";
$filter = data_get($urlParams, "filter") ?? [];
$arguments = array_merge([
"schema" => $schema->name,
"status_in" => "draft,published",
@@ -82,6 +90,7 @@ class RecordController extends Controller
"total" => $graph->total ?? 0,
"filter" => $request->input("filter") ?? [],
"inModal" => true,
"isWritable" => in_array($schemaName,$this->accountService->currentWritableSchemas())
];
if ($request->ajax()) {
@@ -142,6 +151,14 @@ class RecordController extends Controller
public function new(Request $request)
{
if(!in_array($request->input("schema"),$this->accountService->currentWritableSchemas())){
return $this->svelte->render(
layout: "channel",
view: "recordNotFound",
title: "Schema Not Found",
);
}
$schema = $this->channelService->channel->schemas->where("name", $request->input("schema"))->first();
$recordHistory = $this->recordManager->fromSession($request->session())->getRecords();
$record = $this->recordService->createEmpty($schema, $this->authService->currentUserId());
@@ -162,6 +179,14 @@ class RecordController extends Controller
public function newInline(Request $request)
{
if(!in_array($request->input("schema"),$this->accountService->currentWritableSchemas())){
return $this->svelte->render(
layout: "channel",
view: "recordNotFound",
title: "Schema Not Found",
);
}
$schema = $this->channelService->getSchema($request->input("schema"))->get();
$record = $this->recordService->createEmpty($schema);
$queryRecord = QueryRecord::fromRecord($record);
@@ -198,9 +223,17 @@ class RecordController extends Controller
}
$record = $graph->records->first();
if(!in_array($record->schema,$this->accountService->currentReadableSchemas())){
return $this->svelte->render(
layout: "channel",
view: "recordNotFound",
title: "Schema Not Found",
);
}
$schema = $this->channelService->getSchema($record->schema)->get();
$recordHistory = $this->recordManager->fromSession($request->session())->push($rid)->getRecords($rid);
$users = $this->userRepo->all();
return $this->svelte->render(
layout: "channel",
view: "recordEdit",
@@ -209,33 +242,42 @@ class RecordController extends Controller
"schema" => $schema,
"graph" => toArray($graph),
"record" => toArray($record),
"users" => $users,
"users" => $this->accountService->all(),
"recordHistory" => $recordHistory,
"isWritable" => in_array($record->schema,$this->accountService->currentWritableSchemas())
]
);
}
public function editInline(Request $request)
{
$rid = $request->route("rid");
$graph = $this->query
->filter(["id" => $rid])
->limit(1)
->childrenDepth(2)
->parentsDepth(1)
->run();
$record = $graph->records->first();
return ok(
[
"graph" => toArray($graph),
"record" => toArray($record)
]
);
}
// public function editInline(Request $request)
// {
// $rid = $request->route("rid");
//
// $graph = $this->query
// ->filter(["id" => $rid])
// ->limit(1)
// ->childrenDepth(2)
// ->parentsDepth(1)
// ->run();
//
// $record = $graph->records->first();
//
// if(!in_array($record->schema,$this->accountService->currentReadableSchemas())){
// return $this->svelte->render(
// layout: "channel",
// view: "recordNotFound",
// title: "Schema Not Found",
// );
// }
//
// return ok(
// [
// "graph" => toArray($graph),
// "record" => toArray($record)
// ]
// );
// }
public function suggestions(Request $request)