Menu

#467 Rooms/Area restriction

open
nobody
None
1
2019-06-07
2014-01-23
Anonymous
No

Hello,

can we protect a room ? I would like to allow room reservation only for admin users.

Thanks.

Discussion

  • Campbell Morrison

    There are three ways you could do this:

    (1) Run two separate installations of MRBS, with the protected rooms in one installation and the rest in the other. For the protected installation set $auth['only_admin_can_book'].

    (2) Use the ACL branch

    (3) Modify getWritable() in mrbs_auth.inc

    Campbell

     
  • Anonymous

    Anonymous - 2014-01-23

    I change this code ? how I set a restriction on a room created ? for my press room for example ?

    /* getWritable($creator, $user, $room)
     *
     * Determines if a user is able to modify an entry
     *
     * $creator - The creator of the entry
     * $user    - Who wants to modify it
     * $room    - The id of the room that the entry is in
     *
     * Returns:
     *   0        - The user does not have the required access
     *   non-zero - The user has the required access
     */
    function getWritable($creator, $user, $room)
    {
      // Always allowed to modify your own stuff
      if(strcasecmp($creator, $user) == 0)
      {
        return 1;
      }
    
      // Otherwise you have to be a (booking) admin for this room
      if (auth_book_admin($user, $room))
      {
        return 1;
      }
    
      // Unathorised access
      return 0;
    }
    
     

    Last edit: Campbell Morrison 2019-06-05
  • Campbell Morrison

    Insert the following code at the beginning of the function, replacing 42 by the id of your room (you can find the id by going to that room in the week view and there should be the id in the query string in the URL):

      if (($room == 42) && !auth_book_admin($user, $room))
      {
        return 0;
      }
    

    Campbell

     
  • Simona Simone

    Simona Simone - 2019-06-05

    How can i customize control on area instead of room?

     
    • Campbell Morrison

      Use the get_area() function, eg:

      if ((7 == get_area($room)) && !auth_book_admin($user, $room))
        {
          return 0;
        }
      

      Substitute the id of your area for 7.

       
  • Simona Simone

    Simona Simone - 2019-06-06

    I changed getWritable function:

    function getWritable($creator, $room)
    {
      $user = getUserName();
    //  
      if ((3 == get_area($room)) && !auth_book_admin($user, $room))
      {
        return 0;
      }
    
      // Always allowed to modify your own stuff
      if(strcasecmp($creator, $user) === 0)
      {
        return true;
      }
    
      // Otherwise you have to be a (booking) admin for this room
      if (is_book_admin($room))
      {
        return true;
      }
    
      // Unathorised access
      return false;
    }
    

    but when select area number 3 system shows "Whoops! Unfortunately MRBS has encountered a fatal error. Please consult your system administrator"

     

    Last edit: Campbell Morrison 2019-06-06
  • Campbell Morrison

    If you are using MRBS 1.7.3 then the code should be

    function getWritable($creator, $room)
    {
      $user = getUserName();
    
      if ((3 == get_area($room)) && !auth_book_admin($user, $room))
      {
        return false;
      }
    
      // Always allowed to modify your own stuff
      if(strcasecmp($creator, $user) === 0)
      {
        return true;
      }
    
      // Otherwise you have to be a (booking) admin for this room
      if (auth_book_admin($user, $room))
      {
        return true;
      }
    
      // Unathorised access
      return false;
    }
    

    (The is_book_admin() function has been replaced by auth_book_admin() which now takes two parameters. Also it should now be return falserather than return 0.)

     

    Last edit: Campbell Morrison 2019-06-06
  • Campbell Morrison

    Sorry, forget the last post. New version coming up.

     
  • Campbell Morrison

    Here's the correct code for 1.7.3:

    function getWritable($creator, $user, $room)
    {
      if ((3 == get_area($room)) && !auth_book_admin($user, $room))
      {
        return false;
      }
    
      // Always allowed to modify your own stuff
      if(strcasecmp($creator, $user) === 0)
      {
        return true;
      }
    
      // Otherwise you have to be a (booking) admin for this room
      if (auth_book_admin($user, $room))
      {
        return true;
      }
    
      // Unathorised access
      return false;
    }
    

    [getWritable() now takes three parameters].

     
  • Simona Simone

    Simona Simone - 2019-06-06

    I'm sorry if I'm wasting your time but i receive yet fatal error. Maybe because i use your nav_improvement version? does something change in this case?

     
  • Campbell Morrison

    Yes, probably. Can you post your original code for getWritable() so that I can see which version you have, because there have been lots of changes even within that branch.

     
  • Simona Simone

    Simona Simone - 2019-06-06

    This is original code

    function getWritable($creator, $room)
    {
      $user = getUserName();
    
      // Always allowed to modify your own stuff
      if(strcasecmp($creator, $user) === 0)
      {
        return true;
      }
    
      // Otherwise you have to be a (booking) admin for this room
      if (is_book_admin($room))
      {
        return true;
      }
    
      // Unathorised access
      return false;
    }
    
     

    Last edit: Campbell Morrison 2019-06-06
  • Campbell Morrison

    Then you need

    function getWritable($creator, $room)
    {
      $user = getUserName();
    
      if ((3 == get_area($room)) && !is_book_admin($room))
      {
        return false;
      }
    
      // Always allowed to modify your own stuff
      if(strcasecmp($creator, $user) === 0)
      {
        return true;
      }
    
      // Otherwise you have to be a (booking) admin for this room
      if (is_book_admin($room))
      {
        return true;
      }
    
      // Unathorised access
      return false;
    }
    

    If that doesn't work then look in your PHP error log to see what the error is.

     
  • Simona Simone

    Simona Simone - 2019-06-07

    Great, it works!! thank you very much.