Esempio n. 1
0
def assert_is_in_digest_window(room, expected, expected_with_exclude):
    assert room.is_in_digest_window() == expected
    assert room.is_in_digest_window(exclude_first_day=True) == expected_with_exclude
    assert Room.find_first(Room.is_in_digest_window()) == (room if expected else None)
    assert Room.find_first(Room.is_in_digest_window(exclude_first_day=True)) == (
        room if expected_with_exclude else None
    )
Esempio n. 2
0
def assert_is_in_digest_window(room, expected, expected_with_exclude):
    assert room.is_in_digest_window() == expected
    assert room.is_in_digest_window(
        exclude_first_day=True) == expected_with_exclude
    assert Room.find_first(
        Room.is_in_digest_window()) == (room if expected else None)
    assert Room.find_first(Room.is_in_digest_window(
        exclude_first_day=True)) == (room if expected_with_exclude else None)
Esempio n. 3
0
    def getVars(self):
        vars = WJSBase.getVars( self )

        vars["MinStartDate"] = formatDateTime(getMinStartDate(self._conf))
        vars["MaxEndDate"] = formatDateTime(getMaxEndDate(self._conf))
        vars["ExtraMinutesBefore"] = getCERNMCUOptionValueByName("extraMinutesBefore")
        vars["ExtraMinutesAfter"] = getCERNMCUOptionValueByName("extraMinutesAfter")

        # Code to retrieve the event's location and room in order to include the event's room
        # as an initial participant
        location = self._conf.getLocation()
        room = self._conf.getRoom()
        if location and room and location.getName() and room.getName() and location.getName().strip() and room.getName().strip():
            locationName = location.getName()
            roomName = room.getName()

            vars["IncludeInitialRoom"] = True
            vars["IPRetrievalResult"] = -1 # 0 = OK, 1 = room without H323 IP, 2 = room with invalid H323 IP, 3 = connection to RB problem, 4 = another unknown problem
            vars["InitialRoomName"] = roomName
            if self._conf.getLocation():
                vars["InitialRoomInstitution"] = locationName
            else:
                vars["InitialRoomInstitution"] = ""

            if not Config.getInstance().getIsRoomBookingActive():
                room_ip = "Please enter IP"
                vars["IPRetrievalResult"] = 3
            else:
                rb_room = Room.find_first(Location.name == locationName, Room.name == roomName, _join=Room.location)
                if rb_room is None:
                    room_ip = "Please enter IP."
                    vars["IPRetrievalResult"] = 1
                else:
                    vars["InitialRoomName"] = rb_room.full_name
                    attr_name = getCERNMCUOptionValueByName('H323_IP_att_name')
                    room_ip = rb_room.get_attribute_value(attr_name, '').strip()
                    if not room_ip:
                        room_ip = "Please enter IP."
                        vars["IPRetrievalResult"] = 1
                    elif not validIP(room_ip):
                        vars["IPRetrievalResult"] = 2
                    else:
                        vars["IPRetrievalResult"] = 0

            vars["InitialRoomIP"] = room_ip

        else:
            vars["IncludeInitialRoom"] = False
            vars["IPRetrieved"] = False
            vars["InitialRoomName"] = ""
            vars["InitialRoomInstitution"] = ""
            vars["InitialRoomIP"] = ""

        vars["CERNGatekeeperPrefix"] = getCERNMCUOptionValueByName("CERNGatekeeperPrefix")
        vars["GDSPrefix"] = getCERNMCUOptionValueByName("GDSPrefix")
        vars["MCU_IP"] = getCERNMCUOptionValueByName("MCU_IP")
        vars["Phone_number"] = getCERNMCUOptionValueByName("Phone_number")

        return vars
Esempio n. 4
0
def _get_defaults_from_object(obj):
    defaults = {'start_dt': obj.getAdjustedStartDate().replace(tzinfo=None),
                'end_dt': obj.getAdjustedEndDate().replace(tzinfo=None),
                'booking_reason': "{} '{}'".format(obj.getVerboseType(), obj.getTitle())}
    if defaults['end_dt'].date() != defaults['start_dt'].date():
        defaults['repeat_frequency'] = RepeatFrequency.DAY
        defaults['repeat_interval'] = 1
    if obj.getLocation() and obj.getRoom():
        room = Room.find_first(Room.name == obj.getRoom().getName(), Location.name == obj.getLocation().getName(),
                               _join=Room.location)
        if room:
            defaults['room_ids'] = [room.id]
    return defaults
