File systeme V3

This commit is contained in:
Mathieu Lagacé
2020-10-19 18:45:05 -04:00
parent 1664bb06aa
commit 4f83774200
27 changed files with 2030 additions and 1223 deletions

View File

@@ -4,6 +4,7 @@ namespace App\Http\Controllers;
use App\GoogleDriveFile;
use Illuminate\Http\Request;
use function Symfony\Component\VarDumper\Dumper\esc;
class FilesController extends Controller
{
@@ -41,21 +42,83 @@ class FilesController extends Controller
/**
* Display the specified resource.
*
* @param string $id
* @return void
* @param $path
* @return \Symfony\Component\HttpFoundation\StreamedResponse
*/
public function show($path)
public function show(String $path)
{
$file_rules = \DB::table('acl_rules')->where('path','=',$path)->get()->all();
if ($file_rules != []) {
dd($file_rules);
}
dd(dirname($path));
$path_rules = \DB::table('acl_rules')->where('path','=',dirname($path))->get()->all();
if ($path_rules != []) {
$all_rules = collect(\DB::table('acl_rules')->get()->all());
foreach ($all_rules as $rule)
{
if ($rule->path == "*")
{
if (\Auth::check())
{
if (\Auth::user()->checkACLRules($rule) > 0)
{
if (\Storage::exists($path))
{
return \Storage::download($path);
}
else
{
abort(404);
}
}
}
}
}
return abort(404);
$path_array = explode('/',$path);
$checkedPath = $path_array[0];
unset($path_array[0]);
$path_array = array_values($path_array);
while ($checkedPath != $path)
{
$rules = $all_rules->where('path','=',$checkedPath.'/*');
if ($rules->isNotEmpty())
{
$access_level = 0;
foreach ($rules as $r)
{
if (\Auth::check())
{
$temp_access_level = \Auth::user()->checkACLRules($r);
if ($temp_access_level > $access_level)
{
$access_level = $temp_access_level;
}
}
else
{
if ($r->user_id == '*')
{
if ($r->access > $access_level)
{
$access_level = $r->access;
}
}
}
if ($access_level > 0)
{
if (\Storage::exists($path))
{
return \Storage::download($path);
}
else
{
abort(404);
}
}
}
}
$checkedPath = $checkedPath.'/'.$path_array[0];
unset($path_array[0]);
$path_array = array_values($path_array);
}
abort(403);
}
/**
@@ -94,67 +157,63 @@ class FilesController extends Controller
public function guide()
{
if (\App\GoogleDriveFile::checkConfig())
{
$dirID = \App\GoogleDriveFile::findByPath('.Privé/.Staff/.Guide');
$dir = collect(\Storage::cloud()->listContents($dirID->id,false))->sortBy('name');
return view('admin.files.guide',['dir' => $dir]);
}
return redirect('/admin')->with('error','Google Drive n\'est pas configuré');
return redirect('/admin/files?leftPath=Prive/Staff/Guide');
}
public function instruction()
{
if (\App\GoogleDriveFile::checkConfig())
{
return view('admin.files.Google Drive.index',['folder' => \App\GoogleDriveFile::where('path','=','.Privé/.Staff/.Instruction')->first()->id, 'mode' => 'folder']);
}
return redirect('/admin')->with('error','Google Drive n\'est pas configuré');
return redirect('/admin/files?leftPath=Prive/Staff/Instruction');
}
public function cadet()
{
if (!\App\GoogleDriveFile::checkConfig())
{
return redirect('/admin')->with('error','Google Drive n\'est pas configuré');
}
return view('admin.files.Google Drive.index',['folder' => \App\GoogleDriveFile::where('path','=','.Privé/.Cadet')->first()->id, 'mode' => 'folder']);
return redirect('/admin/files?leftPath=Prive/Cadet');
}
public function staff()
{
if (!\App\GoogleDriveFile::checkConfig())
{
return redirect('/admin')->with('error','Google Drive n\'est pas configuré');
}
return view('admin.files.Google Drive.index',['folder' => \App\GoogleDriveFile::where('path','=','.Privé/.Staff')->first()->id, 'mode' => 'folder']);
return redirect('/admin/files?leftPath=Prive/Staff');
}
public function etamas()
{
if (!\App\GoogleDriveFile::checkConfig())
{
return redirect('/admin')->with('error','Google Drive n\'est pas configuré');
}
return view('admin.files.Google Drive.index',['folder' => \App\GoogleDriveFile::where('path','=','.Privé/.ETAMAS')->first()->id, 'mode' => 'folder']);
return redirect('/admin/files?leftPath=Prive/ETAMAS');
}
public function officier()
{
if (!\App\GoogleDriveFile::checkConfig())
{
return redirect('/admin')->with('error','Google Drive n\'est pas configuré');
}
return view('admin.files.Google Drive.index',['folder' => \App\GoogleDriveFile::where('path','=','.Privé/.Officier')->first()->id, 'mode' => 'folder']);
return redirect('/admin/files?leftPath=Prive/Officier');
}
public function publique()
{
if (!\App\GoogleDriveFile::checkConfig())
return redirect('/admin/files?leftPath=Publique');
}
public function show_nominativeList()
{
return view('admin.files.list.index');
}
public function download_nominativeList()
{
if (\Storage::exists('/Systeme/Fichier/ListeNominative.pdf'))
{
return redirect('/admin')->with('error','Google Drive n\'est pas configuré');
return \Storage::download('/Systeme/Fichier/ListeNominative.pdf');
}
return view('admin.files.Google Drive.index',['folder' => \App\GoogleDriveFile::where('path','=','.Publique')->first()->id, 'mode' => 'folder']);
return view('admin.files.list.index');
}
public function edit_nominativeList()
{
return view('admin.files.list.edit');
}
public function update_nominativeList()
{
\Storage::putFileAs('Systeme/Fichier',\request()->file('nominativeList'),'ListeNominative.pdf');
clog('edit','success','a modifié la liste nominative');
return redirect('/admin/nominativelist')->with('success','Modification sauvegarder avec succès !');
}
}