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 #11794 Admins Cannot View Encrypted Field #13295

Merged
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: 2 additions & 2 deletions app/Http/Transformers/AssetsTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,10 @@ public function transformAsset(Asset $asset)
foreach ($asset->model->fieldset->fields as $field) {
if ($field->isFieldDecryptable($asset->{$field->db_column})) {
$decrypted = Helper::gracefulDecrypt($field, $asset->{$field->db_column});
$value = (Gate::allows('superadmin')) ? $decrypted : strtoupper(trans('admin/custom_fields/general.encrypted'));
$value = (Gate::allows('assets.view.encrypted_custom_fields')) ? $decrypted : strtoupper(trans('admin/custom_fields/general.encrypted'));

if ($field->format == 'DATE'){
if (Gate::allows('superadmin')){
if (Gate::allows('assets.view.encrypted_custom_fields')){
$value = Helper::getFormattedDateObject($value, 'date', false);
} else {
$value = strtoupper(trans('admin/custom_fields/general.encrypted'));
Expand Down
5 changes: 5 additions & 0 deletions app/Providers/AuthServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,11 @@ public function boot()
}
});

Gate::define('assets.view.encrypted_custom_fields', function ($user) {
if($user->hasAccess('assets.view.encrypted_custom_fields')){
return true;
}
});

// -----------------------------------------
// Reports
Expand Down
7 changes: 7 additions & 0 deletions config/permissions.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,13 @@
'display' => true,
],

[
'permission' => 'assets.view.encrypted_custom_fields',
'label' => 'View and Modify Encrypted Custom Fields',
'note' => '',
'display' => true,
],

],

'Accessories' => [
Expand Down
2 changes: 1 addition & 1 deletion resources/views/hardware/view.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@
@endif

@if ($field->isFieldDecryptable($asset->{$field->db_column_name()} ))
@can('superuser')
@can('assets.view.encrypted_custom_fields')
@if (($field->format=='URL') && ($asset->{$field->db_column_name()}!=''))
<a href="{{ Helper::gracefulDecrypt($field, $asset->{$field->db_column_name()}) }}" target="_new">{{ Helper::gracefulDecrypt($field, $asset->{$field->db_column_name()}) }}</a>
@elseif (($field->format=='DATE') && ($asset->{$field->db_column_name()}!=''))
Expand Down
2 changes: 1 addition & 1 deletion resources/views/models/custom_fields_form.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@


@else
@if (($field->field_encrypted=='0') || (Gate::allows('admin')))
@if (($field->field_encrypted=='0') || (Gate::allows('assets.view.encrypted_custom_fields')))
<input type="text" value="{{ Request::old($field->db_column_name(),(isset($item) ? Helper::gracefulDecrypt($field, $item->{$field->db_column_name()}) : $field->defaultValue($model->id))) }}" id="{{ $field->db_column_name() }}" class="form-control" name="{{ $field->db_column_name() }}" placeholder="Enter {{ strtolower($field->format) }} text">
@else
<input type="text" value="{{ strtoupper(trans('admin/custom_fields/general.encrypted')) }}" class="form-control disabled" disabled>
Expand Down
Loading