feat:动态权限
This commit is contained in:
@@ -44,8 +44,8 @@ class DatabaseDriver implements ModuleRepositoryInterface
|
||||
public function all(array $search): Collection
|
||||
{
|
||||
return $this->model::query()
|
||||
->when($search['name'] ?? false, function ($query) use ($search) {
|
||||
$query->where('name', 'like', '%'.$search['name'].'%');
|
||||
->when($search['title'] ?? false, function ($query) use ($search) {
|
||||
$query->where('title', 'like', '%'.$search['title'].'%');
|
||||
})->get();
|
||||
}
|
||||
|
||||
@@ -60,7 +60,7 @@ class DatabaseDriver implements ModuleRepositoryInterface
|
||||
$this->hasSameModule($module);
|
||||
|
||||
return $this->model->save([
|
||||
'name' => $module['name'],
|
||||
'title' => $module['title'],
|
||||
'path' => $module['path'],
|
||||
'description' => $module['desc'],
|
||||
'keywords' => $module['keywords'],
|
||||
@@ -91,7 +91,8 @@ class DatabaseDriver implements ModuleRepositoryInterface
|
||||
return $this->model->where('name', $name)
|
||||
|
||||
->update([
|
||||
'name' => $module['name'],
|
||||
'title' => $module['title'],
|
||||
'name' => $module['path'],
|
||||
'path' => $module['path'],
|
||||
'description' => $module['desc'],
|
||||
'keywords' => $module['keywords'],
|
||||
@@ -119,7 +120,7 @@ class DatabaseDriver implements ModuleRepositoryInterface
|
||||
{
|
||||
$module = $this->show($name);
|
||||
|
||||
$module->status = (int) $module->status;
|
||||
$module->enable = (int) $module->enable;
|
||||
|
||||
return $module->save();
|
||||
}
|
||||
@@ -132,7 +133,7 @@ class DatabaseDriver implements ModuleRepositoryInterface
|
||||
public function getEnabled(): Collection
|
||||
{
|
||||
// TODO: Implement getEnabled() method.
|
||||
return $this->model->where('status', Status::Enable->value())->get();
|
||||
return $this->model->where('enable', Status::Enable->value())->get();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -144,7 +145,7 @@ class DatabaseDriver implements ModuleRepositoryInterface
|
||||
public function enabled(string $moduleName): bool
|
||||
{
|
||||
// TODO: Implement enabled() method.
|
||||
return $this->getEnabled()->pluck('path')->contains($moduleName);
|
||||
return $this->getEnabled()->pluck('name')->contains($moduleName);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -157,10 +158,6 @@ class DatabaseDriver implements ModuleRepositoryInterface
|
||||
if ($this->model->where('name', $module['name'])->first()) {
|
||||
throw new FailedException(sprintf('Module [%s] has been created', $module['name']));
|
||||
}
|
||||
|
||||
if ($this->model->where('path', $module['path'])->first()) {
|
||||
throw new FailedException(sprintf('Module Alias [%s] has been exised', $module['alias']));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -55,14 +55,14 @@ class FileDriver implements ModuleRepositoryInterface
|
||||
|
||||
$modules = Collection::make(\json_decode(File::get($this->moduleJson), true))->values();
|
||||
|
||||
$name = $search['name'] ?? '';
|
||||
$title = $search['title'] ?? '';
|
||||
|
||||
if (! $name) {
|
||||
if (! $title) {
|
||||
return $modules;
|
||||
}
|
||||
|
||||
return $modules->filter(function ($module) use ($name) {
|
||||
return Str::of($module['name'])->contains($name);
|
||||
return $modules->filter(function ($module) use ($title) {
|
||||
return Str::of($module['title'])->contains($title);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -82,6 +82,8 @@ class FileDriver implements ModuleRepositoryInterface
|
||||
$module['version'] = '1.0.0';
|
||||
$module['enable'] = true;
|
||||
|
||||
$this->removeDirs($module);
|
||||
|
||||
File::put($this->moduleJson, $modules->push($module)->toJson(JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE));
|
||||
|
||||
return true;
|
||||
@@ -115,12 +117,13 @@ class FileDriver implements ModuleRepositoryInterface
|
||||
{
|
||||
File::put($this->moduleJson, $this->all()->map(function ($m) use ($module, $name) {
|
||||
if (Str::of($name)->exactly($m['name'])) {
|
||||
$m['path'] = $module['path'];
|
||||
$m['name'] = $module['name'];
|
||||
$m['title'] = $module['title'];
|
||||
$m['description'] = $module['description'] ?? '';
|
||||
$m['keywords'] = $module['keywords'] ?? '';
|
||||
$m['enable'] = $module['enable'];
|
||||
}
|
||||
$this->removeDirs($m);
|
||||
return $m;
|
||||
})->toJson(JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE));
|
||||
|
||||
@@ -180,7 +183,7 @@ class FileDriver implements ModuleRepositoryInterface
|
||||
public function enabled(string $moduleName): bool
|
||||
{
|
||||
// TODO: Implement enabled() method.
|
||||
return $this->getEnabled()->pluck('path')->contains($moduleName);
|
||||
return $this->getEnabled()->pluck('name')->contains($moduleName);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -195,10 +198,18 @@ class FileDriver implements ModuleRepositoryInterface
|
||||
if ($modules->pluck('name')->contains($module['name'])) {
|
||||
throw new FailedException(sprintf('Module [%s] has been created', $module['name']));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($modules->pluck('path')->contains($module['path'])) {
|
||||
throw new FailedException(sprintf('Module path [%s] has been existed', $module['path']));
|
||||
}
|
||||
/**
|
||||
* remove dirs
|
||||
*
|
||||
* @param array $modules
|
||||
*/
|
||||
protected function removeDirs(array &$modules)
|
||||
{
|
||||
if ($modules['dirs'] ?? false) {
|
||||
unset($modules['dirs']);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -59,6 +59,8 @@ class ModuleRepository
|
||||
*/
|
||||
public function create(array $module): bool
|
||||
{
|
||||
$module['name'] = lcfirst($module['path']);
|
||||
|
||||
Event::dispatch(new Creating($module));
|
||||
|
||||
$this->moduleRepository->create($module);
|
||||
@@ -93,6 +95,8 @@ class ModuleRepository
|
||||
*/
|
||||
public function update(string $name, array $module): bool
|
||||
{
|
||||
$module['name'] = lcfirst($module['path']);
|
||||
|
||||
Event::dispatch(new Updating($name, $module));
|
||||
|
||||
$this->moduleRepository->update($name, $module);
|
||||
|
Reference in New Issue
Block a user