Changeset 927


Ignore:
Timestamp:
07/12/19 16:13:35 (5 years ago)
Author:
Kris Deugau
Message:

/trunk

Fix mismatch between the web UI search and the RPC search; the RPC search

incorrectly used the leaf allocation entry, not the master VRF entry.

Extend the RPC search to allow specifying the fields to return

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/cgi-bin/search-rpc.cgi

    r925 r927  
    256256  }
    257257
    258   my $cols = "s.cidr, s.custid, s.type, s.city, s.description, s.id, s.parent_id, s.available, s.vrf, a.dispname";
    259   my $sql = qq(SELECT $cols FROM searchme s JOIN alloctypes a ON s.type = a.type);
     258  my $cols = "s.cidr, s.custid, s.type, s.city, s.description, s.id, s.parent_id, s.available, a.vrf, at.dispname";
     259
     260  # Validation and SQL field name mapping all in one!
     261  my %validcols = (cidr => 's.cidr', custid => 's.custid', oldcustid => 's.oldcustid', type => 's.type', city => 's.city',
     262    description => 's.description', notes => 's.notes', circuitid => 's.circuitid', vrf => 'a.vrf', vlan => 's.vlan',
     263    id => 's.id', parent_id => 's.parent_id', master_id => 's.master_id', available => 's.available');
     264  my @usercols;
     265
     266  if ($args{retfields}) {
     267    # caller wants a custom set of returned fields
     268    if (ref($args{retfields}) eq ref([])) {
     269      # field list passed as list/array
     270      foreach (@{$args{retfields}}) {
     271        push @usercols, $validcols{$_} if $validcols{$_};
     272      }
     273    } elsif (not ref $args{retfields}) {
     274      # field list passed as simple string
     275      foreach (split /\s+/, $args{retfields}) {
     276        push @usercols, $validcols{$_} if $validcols{$_};
     277      }
     278    } else {
     279      # nonfatal fail.  only accepts array or string.  fall back to default list
     280    }
     281  }
     282
     283  # only replace the default set if a custom set was passed in
     284  $cols = join ', ', @usercols if @usercols;
     285
     286  my $sql = qq(SELECT $cols FROM searchme s JOIN alloctypes at ON s.type = at.type JOIN allocations a ON s.master_id=a.id);
    260287  my @sqlcriteria;
    261288  for (my $i = 0; $i <= $#fields; $i++) {
     
    436463city, and description.
    437464
     465=item fields
     466
     467Specify the fields to return from the search.  By default, these are returned:
     468
     469=over 4
     470
     471cidr
     472custid
     473type
     474city
     475description
     476id
     477parent_id
     478available
     479vrf
     480dispname  (the "display name" for the type)
     481
    438482=back
    439483
     484The following are available from this interface:
     485
     486=over 4
     487
     488cidr
     489custid
     490oldcustid
     491type
     492city
     493description
     494notes
     495circuitid
     496vrf
     497vlan
     498id
     499parent_id
     500master_id
     501available
     502
     503=back
     504
     505The list may be sent as a space-separated string or as an array.  Unknown field names will be ignored.
     506
     507=back
Note: See TracChangeset for help on using the changeset viewer.