Esempio n. 5
0
 def getMapURL(self, roomName):
     groupdict = self.applyRegularExpressions(roomName)
     if groupdict:
         return self.getBaseMapURL().format(**groupdict)
     if Config.getInstance().getIsRoomBookingActive():
         from indico.modules.rb.models.rooms import Room
         room = Room.find_first(name=roomName)
         if room:
             if all(field in self.getBaseMapURL() for field in ['{building}','{floor}','{roomNr}']):
                 return self.getBaseMapURL().format(**{'building': str(room.building),
                                                       'floor': room.floor,
                                                       'roomNr': room.number})
     return ""
Esempio n. 6
0
def _get_defaults_from_object(obj):
    defaults = {'start_dt': obj.getAdjustedStartDate().replace(tzinfo=None),
                'end_dt': obj.getAdjustedEndDate().replace(tzinfo=None),
                'booking_reason': "{} '{}'".format(obj.getVerboseType(), obj.getTitle())}
    if defaults['end_dt'].date() != defaults['start_dt'].date():
        defaults['repeat_frequency'] = RepeatFrequency.DAY
        defaults['repeat_interval'] = 1
    if obj.getLocation() and obj.getRoom():
        room = Room.find_first(Room.name == obj.getRoom().getName(), Location.name == obj.getLocation().getName(),
                               _join=Room.location)
        if room:
            defaults['room_ids'] = [room.id]
    return defaults
Esempio n. 7
0
 def getLinkRoomAttribute(cls, linkVideo, attName='h323-ip'):
     if linkVideo is None or not Config.getInstance().getIsRoomBookingActive():
         return ""
     location = linkVideo.getLocation()
     room = linkVideo.getRoom()
     if not location or not room:
         return ""
     location_name = location.getName()
     room_name = room.getName()
     if not location_name or not room_name:
         return ''
     rb_room = Room.find_first(Location.name == location_name.strip(), Room.name == room_name.strip(),
                               _join=Room.location)
     return rb_room.get_attribute_value(attName, '') if rb_room else ''
Esempio n. 8
0
 def getMapURL(self, roomName):
     groupdict = self.applyRegularExpressions(roomName)
     if groupdict:
         return self.getBaseMapURL().format(**groupdict)
     if Config.getInstance().getIsRoomBookingActive():
         from indico.modules.rb.models.rooms import Room
         room = Room.find_first(name=roomName)
         if room:
             if all(field in self.getBaseMapURL()
                    for field in ['{building}', '{floor}', '{roomNr}']):
                 return self.getBaseMapURL().format(
                     **{
                         'building': str(room.building),
                         'floor': room.floor,
                         'roomNr': room.number
                     })
     return ""
Esempio n. 9
0
def test_is_auto_confirm(create_room, need_confirmation):
    room = create_room(reservations_need_confirmation=need_confirmation)
    assert room.is_auto_confirm != need_confirmation
    assert Room.find_first(is_auto_confirm=need_confirmation) is None
    assert Room.find_first(is_auto_confirm=not need_confirmation) == room
