Demo user is no longer capable of uploading files.

This commit is contained in:
James Cole 2016-12-27 19:34:27 +01:00
parent 6c5499e848
commit 9ff9385c47
No known key found for this signature in database
GPG Key ID: C16961E655E74B5E
2 changed files with 30 additions and 6 deletions

View File

@ -368,14 +368,30 @@ class ImportController extends Controller
$content = $uploaded->fread($uploaded->getSize());
$contentEncrypted = Crypt::encrypt($content);
$disk = Storage::disk('upload');
$disk->put($newName, $contentEncrypted);
Log::debug('Uploaded file', ['name' => $upload->getClientOriginalName(), 'size' => $upload->getSize(), 'mime' => $upload->getClientMimeType()]);
// user is demo user, replace upload with prepared file.
if (auth()->user()->hasRole('demo')) {
$stubsDisk = Storage::disk('stubs');
$content = $stubsDisk->get('demo-import.csv');
$contentEncrypted = Crypt::encrypt($content);
$disk->put($newName, $contentEncrypted);
Log::debug('Replaced upload with demo file.');
// store configuration file's content into the job's configuration
// thing.
// otherwise, leave it empty.
if ($request->files->has('configuration_file')) {
// also set up prepared configuration.
$configuration = json_decode($stubsDisk->get('demo-configuration.json'), true);
$job->configuration = $configuration;
$job->save();
Log::debug('Set configuration for demo user', $configuration);
}
if (!auth()->user()->hasRole('demo')) {
// user is not demo, process original upload:
$disk->put($newName, $contentEncrypted);
Log::debug('Uploaded file', ['name' => $upload->getClientOriginalName(), 'size' => $upload->getSize(), 'mime' => $upload->getClientMimeType()]);
}
// store configuration file's content into the job's configuration thing. Otherwise, leave it empty.
// demo user's configuration upload is ignored completely.
if ($request->files->has('configuration_file') && !auth()->user()->hasRole('demo')) {
/** @var UploadedFile $configFile */
$configFile = $request->files->get('configuration_file');
Log::debug(
@ -394,6 +410,9 @@ class ImportController extends Controller
}
}
// if user is demo user, replace config with prepared config:
return redirect(route('import.configure', [$job->key]));
}

View File

@ -73,6 +73,11 @@ return [
'driver' => 'local',
'root' => base_path('resources/seeds'),
],
'stubs' => [
'driver' => 'local',
'root' => base_path('resources/stubs'),
],
'public' => [
'driver' => 'local',
'root' => storage_path('app/public'),