mirror of
https://gitlab.com/TheGamecraft/c-cms.git
synced 2026-04-21 10:49:10 -04:00
File systeme V3
This commit is contained in:
@@ -78,9 +78,4 @@ class AdminController extends Controller
|
||||
return view('admin.status.index',['alerts' => $alerts]);
|
||||
}
|
||||
|
||||
public function instruction()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -140,43 +140,9 @@ class ConfigController extends Controller
|
||||
|
||||
public function editfilesConfig()
|
||||
{
|
||||
$configList = [
|
||||
'cadet_list',
|
||||
];
|
||||
|
||||
$configListEncrypt = [
|
||||
'GOOGLE_DRIVE_CLIENT_ID',
|
||||
'GOOGLE_DRIVE_CLIENT_SECRET',
|
||||
'GOOGLE_DRIVE_REFRESH_TOKEN',
|
||||
'GOOGLE_DRIVE_FOLDER_ID'
|
||||
];
|
||||
|
||||
if (\request('is_active') == 'on')
|
||||
if (\request()->file('nominativeList') != null)
|
||||
{
|
||||
$config = \App\Config::find('is_Google_Drive_enabled');
|
||||
$config->data = ['true'];
|
||||
$config->save();
|
||||
}
|
||||
else
|
||||
{
|
||||
$config = \App\Config::find('is_Google_Drive_enabled');
|
||||
$config->data = ['false'];
|
||||
$config->save();
|
||||
}
|
||||
|
||||
|
||||
foreach ($configList as $configName)
|
||||
{
|
||||
$config = \App\Config::find($configName);
|
||||
$config->data = [\request($configName)];
|
||||
$config->save();
|
||||
}
|
||||
|
||||
foreach ($configListEncrypt as $configName)
|
||||
{
|
||||
$config = \App\Config::find($configName);
|
||||
$config->data = [\Crypt::encryptString(\request($configName))];
|
||||
$config->save();
|
||||
\Storage::putFileAs('Systeme/Fichier',\request()->file('nominativeList'),'ListeNominative.pdf');
|
||||
}
|
||||
|
||||
clog('edit','success','a modifié la configuration des fichiers');
|
||||
|
||||
@@ -71,7 +71,7 @@ class CourseController extends Controller
|
||||
{
|
||||
$name = $user->fullname();
|
||||
}
|
||||
return view('admin.course.show',['course' => $course,'username' => $name,'lessonPlanDir' => \App\GoogleDriveFile::findByPath('.Systeme/.Fichier/.PlanDeCours')->id]);
|
||||
return view('admin.course.show',['course' => $course,'username' => $name]);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -136,31 +136,21 @@ class CourseController extends Controller
|
||||
public function updateLessonPlan(Request $request, $id)
|
||||
{
|
||||
$course = Course::findOrFail($id);
|
||||
$name = $course->ocom.'_'.$course->instructor().'_'.$course->event->date_begin.'_'.'v'.date('c').'.'.\request()->file('file')->getClientOriginalExtension();
|
||||
$name = urlencode($name);
|
||||
$dirID = \App\GoogleDriveFile::findByPath('.Systeme/.Fichier/.PlanDeCours')->id;
|
||||
$name = $course->ocom.'_'.$course->instructor().'_'.date('c',strtotime($course->event->date_begin)).'.'.\request()->file('file')->getClientOriginalExtension();
|
||||
$dirID = 'Systeme/Fichier/PlanDeCours';
|
||||
|
||||
if ($course->lessonPlan != null)
|
||||
{
|
||||
$lessonPlan = $course->lessonPlan;
|
||||
$contents = collect(\Storage::cloud()->listContents($dirID, false));
|
||||
|
||||
$file = $contents
|
||||
->where('type', '=', 'file')
|
||||
->where('filename', '=', pathinfo($course->lessonPlan->file, PATHINFO_FILENAME))
|
||||
->where('extension', '=', pathinfo($course->lessonPlan->file, PATHINFO_EXTENSION))
|
||||
->first(); // there can be duplicate file names!
|
||||
\Storage::cloud()->delete($file['path']);
|
||||
}
|
||||
else
|
||||
{
|
||||
$lessonPlan = new \App\LessonPlan();
|
||||
}
|
||||
\Storage::cloud()->putFileAs($dirID,\request()->file('file'),$name);
|
||||
$metadata = \Storage::cloud()->getMetadata($dirID.'/'.$name);
|
||||
\Storage::putFileAs($dirID,\request()->file('file'),$name);
|
||||
|
||||
$lessonPlan->user_id = \Auth::user()->id;
|
||||
$lessonPlan->file = $metadata['name'];
|
||||
$lessonPlan->file = $name;
|
||||
$lessonPlan->course_id = $course->id;
|
||||
$lessonPlan->desc = "";
|
||||
$lessonPlan->comment = "";
|
||||
@@ -169,6 +159,18 @@ class CourseController extends Controller
|
||||
return redirect()->back();
|
||||
}
|
||||
|
||||
public function downloadLessonPlan($name)
|
||||
{
|
||||
if (\Storage::exists('Systeme/Fichier/PlanDeCours/'.$name))
|
||||
{
|
||||
return \Storage::download('Systeme/Fichier/PlanDeCours/'.$name);
|
||||
}
|
||||
else
|
||||
{
|
||||
abort(404);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*
|
||||
|
||||
@@ -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 !');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -57,6 +57,8 @@ class JobController extends Controller
|
||||
$job->permissions = json_encode($tpermission);
|
||||
$job->save();
|
||||
|
||||
$job->updateACLRules();
|
||||
|
||||
clog('add','success','Poste ajouté avec succès');
|
||||
return redirect('/admin/config/jobs')->with('success','Poste ajouté avec succès');
|
||||
}
|
||||
@@ -112,6 +114,8 @@ class JobController extends Controller
|
||||
$job->permissions = json_encode($tpermission);
|
||||
$job->save();
|
||||
|
||||
$job->updateACLRules();
|
||||
|
||||
clog('add','success','Poste modifié avec succès');
|
||||
return redirect('/admin/config/jobs')->with('success','Poste modifié avec succès');
|
||||
}
|
||||
|
||||
@@ -52,6 +52,8 @@ class RankController extends Controller
|
||||
$r->permissions = json_encode($tpermission);
|
||||
$r->save();
|
||||
|
||||
$r->updateACLRules();
|
||||
|
||||
clog('add','success','Grade ajouté avec succès');
|
||||
return redirect('/admin/config/ranks')->with('success','Grade ajouté avec succès');
|
||||
}
|
||||
@@ -99,10 +101,11 @@ class RankController extends Controller
|
||||
$tkey = $perm->ckey;
|
||||
$tpermission[$tkey] = $request->$tkey;
|
||||
}
|
||||
|
||||
$r->permissions = json_encode($tpermission);
|
||||
$r->save();
|
||||
|
||||
$r->updateACLRules();
|
||||
|
||||
clog('edit','success','Grade modifié avec succès');
|
||||
return redirect('/admin/config/ranks')->with('success','Grade modifié avec succès');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user