Esempio n. 10
0
def test_is_auto_confirm(create_room, need_confirmation):
    room = create_room(reservations_need_confirmation=need_confirmation)
    assert room.is_auto_confirm != need_confirmation
    assert Room.find_first(is_auto_confirm=need_confirmation) is None
    assert Room.find_first(is_auto_confirm=not need_confirmation) == room
    def fetch_room_equipment(self, connection, room_name=None):
        self._logger.debug("Fetching rooms equipment...")

        cursor = connection.cursor()
        if room_name:
            cursor.execute(
                'SELECT * FROM foundation_pub.room_equipment WHERE MEETING_ROOM_ID = :room_name',
                room_name=room_name)
        else:
            cursor.execute(
                'SELECT * FROM foundation_pub.room_equipment ORDER BY MEETING_ROOM_ID'
            )

        counter = Counter()
        foundation_room_equipment = defaultdict(list)
        vc_parent = self._location.get_equipment_by_name('Video conference')
        vc_equipment = set(
            self._location.equipment_types.filter(
                EquipmentType.parent_id == vc_parent.id))
        default_vc_equipment = set(
            self._location.equipment_types.filter(
                EquipmentType.parent_id == vc_parent.id,
                EquipmentType.name.in_(DEFAULT_VC_EQUIPMENT)))
        for row in cursor:
            row = self._prepare_row(row, cursor)
            counter['found'] += 1

            room_id = row['MEETING_ROOM_ID'].strip().replace(' ', '-')
            equipment_name = row['EQUIPMENT_NAME']
            building, floor, number = room_id.split('-')

            equipment = self._location.get_equipment_by_name(equipment_name)
            room = Room.find_first(Room.building == building,
                                   Room.floor == floor, Room.number == number)
            try:
                if not room:
                    raise SkipRoom('Room not found in Indico DB')
                if not equipment:
                    raise SkipRoom('Equipment %s not found in Indico DB',
                                   equipment_name)
                if not room.available_equipment.filter(
                        EquipmentType.id == equipment.id).count():
                    room.available_equipment.append(equipment)
                    counter['added'] += 1
                    self._logger.info("Added equipment '%s' to room '%s'",
                                      equipment.name, room.full_name)
                    if equipment == vc_parent:
                        db_vc_equipment = set(
                            room.available_equipment.filter(
                                EquipmentType.parent_id == vc_parent.id))
                        missing_vc_equipment = default_vc_equipment - db_vc_equipment
                        for eq in missing_vc_equipment:
                            room.available_equipment.append(eq)
                            self._logger.info(
                                "Added VC equipment '%s' to room '%s'",
                                eq.name, room.full_name)
                foundation_room_equipment[room].append(equipment.id)
            except SkipRoom as e:
                counter['skipped'] += 1
                self._logger.info("Skipped room %s: %s", room_id, e)

        for room, equipment_types in foundation_room_equipment.iteritems():
            # We handle VC subequipment like equipment that's in the foundation DB since the latter only contains "VC"
            # but no information about the actually available vc equipment...
            vc_equipment_ids = {eq.id for eq in vc_equipment}
            foundation_equipment_ids = set(equipment_types) | vc_equipment_ids
            for equipment in room.available_equipment.filter(
                    ~EquipmentType.id.in_(foundation_equipment_ids)):
                if equipment == vc_parent:
                    for vc_equip in room.available_equipment.filter(
                            EquipmentType.parent_id == vc_parent.id):
                        room.available_equipment.remove(vc_equip)
                        counter['deleted'] += 1
                        self._logger.info(
                            "Deleted VC equipment '%s' from room '%s'",
                            vc_equip.name, room.full_name)
                room.available_equipment.remove(equipment)
                counter['deleted'] += 1
                self._logger.info("Deleted equipment '%s' from room '%s'",
                                  equipment.name, room.full_name)

        db.session.commit()
        self._logger.info(
            "Equipment associations summary: %d found - %d new added - %d skipped - %d deleted",
            counter['found'], counter['added'], counter['skipped'],
            counter['deleted'])
    def fetch_rooms(self, connection, room_name=None):
        self._logger.debug("Fetching room information...")

        counter = Counter()
        foundation_rooms = []

        coordinates = self.fetch_buildings_coordinates(connection)
        cursor = connection.cursor()

        if room_name:
            cursor.execute(
                'SELECT * FROM foundation_pub.meeting_rooms WHERE ID = :room_name',
                room_name=room_name)
        else:
            cursor.execute(
                'SELECT * FROM foundation_pub.meeting_rooms ORDER BY ID')

        for row in cursor:
            counter['found'] += 1
            data = self._prepare_row(row, cursor)
            room_id = data['ID']

            try:
                room_data, email_warning = self._parse_room_data(
                    data, coordinates, room_id)
                room_attrs = self._get_room_attrs(data)
                self._logger.debug("Fetched data for room with id='%s'",
                                   room_id)
            except SkipRoom as e:
                counter['skipped'] += 1
                self._logger.info("Skipped room %s: %s", room_id, e)
                continue

            room = Room.find_first(Room.building == room_data['building'],
                                   Room.floor == room_data['floor'],
                                   Room.number == room_data['number'],
                                   location=self._location)

            if room_data['owner'] is None:
                del room_data['owner']
                if room is None:
                    counter['skipped'] += 1
                    self._logger.info("Skipped room %s: %s", room_id,
                                      email_warning[0] % email_warning[1:])
                    continue
                elif room.is_active:
                    self._logger.warning(*email_warning)

            # Insert new room
            if room is None:
                room = Room()
                self._location.rooms.append(room)
                counter['inserted'] += 1
                self._logger.info("Created new room '%s'", room_id)
            else:
                counter['updated'] += 1

            # Update room data
            room = self._update_room(room, room_data, room_attrs)
            self._logger.info("Updated room '%s' information", room_id)

            foundation_rooms.append(room)

        # Deactivate rooms not found in Foundation
        indico_rooms = Room.find(
            Room.name == room_name) if room_name else Room.find(
                location=self._location)
        rooms_to_deactivate = (
            room for room in indico_rooms
            if room not in foundation_rooms and room.is_active)
        for room in rooms_to_deactivate:
            self._logger.info("Deactivated room '%s'", room.full_name)
            room.is_active = False
            room.is_reservable = False
            counter['deactivated'] += 1
        self._logger.info("Deactivated %d rooms not found in Foundation",
                          counter['deactivated'])

        db.session.commit()
        self._logger.info(
            "Rooms summary: %d in Foundation - %d skipped - %d inserted - %d updated - %d deactivated",
            counter['found'], counter['skipped'], counter['inserted'],
            counter['updated'], counter['deactivated'])