Fixed #6880 - correctly encrypt encrypted fields via the API

This commit is contained in:
snipe 2019-05-15 19:33:30 -07:00
parent 6728089106
commit 9eb7b668d1

View file

@ -448,7 +448,13 @@ class AssetsController extends Controller
$model = AssetModel::find($request->get('model_id')); $model = AssetModel::find($request->get('model_id'));
if ($model->fieldset) { if ($model->fieldset) {
foreach ($model->fieldset->fields as $field) { foreach ($model->fieldset->fields as $field) {
$asset->{$field->convertUnicodeDbSlug()} = e($request->input($field->convertUnicodeDbSlug(), null)); if ($field->field_encrypted=='1') {
if (Gate::allows('admin')) {
$asset->{$field->convertUnicodeDbSlug()} = \Crypt::encrypt($request->input($field->convertUnicodeDbSlug()));
}
} else {
$asset->{$field->convertUnicodeDbSlug()} = $request->input($field->convertUnicodeDbSlug());
}
} }
} }
@ -497,8 +503,12 @@ class AssetsController extends Controller
// Update custom fields // Update custom fields
if (($model = AssetModel::find($asset->model_id)) && (isset($model->fieldset))) { if (($model = AssetModel::find($asset->model_id)) && (isset($model->fieldset))) {
foreach ($model->fieldset->fields as $field) { foreach ($model->fieldset->fields as $field) {
if ($request->has($field->convertUnicodeDbSlug())) { if ($field->field_encrypted=='1') {
$asset->{$field->convertUnicodeDbSlug()} = e($request->input($field->convertUnicodeDbSlug())); if (Gate::allows('admin')) {
$asset->{$field->convertUnicodeDbSlug()} = \Crypt::encrypt($request->input($field->convertUnicodeDbSlug()));
}
} else {
$asset->{$field->convertUnicodeDbSlug()} = $request->input($field->convertUnicodeDbSlug());
} }
} }
} }