diff --git a/app/Http/Controllers/Common/Uploads.php b/app/Http/Controllers/Common/Uploads.php index 06c1213f0..98274b149 100644 --- a/app/Http/Controllers/Common/Uploads.php +++ b/app/Http/Controllers/Common/Uploads.php @@ -28,6 +28,55 @@ class Uploads extends Controller return response()->file($path); } + /** + * Get the specified resource. + * + * @param $id + * @return mixed + */ + public function show($id, Request $request) + { + $file = false; + $options = false; + $column_name = 'attachment'; + + if ($request->has('column_name')) { + $column_name = $request->get('column_name'); + } + + if ($request->has('page')) { + $options = [ + 'page' => $request->get('page'), + 'key' => $request->get('key'), + ]; + } + + $media = Media::find($id); + + // Get file path + if (!$path = $this->getPath($media)) { + return response()->json([ + 'success' => false, + 'error' => true, + 'data' => [], + 'message' => 'null', + 'html' => '', + ]); + } + + $file = $media; + + $html = view('partials.media.file', compact('file', 'column_name', 'options'))->render(); + + return response()->json([ + 'success' => true, + 'error' => false, + 'data' => [], + 'message' => 'null', + 'html' => $html, + ]); + } + /** * Download the specified resource. * diff --git a/app/Listeners/Updates/V13/Version1311.php b/app/Listeners/Updates/V13/Version1311.php new file mode 100644 index 000000000..114165eb8 --- /dev/null +++ b/app/Listeners/Updates/V13/Version1311.php @@ -0,0 +1,62 @@ +check($event)) { + return; + } + + $this->updatePermissions(); + + // Update database + Artisan::call('migrate', ['--force' => true]); + } + + protected function updatePermissions() + { + $permissions = []; + + // Common Uploads + $permissions[] = Permission::firstOrCreate([ + 'name' => 'read-common-uploads', + 'display_name' => 'Read Common Uploads', + 'description' => 'Read Common Uploads', + ]); + + // Attach permission to roles + $roles = Role::all(); + + foreach ($roles as $role) { + $allowed = ['admin', 'manager']; + + if (!in_array($role->name, $allowed)) { + continue; + } + + foreach ($permissions as $permission) { + $role->attachPermission($permission); + } + } + } +} diff --git a/app/Providers/EventServiceProvider.php b/app/Providers/EventServiceProvider.php index 86267942b..b5732a2fa 100644 --- a/app/Providers/EventServiceProvider.php +++ b/app/Providers/EventServiceProvider.php @@ -33,6 +33,7 @@ class EventServiceProvider extends ServiceProvider 'App\Listeners\Updates\V13\Version135', 'App\Listeners\Updates\V13\Version138', 'App\Listeners\Updates\V13\Version139', + 'App\Listeners\Updates\V13\Version1311', ], 'Illuminate\Auth\Events\Login' => [ 'App\Listeners\Auth\Login', diff --git a/database/seeds/Roles.php b/database/seeds/Roles.php index 088d369ac..3c7a0b8be 100644 --- a/database/seeds/Roles.php +++ b/database/seeds/Roles.php @@ -36,7 +36,7 @@ class Roles extends Seeder 'common-companies' => 'c,r,u,d', 'common-import' => 'c', 'common-items' => 'c,r,u,d', - 'common-uploads' => 'd', + 'common-uploads' => 'r,d', 'common-notifications' => 'c,r,u,d', 'incomes-invoices' => 'c,r,u,d', 'incomes-revenues' => 'c,r,u,d', @@ -76,6 +76,7 @@ class Roles extends Seeder 'common-companies' => 'c,r,u,d', 'common-import' => 'c', 'common-items' => 'c,r,u,d', + 'common-uploads' => 'r', 'common-notifications' => 'c,r,u,d', 'incomes-invoices' => 'c,r,u,d', 'incomes-revenues' => 'c,r,u,d', diff --git a/public/css/app.css b/public/css/app.css index df8840fd0..ea1fb1398 100644 --- a/public/css/app.css +++ b/public/css/app.css @@ -933,3 +933,14 @@ input[type="number"] { .table-report { overflow-x: auto !important; } + +.mailbox-attachment-file-name { + white-space: nowrap; + width: 100%; + overflow: hidden; + text-overflow: ellipsis; +} + +.mailbox-attachment-download { + margin-right: 5px; +} diff --git a/resources/views/auth/users/edit.blade.php b/resources/views/auth/users/edit.blade.php index 0b8bd9b5f..d2e081b6f 100644 --- a/resources/views/auth/users/edit.blade.php +++ b/resources/views/auth/users/edit.blade.php @@ -86,31 +86,30 @@ text : '{{ trans('general.form.select.file') }}', style : 'btn-default', @if($user->picture) - placeholder : 'picture->basename; ?>' + placeholder : '{{ $user->picture->basename }}' @else placeholder : '{{ trans('general.form.no_file_selected') }}' @endif }); @if($user->picture) - picture_html = ''; - picture_html += ' '; - picture_html += ' '; - picture_html += ' {{ $user->picture->basename }}'; - picture_html += ' '; - picture_html += ' '; - picture_html += ' {!! Form::open(['id' => 'picture-' . $user->picture->id, 'method' => 'DELETE', 'url' => [url('uploads/' . $user->picture->id)], 'style' => 'display:inline']) !!}'; - picture_html += ' '; - picture_html += ' '; - picture_html += ' '; - picture_html += ' {!! Form::close() !!}'; - picture_html += ''; - - $('.fancy-file .fake-file').append(picture_html); - - $(document).on('click', '#remove-picture', function (e) { - confirmDelete("#picture-{!! $user->picture->id !!}", "{!! trans('general.attachment') !!}", "{!! trans('general.delete_confirm', ['name' => '' . $user->picture->basename . '', 'type' => strtolower(trans('general.attachment'))]) !!}", "{!! trans('general.cancel') !!}", "{!! trans('general.delete') !!}"); - }); + $.ajax({ + url: '{{ url('uploads/' . $user->picture->id . '/show') }}', + type: 'GET', + data: {column_name: 'picture'}, + dataType: 'JSON', + success: function(json) { + if (json['success']) { + $('.fancy-file').after(json['html']); + } + } + }); + + @permission('delete-common-uploads') + $(document).on('click', '#remove-picture', function (e) { + confirmDelete("#picture-{!! $user->picture->id !!}", "{!! trans('general.attachment') !!}", "{!! trans('general.delete_confirm', ['name' => '' . $user->picture->basename . '', 'type' => strtolower(trans('general.attachment'))]) !!}", "{!! trans('general.cancel') !!}", "{!! trans('general.delete') !!}"); + }); + @endpermission @endif @endif diff --git a/resources/views/common/companies/edit.blade.php b/resources/views/common/companies/edit.blade.php index 29defd177..54d424874 100644 --- a/resources/views/common/companies/edit.blade.php +++ b/resources/views/common/companies/edit.blade.php @@ -63,31 +63,30 @@ text : '{{ trans('general.form.select.file') }}', style : 'btn-default', @if($company->company_logo) - placeholder : 'company_logo->basename; ?>' + placeholder : '{{ $company->company_logo->basename }}' @else placeholder : '{{ trans('general.form.no_file_selected') }}' @endif }); @if($company->company_logo) - attachment_html = ''; - attachment_html += ' '; - attachment_html += ' '; - attachment_html += ' {{ $company->company_logo->basename }}'; - attachment_html += ' '; - attachment_html += ' '; - attachment_html += ' {!! Form::open(['id' => 'attachment-' . $company->company_logo->id, 'method' => 'DELETE', 'url' => [url('uploads/' . $company->company_logo->id)], 'style' => 'display:inline']) !!}'; - attachment_html += ' '; - attachment_html += ' '; - attachment_html += ' '; - attachment_html += ' {!! Form::close() !!}'; - attachment_html += ''; + $.ajax({ + url: '{{ url('uploads/' . $company->company_logo->id . '/show') }}', + type: 'GET', + data: {column_name: 'attachment'}, + dataType: 'JSON', + success: function(json) { + if (json['success']) { + $('.fancy-file').after(json['html']); + } + } + }); - $('.fancy-file .fake-file').append(attachment_html); - - $(document).on('click', '#remove-attachment', function (e) { - confirmDelete("#attachment-{!! $company->company_logo->id !!}", "{!! trans('general.attachment') !!}", "{!! trans('general.delete_confirm', ['name' => '' . $company->company_logo->basename . '', 'type' => strtolower(trans('general.attachment'))]) !!}", "{!! trans('general.cancel') !!}", "{!! trans('general.delete') !!}"); - }); + @permission('delete-common-uploads') + $(document).on('click', '#remove-attachment', function (e) { + confirmDelete("#attachment-{!! $company->company_logo->id !!}", "{!! trans('general.attachment') !!}", "{!! trans('general.delete_confirm', ['name' => '' . $company->company_logo->basename . '', 'type' => strtolower(trans('general.attachment'))]) !!}", "{!! trans('general.cancel') !!}", "{!! trans('general.delete') !!}"); + }); + @endpermission @endif }); diff --git a/resources/views/common/items/edit.blade.php b/resources/views/common/items/edit.blade.php index 3ecf81db1..2403c6b27 100644 --- a/resources/views/common/items/edit.blade.php +++ b/resources/views/common/items/edit.blade.php @@ -110,31 +110,30 @@ text : '{{ trans('general.form.select.file') }}', style : 'btn-default', @if($item->picture) - placeholder : 'picture->basename; ?>' + placeholder : '{{ $item->picture->basename }}' @else placeholder : '{{ trans('general.form.no_file_selected') }}' @endif }); @if($item->picture) - picture_html = ''; - picture_html += ' '; - picture_html += ' '; - picture_html += ' {{ $item->picture->basename }}'; - picture_html += ' '; - picture_html += ' '; - picture_html += ' {!! Form::open(['id' => 'picture-' . $item->picture->id, 'method' => 'DELETE', 'url' => [url('uploads/' . $item->picture->id)], 'style' => 'display:inline']) !!}'; - picture_html += ' '; - picture_html += ' '; - picture_html += ' '; - picture_html += ' {!! Form::close() !!}'; - picture_html += ''; - - $('.fancy-file .fake-file').append(picture_html); - - $(document).on('click', '#remove-picture', function (e) { - confirmDelete("#picture-{!! $item->picture->id !!}", "{!! trans('general.attachment') !!}", "{!! trans('general.delete_confirm', ['name' => '' . $item->picture->basename . '', 'type' => strtolower(trans('general.attachment'))]) !!}", "{!! trans('general.cancel') !!}", "{!! trans('general.delete') !!}"); - }); + $.ajax({ + url: '{{ url('uploads/' . $item->picture->id . '/show') }}', + type: 'GET', + data: {column_name: 'picture'}, + dataType: 'JSON', + success: function(json) { + if (json['success']) { + $('.fancy-file').after(json['html']); + } + } + }); + + @permission('delete-common-uploads') + $(document).on('click', '#remove-picture', function (e) { + confirmDelete("#picture-{!! $item->picture->id !!}", "{!! trans('general.attachment') !!}", "{!! trans('general.delete_confirm', ['name' => '' . $item->picture->basename . '', 'type' => strtolower(trans('general.attachment'))]) !!}", "{!! trans('general.cancel') !!}", "{!! trans('general.delete') !!}"); + }); + @endpermission @endif }); diff --git a/resources/views/customers/profile/edit.blade.php b/resources/views/customers/profile/edit.blade.php index ba5464bcf..1df388a87 100644 --- a/resources/views/customers/profile/edit.blade.php +++ b/resources/views/customers/profile/edit.blade.php @@ -64,31 +64,30 @@ text : '{{ trans('general.form.select.file') }}', style : 'btn-default', @if($user->picture) - placeholder : 'picture->basename; ?>' + placeholder : '{{ $user->picture->basename }}' @else placeholder : '{{ trans('general.form.no_file_selected') }}' @endif }); @if($user->picture) - picture_html = ''; - picture_html += ' '; - picture_html += ' '; - picture_html += ' {{ $user->picture->basename }}'; - picture_html += ' '; - picture_html += ' '; - picture_html += ' {!! Form::open(['id' => 'picture-' . $user->picture->id, 'method' => 'DELETE', 'url' => [url('uploads/' . $user->picture->id)], 'style' => 'display:inline']) !!}'; - picture_html += ' '; - picture_html += ' '; - picture_html += ' '; - picture_html += ' {!! Form::close() !!}'; - picture_html += ''; + $.ajax({ + url: '{{ url('uploads/' . $user->picture->id . '/show') }}', + type: 'GET', + data: {column_name: 'picture'}, + dataType: 'JSON', + success: function(json) { + if (json['success']) { + $('.fancy-file').after(json['html']); + } + } + }); - $('.fancy-file .fake-file').append(picture_html); - - $(document).on('click', '#remove-picture', function (e) { - confirmDelete("#picture-{!! $user->picture->id !!}", "{!! trans('general.attachment') !!}", "{!! trans('general.delete_confirm', ['name' => '' . $user->picture->basename . '', 'type' => strtolower(trans('general.attachment'))]) !!}", "{!! trans('general.cancel') !!}", "{!! trans('general.delete') !!}"); - }); + @permission('delete-common-uploads') + $(document).on('click', '#remove-picture', function (e) { + confirmDelete("#picture-{!! $user->picture->id !!}", "{!! trans('general.attachment') !!}", "{!! trans('general.delete_confirm', ['name' => '' . $user->picture->basename . '', 'type' => strtolower(trans('general.attachment'))]) !!}", "{!! trans('general.cancel') !!}", "{!! trans('general.delete') !!}"); + }); + @endpermission @endif }); diff --git a/resources/views/expenses/bills/edit.blade.php b/resources/views/expenses/bills/edit.blade.php index 736cdf228..c90eaa2a8 100644 --- a/resources/views/expenses/bills/edit.blade.php +++ b/resources/views/expenses/bills/edit.blade.php @@ -257,27 +257,24 @@ text : '{{ trans('general.form.select.file') }}', style : 'btn-default', @if($bill->attachment) - placeholder : 'attachment->basename; ?>' + placeholder : '{{ $bill->attachment->basename }}' @else placeholder : '{{ trans('general.form.no_file_selected') }}' @endif }); @if($bill->attachment) - attachment_html = ''; - attachment_html += ' '; - attachment_html += ' '; - attachment_html += ' {{ $bill->attachment->basename }}'; - attachment_html += ' '; - attachment_html += ' '; - attachment_html += ' {!! Form::open(['id' => 'attachment-' . $bill->attachment->id, 'method' => 'DELETE', 'url' => [url('uploads/' . $bill->attachment->id)], 'style' => 'display:inline']) !!}'; - attachment_html += ' '; - attachment_html += ' '; - attachment_html += ' '; - attachment_html += ' {!! Form::close() !!}'; - attachment_html += ''; - - $('.fancy-file .fake-file').append(attachment_html); + $.ajax({ + url: '{{ url('uploads/' . $bill->attachment->id . '/show') }}', + type: 'GET', + data: {column_name: 'attachment'}, + dataType: 'JSON', + success: function(json) { + if (json['success']) { + $('.fancy-file').after(json['html']); + } + } + }); @endif @if(old('item')) @@ -285,11 +282,13 @@ @endif }); + @permission('delete-common-uploads') @if($bill->attachment) $(document).on('click', '#remove-attachment', function (e) { confirmDelete("#attachment-{!! $bill->attachment->id !!}", "{!! trans('general.attachment') !!}", "{!! trans('general.delete_confirm', ['name' => '' . $bill->attachment->basename . '', 'type' => strtolower(trans('general.attachment'))]) !!}", "{!! trans('general.cancel') !!}", "{!! trans('general.delete') !!}"); }); @endif + @endpermission $(document).on('click', '#button-add-item', function (e) { $.ajax({ diff --git a/resources/views/expenses/bills/show.blade.php b/resources/views/expenses/bills/show.blade.php index 489feb93f..7d9cb3cdc 100644 --- a/resources/views/expenses/bills/show.blade.php +++ b/resources/views/expenses/bills/show.blade.php @@ -311,23 +311,8 @@ @if($bill->attachment) - - - - {{ $bill->attachment->basename }} - - - {!! Form::open([ - 'id' => 'attachment-' . $bill->attachment->id, - 'method' => 'DELETE', - 'url' => [url('uploads/' . $bill->attachment->id)], - 'style' => 'display:inline' - ]) !!} - - - - {!! Form::close() !!} - + @php $file = $bill->attachment; @endphp + @include('partials.media.file') @endif @@ -446,11 +431,13 @@ @push('scripts') diff --git a/resources/views/incomes/invoices/edit.blade.php b/resources/views/incomes/invoices/edit.blade.php index c62194d9d..2805c057a 100644 --- a/resources/views/incomes/invoices/edit.blade.php +++ b/resources/views/incomes/invoices/edit.blade.php @@ -257,27 +257,24 @@ text : '{{ trans('general.form.select.file') }}', style : 'btn-default', @if($invoice->attachment) - placeholder : 'attachment->basename; ?>' + placeholder : '{{ $invoice->attachment->basename }}' @else placeholder : '{{ trans('general.form.no_file_selected') }}' @endif }); @if($invoice->attachment) - attachment_html = ''; - attachment_html += ' '; - attachment_html += ' '; - attachment_html += ' {{ $invoice->attachment->basename }}'; - attachment_html += ' '; - attachment_html += ' '; - attachment_html += ' {!! Form::open(['id' => 'attachment-' . $invoice->attachment->id, 'method' => 'DELETE', 'url' => [url('uploads/' . $invoice->attachment->id)], 'style' => 'display:inline']) !!}'; - attachment_html += ' '; - attachment_html += ' '; - attachment_html += ' '; - attachment_html += ' {!! Form::close() !!}'; - attachment_html += ''; - - $('.fancy-file .fake-file').append(attachment_html); + $.ajax({ + url: '{{ url('uploads/' . $invoice->attachment->id . '/show') }}', + type: 'GET', + data: {column_name: 'attachment'}, + dataType: 'JSON', + success: function(json) { + if (json['success']) { + $('.fancy-file').after(json['html']); + } + } + }); @endif @if(old('item')) @@ -285,11 +282,13 @@ @endif }); + @permission('delete-common-uploads') @if($invoice->attachment) $(document).on('click', '#remove-attachment', function (e) { confirmDelete("#attachment-{!! $invoice->attachment->id !!}", "{!! trans('general.attachment') !!}", "{!! trans('general.delete_confirm', ['name' => '' . $invoice->attachment->basename . '', 'type' => strtolower(trans('general.attachment'))]) !!}", "{!! trans('general.cancel') !!}", "{!! trans('general.delete') !!}"); }); @endif + @endpermission $(document).on('click', '#button-add-item', function (e) { $.ajax({ diff --git a/resources/views/incomes/invoices/show.blade.php b/resources/views/incomes/invoices/show.blade.php index ca230a31f..368941448 100644 --- a/resources/views/incomes/invoices/show.blade.php +++ b/resources/views/incomes/invoices/show.blade.php @@ -339,23 +339,8 @@ @if($invoice->attachment) - - - - {{ $invoice->attachment->basename }} - - - {!! Form::open([ - 'id' => 'attachment-' . $invoice->attachment->id, - 'method' => 'DELETE', - 'url' => [url('uploads/' . $invoice->attachment->id)], - 'style' => 'display:inline' - ]) !!} - - - - {!! Form::close() !!} - + @php $file = $invoice->attachment; @endphp + @include('partials.media.file') @endif @@ -474,11 +459,13 @@ @push('scripts') diff --git a/routes/web.php b/routes/web.php index 7874cb64f..eaa8031c4 100644 --- a/routes/web.php +++ b/routes/web.php @@ -4,6 +4,7 @@ Route::group(['middleware' => 'language'], function () { Route::group(['middleware' => 'auth'], function () { Route::group(['prefix' => 'uploads'], function () { Route::get('{id}', 'Common\Uploads@get'); + Route::get('{id}/show', 'Common\Uploads@show'); Route::get('{id}/download', 'Common\Uploads@download'); });