mirror of
https://github.com/BookStackApp/BookStack.git
synced 2024-10-01 05:36:00 +00:00
File upload deletion complete & added extension handling
Also fixed issue with file editing on JS side
This commit is contained in:
parent
867fc8be64
commit
7ee695d74a
10
app/File.php
10
app/File.php
@ -5,6 +5,16 @@ class File extends Ownable
|
|||||||
{
|
{
|
||||||
protected $fillable = ['name', 'order'];
|
protected $fillable = ['name', 'order'];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the downloadable file name for this upload.
|
||||||
|
* @return mixed|string
|
||||||
|
*/
|
||||||
|
public function getFileName()
|
||||||
|
{
|
||||||
|
if (str_contains($this->name, '.')) return $this->name;
|
||||||
|
return $this->name . '.' . $this->extension;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the page this file was uploaded to.
|
* Get the page this file was uploaded to.
|
||||||
* @return Page
|
* @return Page
|
||||||
|
@ -196,7 +196,7 @@ class FileController extends Controller
|
|||||||
$fileContents = $this->fileService->getFile($file);
|
$fileContents = $this->fileService->getFile($file);
|
||||||
return response($fileContents, 200, [
|
return response($fileContents, 200, [
|
||||||
'Content-Type' => 'application/octet-stream',
|
'Content-Type' => 'application/octet-stream',
|
||||||
'Content-Disposition' => 'attachment; filename="'. $file->name .'"'
|
'Content-Disposition' => 'attachment; filename="'. $file->getFileName() .'"'
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5,6 +5,7 @@ use BookStack\Book;
|
|||||||
use BookStack\Chapter;
|
use BookStack\Chapter;
|
||||||
use BookStack\Entity;
|
use BookStack\Entity;
|
||||||
use BookStack\Exceptions\NotFoundException;
|
use BookStack\Exceptions\NotFoundException;
|
||||||
|
use BookStack\Services\FileService;
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
use DOMDocument;
|
use DOMDocument;
|
||||||
use DOMXPath;
|
use DOMXPath;
|
||||||
@ -633,6 +634,13 @@ class PageRepo extends EntityRepo
|
|||||||
$page->revisions()->delete();
|
$page->revisions()->delete();
|
||||||
$page->permissions()->delete();
|
$page->permissions()->delete();
|
||||||
$this->permissionService->deleteJointPermissionsForEntity($page);
|
$this->permissionService->deleteJointPermissionsForEntity($page);
|
||||||
|
|
||||||
|
// Delete AttachedFiles
|
||||||
|
$fileService = app(FileService::class);
|
||||||
|
foreach ($page->files as $file) {
|
||||||
|
$fileService->deleteFile($file);
|
||||||
|
}
|
||||||
|
|
||||||
$page->delete();
|
$page->delete();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -38,6 +38,7 @@ class FileService extends UploadService
|
|||||||
$file = File::forceCreate([
|
$file = File::forceCreate([
|
||||||
'name' => $fileName,
|
'name' => $fileName,
|
||||||
'path' => $filePath,
|
'path' => $filePath,
|
||||||
|
'extension' => $uploadedFile->getClientOriginalExtension(),
|
||||||
'uploaded_to' => $page_id,
|
'uploaded_to' => $page_id,
|
||||||
'created_by' => user()->id,
|
'created_by' => user()->id,
|
||||||
'updated_by' => user()->id,
|
'updated_by' => user()->id,
|
||||||
@ -67,6 +68,7 @@ class FileService extends UploadService
|
|||||||
$file->name = $fileName;
|
$file->name = $fileName;
|
||||||
$file->path = $filePath;
|
$file->path = $filePath;
|
||||||
$file->external = false;
|
$file->external = false;
|
||||||
|
$file->extension = $uploadedFile->getClientOriginalExtension();
|
||||||
$file->save();
|
$file->save();
|
||||||
return $file;
|
return $file;
|
||||||
}
|
}
|
||||||
@ -85,6 +87,7 @@ class FileService extends UploadService
|
|||||||
'name' => $name,
|
'name' => $name,
|
||||||
'path' => $link,
|
'path' => $link,
|
||||||
'external' => true,
|
'external' => true,
|
||||||
|
'extension' => '',
|
||||||
'uploaded_to' => $page_id,
|
'uploaded_to' => $page_id,
|
||||||
'created_by' => user()->id,
|
'created_by' => user()->id,
|
||||||
'updated_by' => user()->id,
|
'updated_by' => user()->id,
|
||||||
|
@ -17,6 +17,7 @@ class CreateFilesTable extends Migration
|
|||||||
$table->increments('id');
|
$table->increments('id');
|
||||||
$table->string('name');
|
$table->string('name');
|
||||||
$table->string('path');
|
$table->string('path');
|
||||||
|
$table->string('extension', 20);
|
||||||
$table->integer('uploaded_to');
|
$table->integer('uploaded_to');
|
||||||
|
|
||||||
$table->boolean('external');
|
$table->boolean('external');
|
||||||
@ -59,16 +60,12 @@ class CreateFilesTable extends Migration
|
|||||||
{
|
{
|
||||||
Schema::dropIfExists('files');
|
Schema::dropIfExists('files');
|
||||||
|
|
||||||
// Get roles with permissions we need to change
|
|
||||||
$adminRoleId = DB::table('roles')->where('system_name', '=', 'admin')->first()->id;
|
|
||||||
|
|
||||||
// Create & attach new entity permissions
|
// Create & attach new entity permissions
|
||||||
$ops = ['Create All', 'Create Own', 'Update All', 'Update Own', 'Delete All', 'Delete Own'];
|
$ops = ['Create All', 'Create Own', 'Update All', 'Update Own', 'Delete All', 'Delete Own'];
|
||||||
$entity = 'File';
|
$entity = 'File';
|
||||||
foreach ($ops as $op) {
|
foreach ($ops as $op) {
|
||||||
$permName = strtolower($entity) . '-' . strtolower(str_replace(' ', '-', $op));
|
$permName = strtolower($entity) . '-' . strtolower(str_replace(' ', '-', $op));
|
||||||
$permission = DB::table('role_permissions')->where('name', '=', $permName)->get();
|
DB::table('role_permissions')->where('name', '=', $permName)->delete();
|
||||||
DB::table('permission_role')->where('permission_id', '=', $permission->id)->delete();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -674,6 +674,7 @@ module.exports = function (ngApp, events) {
|
|||||||
if ($scope.editFile && !file.external) {
|
if ($scope.editFile && !file.external) {
|
||||||
$scope.editFile.link = '';
|
$scope.editFile.link = '';
|
||||||
}
|
}
|
||||||
|
$scope.editFile = false;
|
||||||
events.emit('success', 'Attachment details updated');
|
events.emit('success', 'Attachment details updated');
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
@ -686,7 +687,7 @@ module.exports = function (ngApp, events) {
|
|||||||
*/
|
*/
|
||||||
function filesIndexOf(file) {
|
function filesIndexOf(file) {
|
||||||
for (let i = 0; i < $scope.files.length; i++) {
|
for (let i = 0; i < $scope.files.length; i++) {
|
||||||
if ($scope.files[i].id == file.id) return file.id;
|
if ($scope.files[i].id == file.id) return i;
|
||||||
}
|
}
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user