File Explorer update + Permission update

This commit is contained in:
George Frederick "Buzz" Beurling
2020-03-19 19:07:26 -04:00
parent 8a0e09cb80
commit 1e3ae2fbbb
36 changed files with 1899 additions and 434 deletions

View File

@@ -2,6 +2,7 @@
namespace App\Http\Controllers;
use App\GoogleDriveFile;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Storage;
use Psy\Util\Str;
@@ -245,9 +246,6 @@ class GoogleDriveController extends Controller
$contents = collect(Storage::cloud()->listContents($folder, $recursive));
}
//dd($contents);
//$meta = collect(Storage::cloud()->listContents($folder, true));
//dd($meta);
return view('admin.files.Google Drive.explorer',['directories' => $contents->where('type', '=', 'dir')->sortByDesc('name'), 'files' => $contents->where('type', '=', 'file'), 'currentDir' => $folder]);
}
@@ -256,7 +254,7 @@ class GoogleDriveController extends Controller
$error = [];
if(\App\Config::getData('is_Google_Drive_enabled') == "true")
{
if ($this->checkConfig())
if (GoogleDriveFile::checkConfig())
{
$structure = $this->getFileStructure();
$this->checkStructure($structure,'/','/',$error);
@@ -273,61 +271,135 @@ class GoogleDriveController extends Controller
return $error;
}
public function checkStructure($structure,$parent,$id,&$error)
public function checkStructure()
{
$mydir = $this->listLockDirectory($id);
$structure = $this->getFileStructure();
foreach ($structure as $key => $value)
foreach ($structure as $directory => $value)
{
$found = false;
$newDirID = null;
$p = null;
foreach ($mydir as $dir)
$basename = GoogleDriveFile::findByPathInDrive($directory);
if ($basename == false)
{
$p = $dir['basename'];
if ($dir['extension'] == $key)
$basename = GoogleDriveFile::createByPathInDrive($directory);
}
$googleDriveFile = GoogleDriveFile::findByPath($directory);
if ($googleDriveFile == null)
{
$googleDriveFile = new GoogleDriveFile();
$googleDriveFile->id = $basename;
$googleDriveFile->type = 'directory';
$googleDriveFile->rank_permission = $value['rank'];
$googleDriveFile->job_permission = [];
$googleDriveFile->user_permission = [];
$googleDriveFile->path = $directory;
$name = explode('/',$directory);
$googleDriveFile->name = $name[count($name)-1];
$googleDriveFile->save();
}
else
{
if ($googleDriveFile->id != $basename)
{
$found = true;
$newDirID = $dir['basename'];
break;
$googleDriveFile->id = $basename;
$googleDriveFile->save();
}
}
if (!$found)
{
array_push($error,'Dossier 🔒.'.$key.' manquant... Le dossier a été créer');
\Storage::cloud()->createDir($parent.'/🔒.'.$key);
$tempdir = $this->listLockDirectory($parent);
$p = $tempdir->where('extension','=',$key)->first()['basename'];
}
if ($value != [])
{
$this->checkStructure($value,$p,$newDirID,$error);
}
}
}
public function editPermission($folder)
{
$f = GoogleDriveFile::find($folder);
if ($f == null)
{
$metadata = \Storage::cloud()->getMetadata($folder);
$f = new GoogleDriveFile();
$f->id = $folder;
$f->type = 'directory';
$f->name = $metadata['name'];
$f->rank_permission = [1 => 'rwp'];
$f->job_permission = [];
$f->user_permission = [];
$f->path = $this->recreatePath($folder);
$f->save();
}
return view('admin.files.Google Drive.permission',['dir' => $f]);
}
public function getFileStructure()
{
return collect([
'Privé' => [
'Cadet' => [],
'ETAMAS' => [],
'Officier' => [],
'Staff' => [
'Guide' => []
]
'🔒.Privé' => [
'rank' => [1 => 'rwp'],
'job' => [],
'user' => []
],
'Publique' => [
'Fichier' => [],
'Image' => []
'🔒.Privé/🔒.Cadet' => [
'rank' => [1 => 'rwp'],
'job' => [],
'user' => []
],
'🔒.Privé/🔒.ETAMAS' => [
'rank' => [1 => 'rwp'],
'job' => [],
'user' => []
],
'🔒.Privé/🔒.Officier' => [
'rank' => [1 => 'rwp'],
'job' => [],
'user' => []
],
'🔒.Privé/🔒.Staff' => [
'rank' => [1 => 'rwp'],
'job' => [],
'user' => []
],
'🔒.Privé/🔒.Staff/🔒.Guide' => [
'rank' => [1 => 'rwp'],
'job' => [],
'user' => []
],
'🔒.Publique' => [
'rank' => [1 => 'rwp',0 => 'r'],
'job' => [],
'user' => []
],
'🔒.Publique/🔒.Fichier' => [
'rank' => [1 => 'rwp',0 => 'r'],
'job' => [],
'user' => []
],
'🔒.Publique/🔒.Image' => [
'rank' => [1 => 'rwp',0 => 'r'],
'job' => [],
'user' => []
],
'🔒.Système' => [
'rank' => [1 => 'rwp'],
'job' => [],
'user' => []
],
'🔒.Système/🔒.Fichier' => [
'rank' => [1 => 'rwp'],
'job' => [],
'user' => []
],
'🔒.Système/🔒.Image' => [
'rank' => [1 => 'rwp'],
'job' => [],
'user' => []
],
'🔒.Système/🔒.Image/🔒.Nouvelle' => [
'rank' => [1 => 'rwp'],
'job' => [],
'user' => []
],
'🔒.Système/🔒.Image/🔒.Profil' => [
'rank' => [1 => 'rwp'],
'job' => [],
'user' => []
],
'Système' => [
'Fichier' => [],
'Image' => [
'Nouvelle' => [],
'Profil' => []
]
]
]);
}
@@ -340,24 +412,70 @@ class GoogleDriveController extends Controller
return $dir;
}
public function checkConfig()
public function recreatePath($folder)
{
$configNull = (\Crypt::decryptString(\App\Config::getData('GOOGLE_DRIVE_CLIENT_ID')) != "" && \Crypt::decryptString(\App\Config::getData('GOOGLE_DRIVE_CLIENT_SECRET')) != "" && \Crypt::decryptString(\App\Config::getData('GOOGLE_DRIVE_REFRESH_TOKEN')) != "" && \Crypt::decryptString(\App\Config::getData('GOOGLE_DRIVE_FOLDER_ID')) != "");
$configOk = true;
if ($configNull)
$path = [];
$name = [];
$directories = collect(json_decode($this->getPathArray(),true));
foreach ($directories as $dir)
{
try {
$contents = collect(Storage::cloud()->listContents("/", false));
}
catch (\Exception $e)
$path[$dir['basename']] = $dir['dirname'];
$name[$dir['basename']] = $dir['name'];
}
$realPath = $name[$folder];
$foo = $folder;
while ($foo != "")
{
$bar = explode('/',$path[$foo]);
$foo = $bar[count($bar)-1];
if ($foo != "")
{
$configOk = false;
$realPath = $name[$foo].'/'.$realPath;
}
}
return $realPath;
}
return $configNull && $configOk;
public function editPermissionModal($folder,$subject,$id)
{
$dir = GoogleDriveFile::find($folder);
$foo = null;
$perm = null;
if ($subject == 'rank')
{
if ($id == 0)
{
$foo = new \App\Rank();
$foo->name = "Utilisateur non authentifié";
$foo->id = 0;
if (isset($dir->rank_permission[$id]))
{
$perm = $dir->rank_permission[$id];
}
else
{
$perm = "";
}
}
else
{
$foo = \App\Rank::find($id);
$perm = $dir->rank_permission[$id];
}
}
elseif ($subject == 'job')
{
$foo = \App\Job::find($id);
$perm = $dir->job_permission[$id];
}
else
{
$foo = \App\User::find($id);
$perm = $dir->user_permission[$id];
}
return view('admin.files.Google Drive.permission.edit',['folder' => $dir,'subject' => $foo,'perm' => $perm,'s' => $subject]);
}
}