Permission update

This commit is contained in:
George Frederick "Buzz" Beurling
2020-03-22 20:00:23 -04:00
parent 1e3ae2fbbb
commit ae3be2b977
27 changed files with 344 additions and 655 deletions

View File

@@ -238,9 +238,40 @@ class GoogleDriveFile extends Model
public static function getPermForUser($folder,$user,$perm = 'r')
{
if ($folder == '' || $folder == "root")
{
if ($user->p('file_manage') == 1)
{
return true;
}
else
{
return false;
}
}
$dir = \App\GoogleDriveFile::find($folder);
if ($dir == null)
{
$path = GoogleDriveFile::getPathFolder($folder);
$exploderPath = explode('/',$path);
for ($i = count($exploderPath)-1; $i >= 0; $i--)
{
$dir = \App\GoogleDriveFile::find($exploderPath[$i]);
if ($dir != null)
{
$metaData = \Storage::cloud()->getMetadata($folder);
$googleDriveFile = new GoogleDriveFile();
$googleDriveFile->id = $folder;
$googleDriveFile->type = 'directory';
$googleDriveFile->name = $metaData['name'];
$googleDriveFile->path = self::recreatePath($folder);
$googleDriveFile->rank_permission = $dir->rank_permission;
$googleDriveFile->job_permission = $dir->job_permission;
$googleDriveFile->user_permission = $dir->user_permission;
$googleDriveFile->save();
return $dir->canUser($user,$perm);
}
}
return false;
}
else
@@ -253,4 +284,47 @@ class GoogleDriveFile extends Model
{
return self::getPermForUser($folder,\Auth::user(),$perm);
}
public static function getPathFolder($folder)
{
$allDir = \Storage::cloud()->allDirectories();
foreach ($allDir as $dir)
{
$exploderDir = explode('/',$dir);
if ($exploderDir[count($exploderDir)-1] == $folder)
{
return $dir;
}
}
}
public static function recreatePath($folder)
{
$path = [];
$name = [];
$directories = collect(json_decode(self::getPathArray(),true));
foreach ($directories as $dir)
{
$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 != "")
{
$realPath = $name[$foo].'/'.$realPath;
}
}
return $realPath;
}
public static function getPathArray()
{
$contents = collect(Storage::cloud()->listContents('/', true));
return json_encode($contents->where('type', '=', 'dir'));
}
}