A free open source IT asset/license management system
Merge branch 'develop'
snipeb29d7beb3afc
diff --cc app/Http/Controllers/AssetsController.phpindex 827f0af061,c084a7cc80..6e2163e5cb--- a/app/Http/Controllers/AssetsController.php+++ b/app/Http/Controllers/AssetsController.php@@@ -454,21 -379,8 +379,8 @@@ class AssetsController extends Controllif ($asset->save()) {// Redirect to the new asset page-- $logaction = new Actionlog();- $logaction->item_type = Asset::class;- $logaction->item_id = $asset->id;- $logaction->created_at = date("Y-m-d H:i:s");- if (Input::has('rtd_location_id')) {- $logaction->location_id = e(Input::get('rtd_location_id'));- }- $logaction->user_id = Auth::user()->id;- $log = $logaction->logaction('update');---- \Session::flash('success', trans('admin/hardware/message.update.success'));+ \Session::flash('success', trans('admin/hardware/message.update.success'));- return response()->json(['redirect_url' => route("hardware.show", $assetId)]);+ return response()->json(['redirect_url' => route("view/hardware", $assetId)]);}\Input::flash();\Session::flash('errors', $asset->getErrors());@@@ -498,22 -410,10 +410,17 @@@->where('id', $asset->id)->update(array('assigned_to' => null));-$asset->delete();+ $logaction = new Actionlog();+ $logaction->item_type = Asset::class;+ $logaction->item_id = $asset->id;+ $logaction->created_at = date("Y-m-d H:i:s");+ $logaction->user_id = Auth::user()->id;+ $log = $logaction->logaction('deleted');+// Redirect to the asset management page- return redirect()->to('hardware')->with('success', trans('admin/hardware/message.delete.success'));----+ return redirect()->route('hardware.index')->with('success', trans('admin/hardware/message.delete.success'));}/**diff --cc app/Http/Controllers/LicensesController.phpindex 4e5bb67926,8ec893fa32..2f14a72829--- a/app/Http/Controllers/LicensesController.php+++ b/app/Http/Controllers/LicensesController.php@@@ -746,28 -436,18 +436,21 @@@ class LicensesController extends Contro* @author [A. Gianotto] [<[email protected]>]* @since [v1.0]* @param int $licenseId- * @return View- */- public function getView($licenseId = null)+ * @return \Illuminate\Contracts\View\View+ */+ public function show($licenseId = null){+- $license = License::withTrashed()->find($licenseId);+ $license = License::find($licenseId);+ $license = $license->load('assignedusers', 'licenseSeats.user', 'licenseSeats.asset');+if (isset($license->id)) {-- if (!Company::isCurrentUserHasAccess($license)) {- return redirect()->to('admin/licenses')->with('error', trans('general.insufficient_permissions'));- }- return View::make('licenses/view', compact('license'));-- } else {- // Prepare the error message- $error = trans('admin/licenses/message.does_not_exist', compact('id'));-- // Redirect to the user management page- return redirect()->route('licenses')->with('error', $error);+ $license = $license->load('assignedusers', 'licenseSeats.user', 'licenseSeats.asset');+ $this->authorize('view', $license);+ return view('licenses/view', compact('license'));}+ $error = trans('admin/licenses/message.does_not_exist', compact('id'));+ return redirect()->route('licenses.index')->with('error', $error);}public function getClone($licenseId = null)diff --cc app/Http/Controllers/UsersController.phpindex a5a59ff9a0,72fdabda6b..62360ff51c--- a/app/Http/Controllers/UsersController.php+++ b/app/Http/Controllers/UsersController.php@@@ -422,34 -367,27 +367,28 @@@ class UsersController extends Controlletry {// Get user information$user = User::find($id);+ // Authorize takes care of many of our logic checks now.+ $this->authorize('delete', User::class);- if ($user->assets()->count() > 0) {+ // Check if we are not trying to delete ourselves+ if ($user->id === Auth::user()->id) {// Redirect to the user management page- return redirect()->route('users')->with('error', trans('admin/users/message.error.delete'));- }-- // Do we have permission to delete this user?- if ((Gate::denies('users.delete') || (config('app.lock_passwords')))) {- return redirect()->route('users')->with('error', 'Insufficient permissions!');+ return redirect()->route('users.index')->with('error', 'This user still has ' . $user->assets()->count() . ' assets associated with them.');}- if (count($user->assets) > 0) {-+ if ($user->licenses()->count() > 0) {// Redirect to the user management page- return redirect()->route('users')->with('error', 'This user still has ' . count($user->assets) . ' assets associated with them.');- return redirect()->route('users.index')->with('error', 'This user still has ' . $user->licenses()->count() . ' licenses associated with them.');++ return redirect()->route('users.index')->with('error', 'This user still has ' . $user->assets()->count() . ' assets associated with them.');}- if (count($user->licenses) > 0) {-+ if ($user->accessories()->count() > 0) {// Redirect to the user management page- return redirect()->route('users')->with('error', 'This user still has ' . count($user->licenses) . ' licenses associated with them.');+ return redirect()->route('users.index')->with('error', 'This user still has ' . $user->accessories()->count() . ' accessories associated with them.');}- if (count($user->accessories) > 0) {-+ if ($user->managedLocations()->count() > 0) {// Redirect to the user management page- return redirect()->route('users')->with('error', 'This user still has ' . count($user->accessories) . ' accessories associated with them.');+ return redirect()->route('users.index')->with('error', 'This user still has ' . $user->managedLocations()->count() . ' locations that they manage.');}// Delete the user@@@ -1091,26 -928,22 +925,21 @@@$user = User::find($userId);$destinationPath = config('app.private_uploads').'/users';- // the license is validif (isset($user->id)) {-- if (!Company::isCurrentUserHasAccess($user)) {- return redirect()->route('users')->with('error', trans('general.insufficient_permissions'));- } else {- $log = Actionlog::find($fileId);- $full_filename = $destinationPath . '/' . $log->filename;- if (file_exists($full_filename)) {- unlink($destinationPath . '/' . $log->filename);- }- $log->delete();- return redirect()->back()->with('success', trans('admin/users/message.deletefile.success'));+ $this->authorize('update', $user);+ $log = Actionlog::find($fileId);+ $full_filename = $destinationPath . '/' . $log->filename;+ if (file_exists($full_filename)) {+ unlink($destinationPath . '/' . $log->filename);}- } else {- // Prepare the error message- $error = trans('admin/users/message.does_not_exist', compact('id'));-- // Redirect to the licence management page- return redirect()->route('users')->with('error', $error);+ $log->delete();+ return redirect()->back()->with('success', trans('admin/users/message.deletefile.success'));}+ // Prepare the error message+ $error = trans('admin/users/message.does_not_exist', compact('id'));+ // Redirect to the licence management page+ return redirect()->route('users.index')->with('error', $error);+}/**diff --cc resources/views/hardware/view.blade.phpindex 85fc0b9113,27f9315f30..ec9cea61be--- a/resources/views/hardware/view.blade.php+++ b/resources/views/hardware/view.blade.php@@@ -359,25 -385,26 +385,26 @@@</tbody></table></div> <!-- /table-responsive -->- </div><!-- /col -->+ </div><!-- /col-md-8 --><div class="col-md-4">-@if ($asset->image)- <img src="{{ config('app.url') }}/uploads/assets/{{{ $asset->image }}}" class="assetimg img-responsive">+ <img src="{{ url('/') }}/uploads/assets/{{{ $asset->image }}}" class="assetimg img-responsive">@elseif ($asset->model->image!='')- <img src="{{ config('app.url') }}/uploads/models/{{{ $asset->model->image }}}" class="assetimg img-responsive">+ <img src="{{ url('/') }}/uploads/models/{{{ $asset->model->image }}}" class="assetimg img-responsive">@endif-- @if (($snipeSettings->qr_code=='1') && ($asset->deleted_at==''))- <img src="{{ url('/') }}/hardware/{{ $asset->id }}/qr_code" class="img-thumbnail pull-right" style="height: 100px; width: 100px; margin-right: 10px;">++ @if ($snipeSettings->qr_code=='1')+ <img src="{{ config('app.url') }}/hardware/{{ $asset->id }}/qr_code" class="img-thumbnail pull-right" style="height: 100px; width: 100px; margin-right: 10px;">@endif- @if (($asset->assigneduser) && ($asset->assigned_to > 0) && ($asset->deleted_at==''))+ @if (($asset->assignedTo) && ($asset->deleted_at==''))<h4>{{ trans('admin/hardware/form.checkedout_to') }}</h4><p>- <img src="{{ $asset->assigneduser->gravatar() }}" class="user-image-inline" alt="{{ $asset->assigneduser->fullName() }}">- <a href="{{ route('view/user', $asset->assigned_to) }}">{{ $asset->assigneduser->fullName() }}</a>+ @if($asset->checkedOutToUser()) <!-- Only users have avatars currently-->+ <img src="{{ $asset->assignedTo->present()->gravatar() }}" class="user-image-inline" alt="{{ $asset->assignedTo->present()->fullName() }}">+ @endif+ {!! $asset->assignedTo->present()->glyph() . ' ' .$asset->assignedTo->present()->nameUrl() !!}</p><ul class="list-unstyled">@@@ -513,62 -520,59 +520,63 @@@<!-- Asset Maintenance table -->@if (count($asset->assetmaintenances) > 0)- <table class="table table-striped">- <thead>- <tr>- <th>{{ trans('general.supplier') }}</th>- <th>{{ trans('admin/asset_maintenances/form.title') }}</th>- <th>{{ trans('admin/asset_maintenances/form.asset_maintenance_type') }}</th>- <th>{{ trans('admin/asset_maintenances/form.start_date') }}</th>- <th>{{ trans('admin/asset_maintenances/form.completion_date') }}</th>- <th>{{ trans('admin/asset_maintenances/form.notes') }}</th>- <th>{{ trans('admin/asset_maintenances/table.is_warranty') }}</th>- <th>{{ trans('admin/asset_maintenances/form.cost') }}</th>- <th>{{ trans('general.admin') }}</th>- @can('assets.edit')- <th>{{ trans('table.actions') }}</th>- @endcan- </tr>- </thead>- <tbody>- <?php $totalCost = 0; ?>+ <table class="table table-striped">+ <thead>+ <tr>+ <th>{{ trans('general.supplier') }}</th>+ <th>{{ trans('admin/asset_maintenances/form.title') }}</th>+ <th>{{ trans('admin/asset_maintenances/form.asset_maintenance_type') }}</th>+ <th>{{ trans('admin/asset_maintenances/form.start_date') }}</th>+ <th>{{ trans('admin/asset_maintenances/form.completion_date') }}</th>+ <th>{{ trans('admin/asset_maintenances/form.notes') }}</th>+ <th>{{ trans('admin/asset_maintenances/table.is_warranty') }}</th>+ <th>{{ trans('admin/asset_maintenances/form.cost') }}</th>+ <th>{{ trans('general.admin') }}</th>++ @can('update', \App\Models\Asset::class)+ <th>{{ trans('table.actions') }}</th>+ @endcan+ </tr>+ </thead>+ <tbody>+ <?php $totalCost = 0; ?>- @foreach ($asset->assetmaintenances as $assetMaintenance)- @if (is_null($assetMaintenance->deleted_at))- <tr>- <td><a href="{{ route('suppliers.show', $assetMaintenance->supplier_id) }}">{{ $assetMaintenance->supplier->name }}</a></td>- <td>{{ $assetMaintenance->title }}</td>- <td>{{ $assetMaintenance->asset_maintenance_type }}</td>- <td>{{ $assetMaintenance->start_date }}</td>- <td>{{ $assetMaintenance->completion_date }}</td>- <td>{{ $assetMaintenance->notes }}</td>- <td>{{ $assetMaintenance->is_warranty ? trans('admin/asset_maintenances/message.warranty') : trans('admin/asset_maintenances/message.not_warranty') }}</td>- <td class="text-right"><nobr>{{ $use_currency.$assetMaintenance->cost }}</nobr></td>- <td>- @if ($assetMaintenance->admin)- <a href="{{ route('users.show', $assetMaintenance->admin->id) }}">{{ $assetMaintenance->admin->present()->fullName() }}</a>- @endif- </td>+ @foreach ($asset->assetmaintenances as $assetMaintenance)+ @if (is_null($assetMaintenance->deleted_at))+ <tr>+ <td>+ @if ($assetMaintenance->supplier)+ <a href="{{ route('view/supplier', $assetMaintenance->supplier_id) }}">{{ $assetMaintenance->supplier->name }}</a>+ @endif+ </td>+ <td>{{ $assetMaintenance->title }}</td>+ <td>{{ $assetMaintenance->asset_maintenance_type }}</td>+ <td>{{ $assetMaintenance->start_date }}</td>+ <td>{{ $assetMaintenance->completion_date }}</td>+ <td>{{ $assetMaintenance->notes }}</td>+ <td>{{ $assetMaintenance->is_warranty ? trans('admin/asset_maintenances/message.warranty') : trans('admin/asset_maintenances/message.not_warranty') }}</td>+ <td class="text-right"><nobr>{{ $use_currency.$assetMaintenance->cost }}</nobr></td>+ <td>+ @if ($assetMaintenance->admin)+ <a href="{{ config('app.url') }}/admin/users/{{ $assetMaintenance->admin->id }}/view">{{ $assetMaintenance->admin->fullName() }}</a>+ @endif+ </td><?php $totalCost += $assetMaintenance->cost; ?>- @can('assets.edit')- <td>- <a href="{{ route('update/asset_maintenance', $assetMaintenance->id) }}" class="btn btn-warning btn-sm"><i class="fa fa-pencil icon-white"></i></a>- </td>- @endcan- </tr>- @endif- @endforeach- </tbody>- <tfoot>- <tr>- <td colspan="8" class="text-right">{{ is_numeric($totalCost) ? $use_currency.number_format($totalCost, 2) : $totalCost }}</td>- </tr>- </tfoot>- </table>+ @can('update', \App\Models\Asset::class)+ <td>+ <a href="{{ route('maintenances.edit', $assetMaintenance->id) }}" class="btn btn-warning btn-sm"><i class="fa fa-pencil icon-white"></i></a>+ </td>+ @endcan+ </tr>+ @endif+ @endforeach+ </tbody>+ <tfoot>+ <tr>+ <td colspan="8" class="text-right">{{ is_numeric($totalCost) ? $use_currency.number_format($totalCost, 2) : $totalCost }}</td>+ </tr>+ </tfoot>+ </table>@else<div class="alert alert-info alert-block"><i class="fa fa-info-circle"></i>diff --cc snipeit.shindex 5231849424,f14fbf1382..4aad3db983--- a/snipeit.sh+++ b/snipeit.sh@@@ -111,14 -111,15 +111,15 @@@ function isinstalled}if [ -f /etc/lsb-release ]; then- distro="$(lsb_release -s -i )"- version="$(lsb_release -s -r)"+ distro="$(lsb_release -s -i )"+ version="$(lsb_release -s -r)"+ codename="$(lsb_release -c -s)"elif [ -f /etc/os-release ]; then- distro="$(. /etc/os-release && echo $ID)"- version="$(. /etc/os-release && echo $VERSION_ID)"-#Order is important here. If /etc/os-release and /etc/centos-release exist, we're on centos 7.-#If only /etc/centos-release exist, we're on centos6(or earlier). Centos-release is less parsable,-#so lets assume that it's version 6 (Plus, who would be doing a new install of anything on centos5 at this point..)+ distro="$(. /etc/os-release && echo $ID)"+ version="$(. /etc/os-release && echo $VERSION_ID)"+ #Order is important here. If /etc/os-release and /etc/centos-release exist, we're on centos 7.+ #If only /etc/centos-release exist, we're on centos6(or earlier). Centos-release is less parsable,+ #so lets assume that it's version 6 (Plus, who would be doing a new install of anything on centos5 at this point..)elif [ -f /etc/centos-release ]; thendistro="Centos"version="6"@@@ -296,11 -290,12 +294,13 @@@ case $distro icurl -sS https://getcomposer.org/installer | phpphp composer.phar install --no-dev --prefer-sourceperms+ chown -R www-data:www-data "/var/www/$name"service apache2 restart+ php artisan key:generate+ php artisan passport:install;;- centos)- if [ "$version" == "6" ]; then+ centos )+ if [[ "$version" =~ ^6 ]]; then##################################### Install for Centos/Redhat 6 ##############################################webdir=/var/www/html