diff --git a/app/Models/Asset.php b/app/Models/Asset.php index ecf1b1332..e0c0f45ef 100644 --- a/app/Models/Asset.php +++ b/app/Models/Asset.php @@ -12,11 +12,13 @@ use App\Presenters\Presentable; use App\Presenters\AssetPresenter; use Illuminate\Support\Facades\Auth; use Carbon\Carbon; +use Illuminate\Support\Facades\Crypt; use Illuminate\Support\Facades\DB; use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\SoftDeletes; use Illuminate\Support\Facades\Storage; +use Illuminate\Support\Facades\Validator; use Watson\Validating\ValidatingTrait; use Illuminate\Database\Eloquent\Casts\Attribute; use Illuminate\Database\Eloquent\Model; @@ -213,14 +215,15 @@ class Asset extends Depreciable $this->attributes['expected_checkin'] = $value; } - public function withValidator($validator) - { - foreach ($this->customFields as $field) { - if ($field->isEncrypted()) { - Crypt::decrypt($this->value); - } - } - } + // i don't think this will work the way we'd need it to + //public function withValidator(Validator $validator) + //{ + // foreach ($this->customFields as $field) { + // if ($field->field_encrypted) { + // return Crypt::decrypt($this->value); + // } + // } + //} /** * This handles the custom field validation for assets diff --git a/app/Models/CustomFieldset.php b/app/Models/CustomFieldset.php index c286005bf..1059c5d5f 100644 --- a/app/Models/CustomFieldset.php +++ b/app/Models/CustomFieldset.php @@ -2,6 +2,8 @@ namespace App\Models; +use App\Rules\AlphaEncrypted; +use App\Rules\NumericEncrypted; use Gate; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; @@ -92,13 +94,20 @@ class CustomFieldset extends Model $rule[] = 'unique_undeleted'; } - if ($field->hasFormat() && $field->isEncrypted()) { - $rule[] = $rule.'-encrypted'; - } - array_push($rule, $field->attributes['format']); $rules[$field->db_column_name()] = $rule; + + if ($field->format === 'NUMERIC' && $field->field_encrypted) { + $numericKey = array_search('numeric', $rules[$field->db_column_name()]); + $rules[$field->db_column_name()][$numericKey] = new NumericEncrypted; + } + + if ($field->format === 'ALPHA' && $field->field_encrypted) { + $alphaKey = array_search('alpha', $rules[$field->db_column_name()]); + $rules[$field->db_column_name()][$alphaKey] = new AlphaEncrypted; + } + // add not_array to rules for all fields but checkboxes if ($field->element != 'checkbox') { $rules[$field->db_column_name()][] = 'not_array'; @@ -113,6 +122,8 @@ class CustomFieldset extends Model } } + dump($rules); + return $rules; } } diff --git a/app/Rules/AlphaEncrypted.php b/app/Rules/AlphaEncrypted.php new file mode 100644 index 000000000..246d92f0b --- /dev/null +++ b/app/Rules/AlphaEncrypted.php @@ -0,0 +1,28 @@ +getMessage()); + } + } +} diff --git a/app/Rules/NumericEncrypted.php b/app/Rules/NumericEncrypted.php new file mode 100644 index 000000000..f36c4174e --- /dev/null +++ b/app/Rules/NumericEncrypted.php @@ -0,0 +1,28 @@ +getMessage()); + } + } +}