snipe-it icon indicating copy to clipboard operation
snipe-it copied to clipboard

Custom field type URL not treated as hyperlink

Open diekmanu opened this issue 9 years ago • 6 comments

Expected Behavior (or desired behavior if a feature request)

Custom fields with the URL attribute set should be hyperlinks.


Actual Behavior

These fields are actually treated as "regular text". So you always have to copy/paste or open up the asset's info page individually.


Please confirm you have done the following before posting your bug report:


Provide answers to these questions:

Is this a fresh install or an upgrade? Upgrade Version of Snipe-IT you're running: v4.0.6 build 47 (g2e76620) / develop Version of PHP you're running: 5.6.29 Version of MySQL/MariaDB you're running: MariaDB 10.1.3 What OS and web server you're running Snipe-IT on: win7x64, nginx What method you used to install Snipe-IT (install.sh, manual installation, docker, etc): manual WITH DEBUG TURNED ON, if you're getting an error in your browser, include that error What specific Snipe-IT page you're on, and what specific element you're interacting with to trigger the error

  • If a stacktrace is provided in the error, include that too.
  • Any errors that appear in your browser's error console.
  • Confirm whether the error is reproduceable on the demo: https://snipeitapp.com/demo.
  • Include any additional information you can find in app/storage/logs and your webserver's logs.
  • Include what you've done so far in the installation, and if you got any error messages along the way.
  • Indicate whether or not you've manually edited any data directly in the database

Please do not post an issue without answering the related questions above. If you have opened a different issue and already answered these questions, answer them again, once for every ticket. It will be next to impossible for us to help you.

https://snipe-it.readme.io/docs/getting-help

diekmanu avatar Oct 02 '17 06:10 diekmanu

Is this in the list view, the detail view, or both?

We have code to link them in the view:

 @if (($field->format=='URL') && ($asset->{$field->db_column_name()}!=''))
      <a href="{{ $asset->{$field->db_column_name()} }}" target="_new">{{ $asset->{$field->db_column_name()} }}</a>
 @else
     {{ $asset->{$field->db_column_name()} }}
@endif

snipe avatar Oct 03 '17 05:10 snipe

Ony in list view.

diekmanu avatar Oct 04 '17 06:10 diekmanu

In v3 this was implemented in app\HTTP\Controllers\AssetsController.php:

        foreach ($all_custom_fields as $field) {
            $column_name = $field->db_column_name();

            if ($field->isFieldDecryptable($asset->{$column_name})) {

                if (Gate::allows('admin')) {
                    if (($field->format=='URL') && ($asset->{$column_name}!='')) {
                        $row[$column_name] = '<a href="'.Helper::gracefulDecrypt($field, $asset->{$column_name}).'" target="_blank">'.Helper::gracefulDecrypt($field, $asset->{$column_name}).'</a>';
                    } else {
                        $row[$column_name] = Helper::gracefulDecrypt($field, $asset->{$column_name});
                    }

                } else {
                    $row[$field->db_column_name()] = strtoupper(trans('admin/custom_fields/general.encrypted'));
                }
            } else {
                if (($field->format=='URL') && ($asset->{$field->db_column_name()}!='')) {
                    $row[$field->db_column_name()] = '<a href="'.$asset->{$field->db_column_name()}.'" target="_blank">'.$asset->{$field->db_column_name()}.'</a>';
                } else {
                    $row[$field->db_column_name()] = e($asset->{$field->db_column_name()});
                }
            }

In v4 this seems to be transferred to app\HTTP\Controllers\Api\AssetsController.php:

    $all_custom_fields = CustomField::all(); //used as a 'cache' of custom fields throughout this page load
    foreach ($all_custom_fields as $field) {
        $allowed_columns[]=$field->db_column_name();
    }

...but missing the code for URL-formatted fields.

diekmanu avatar Oct 24 '17 08:10 diekmanu

Updaded to v4.1.3 build 94 (gb6a14d2) but still no hyperlinks in list view :cry:

diekmanu avatar Nov 06 '17 06:11 diekmanu

This is fixed on dev

snipe avatar Nov 22 '17 06:11 snipe

v4.7.4 (in docker) - I'm not getting hyperlinks for a custom url field in list view or detail view of asset.

Kolossi avatar Jun 15 '19 20:06 Kolossi