I have a room, with prices, availability and bookings.

I have a node with an availability calendar ( https://www.drupal.org/node/1782238 )

When logged in as admin, this works. When logged out this does not.

--- Logged IN:

http://panopoly.local/content/test-unit-2?q=rooms/units/unit/1/availabil...
[{"id":"1","start":"2014-09-01T13:00:00Z","end":"2014-09-30T13:00:00Z","title":"AV","color":"#8CBF62","borderColor":"#04711B"}]

NOTE: VALID json

--- Logged OUT:

http://panopoly.local/content/test-unit-2?q=rooms/units/unit/1/availabil...
[][{"id":"1","start":"2014-09-02T13:00:00Z","end":"2014-09-30T13:00:00Z","title":"AV","color":"#8CBF62","borderColor":"#04711B"}]

Note: INVALID json, the first two characters: [] are a problem.

This seems to be a problem AFTER the function:

sites/all/modules/rooms_availability/rooms_availability.moule -> rooms_availability_event(....)

is called...

But regardless, when the invalid json is passed to fullcalendar.js (line 995) with the ajax.complete() is run, it simply returns a parse error.

Expected behaviour:

- When logged in as admin, can see the calendar as normal
- When logged out, or logged in as user can see own bookings, can see other peoples bookings as 'booked' with no details

Comments

ITWest-jg’s picture

Issue summary: View changes
ITWest-jg’s picture

OK, I'm sorry but I'm going to log my trail of discovery here.

It seems that rooms_availability.module:

/**
 * Helper function to determine the $event style depending on permissions.
 */
function rooms_availability_get_style($event_style, $unit) {
  $event_style = is_numeric($event_style) ? (int) $event_style : (int) ROOMS_AVAILABILITY_ADMIN_STYLE;

  // If user don't have 'view named availability information' permission.
  if (!(user_access('view named availability information') || rooms_unit_access('update availability', $unit))
    && $event_style == ROOMS_AVAILABILITY_ADMIN_STYLE) {
    $event_style = (int) ROOMS_AVAILABILITY_GENERIC_STYLE;
  }
  // If user don't have 'view anonymous availability information' permission.
  if (!(user_access('view anonymous availability information') || rooms_unit_access('update availability', $unit))
    && $event_style == ROOMS_AVAILABILITY_GENERIC_STYLE) {
    //
    //
    //
    echo drupal_json_encode(array());  // <-- here
    //
    //
    //

  }

  return $event_style;
}

the commented line is the problem.

So '[]' is echo'd, then later the correct array is also echo'd. There are a few problems here.

IMHO: rooms_availability_get_style should not have side effects (the echo)

mbchler@drupal.org’s picture

I reported the same issue recently, it is solved on master branch, please see https://www.drupal.org/node/2322951

acrollet’s picture