Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed #6956 - viewKeys policy inconsistent #7009

Merged
merged 2 commits into from
May 8, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion app/Http/Controllers/LicensesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,9 @@ public function update(Request $request, $licenseId = null)
$license->purchase_date = $request->input('purchase_date');
$license->purchase_order = $request->input('purchase_order');
$license->reassignable = $request->input('reassignable', 0);
$license->serial = $request->input('serial');
if (Gate::allows('viewKeys', $license)) {
$license->serial = $request->input('serial');
}
$license->termination_date = $request->input('termination_date');
$license->seats = e($request->input('seats'));
$license->manufacturer_id = $request->input('manufacturer_id');
Expand Down
27 changes: 19 additions & 8 deletions app/Policies/LicensePolicy.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,27 @@ protected function columnName()
return 'licenses';
}

/**
* Determine whether the user can view license keys
*
* @param \App\Models\User $user
* @param \App\Models\License $license
* @return mixed
*/
/**
* Determine whether the user can view license keys.
* This gets a little tricky, UX/logic-wise. If a user has the ability
* to create a license (which requires a product key), shouldn't they
* have the ability to see the product key as well?
*
* Example: I create the license, realize I need to change
* something (maybe I got the product key wrong), and now I can never
* see/edit that product key.
*
* @see https://github.com/snipe/snipe-it/issues/6956
* @param \App\Models\User $user
* @param \App\Models\License $license
* @return mixed
*/
public function viewKeys(User $user, License $license = null)
{
return $user->hasAccess('licenses.keys');
if ($user->hasAccess('licenses.keys') || $user->hasAccess('licenses.create') || $user->hasAccess('licenses.edit')) {
return true;
}
return false;
}

}
8 changes: 7 additions & 1 deletion resources/views/licenses/checkin.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,13 @@
<div class="form-group">
<label class="col-sm-2 control-label">{{ trans('admin/hardware/form.serial') }}</label>
<div class="col-md-6">
<p class="form-control-static">{{ $licenseSeat->license->serial }}</p>
<p class="form-control-static">
@can('viewKeys', $licenseSeat->license)
{{ $licenseSeat->license->serial }}
@else
------------
@endcan
</p>
</div>
</div>

Expand Down
8 changes: 7 additions & 1 deletion resources/views/licenses/checkout.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,13 @@
<div class="form-group">
<label class="col-sm-3 control-label">{{ trans('admin/hardware/form.serial') }}</label>
<div class="col-md-9">
<p class="form-control-static" style="word-wrap: break-word;">{{ $license->serial }}</p>
<p class="form-control-static" style="word-wrap: break-word;">
@can('viewKeys', $license)
{{ $license->serial }}
@else
------------
@endcan
</p>
</div>
</div>

Expand Down
4 changes: 4 additions & 0 deletions resources/views/licenses/edit.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,18 @@
@section('inputFields')
@include ('partials.forms.edit.name', ['translated_name' => trans('admin/licenses/form.name')])
@include ('partials.forms.edit.category-select', ['translated_name' => trans('admin/categories/general.category_name'), 'fieldname' => 'category_id', 'required' => 'true', 'category_type' => 'license'])


<!-- Serial-->
@can('viewKeys', $item)
<div class="form-group {{ $errors->has('serial') ? ' has-error' : '' }}">
<label for="serial" class="col-md-3 control-label">{{ trans('admin/licenses/form.license_key') }}</label>
<div class="col-md-7{{ (\App\Helpers\Helper::checkIfRequired($item, 'serial')) ? ' required' : '' }}">
<textarea class="form-control" type="text" name="serial" id="serial">{{ Input::old('serial', $item->serial) }}</textarea>
{!! $errors->first('serial', '<span class="alert-msg"><i class="fa fa-times"></i> :message</span>') !!}
</div>
</div>
@endcan

<!-- Seats -->
<div class="form-group {{ $errors->has('seats') ? ' has-error' : '' }}">
Expand Down
8 changes: 7 additions & 1 deletion resources/views/reports/licenses.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,13 @@ class="table table-striped snipe-table"
<tr>
<td>{{ is_null($license->company) ? '' : $license->company->name }}</td>
<td>{{ $license->name }}</td>
<td>{{ mb_strimwidth($license->serial, 0, 50, "...") }}</td>
<td>
@can('viewKeys', $license)
{{ $license->serial }}
@else
------------
@endcan
</td>
<td>{{ $license->seats }}</td>
<td>{{ $license->remaincount() }}</td>
<td>{{ $license->expiration_date }}</td>
Expand Down
8 changes: 7 additions & 1 deletion resources/views/users/print.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,13 @@
<tr>
<td>{{ $lcounter }}</td>
<td>{{ $license->name }}</td>
<td>{{ $license->serial }}</td>
<td>
@can('viewKeys', $license)
{{ $license->serial }}
@else
------------
@endcan
</td>
<td>{{ $license->assetlog->first()->created_at }}</td>
</tr>
@php
Expand Down
4 changes: 4 additions & 0 deletions resources/views/users/view.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,11 @@
{!! $license->present()->nameUrl() !!}
</td>
<td>
@can('viewKeys', $license)
{!! $license->present()->serialUrl() !!}
@else
------------
@endcan
</td>
<td class="hidden-print">
@can('update', $license)
Expand Down