Esempio n. 1
0
 def update_delete_rooms_create_resource(self, room_id):
     admin_details = get_user_from_db()
     location_query = location_join_room()
     room_location = location_query.filter(
         RoomModel.id == room_id).first()  # noqa: E501
     if admin_details.location != room_location.name:
         raise GraphQLError("You are not authorized to make changes in " +
                            room_location.name)  # noqa: E501
Esempio n. 2
0
    def mutate(self, info, **kwargs):
        location_query = location_join_room()
        room_location = location_query.filter(
            RoomModel.id == kwargs['room_id']).first()  # noqa: E501
        if not room_location:
            raise GraphQLError("Room not found")
        admin_roles.update_delete_rooms_create_resource(
            room_id=kwargs['room_id'])  # noqa: E501

        resource = ResourceModel(**kwargs)
        resource.save()

        return CreateResource(resource=resource)
Esempio n. 3
0
    def mutate(self, info, **kwargs):
        room_location = location_join_room().filter(
            RoomModel.id == kwargs['room_id'],
            RoomModel.state == 'active').first()
        if not room_location:
            raise GraphQLError("Room not found")
        admin_roles.update_delete_rooms_create_resource(
            room_id=kwargs['room_id'])
        device = DevicesModel(**kwargs,
                              date_added=datetime.now(),
                              last_seen=datetime.now())
        device.save()

        return CreateDevice(device=device)
Esempio n. 4
0
    def update_resource(self, resource_id, room_id):
        admin_details = get_user_from_db()
        location_query = location_join_resources()
        resource_location = location_query.filter(
            ResourceModel.id == resource_id).first()  # noqa: E501

        if admin_details.location != resource_location.name:
            raise GraphQLError("You are not authorized to make changes in " +
                               resource_location.name)  # noqa: E501
        # check room_id incase the resource room is to be updated.
        location_query = location_join_room()
        room_location = location_query.filter(
            RoomModel.id == room_id).first()  # noqa: E501
        if admin_details.location != room_location.name:
            raise GraphQLError("You are not authorized to make changes in " +
                               room_location.name)  # noqa: E501
Esempio n. 5
0
    def mutate(self, info, **kwargs):
        room_location = location_join_room().filter(
            RoomModel.id == kwargs['room_id'],
            RoomModel.state == 'active'
        ).first()
        if not room_location:
            raise GraphQLError("Room not found")
        user = get_user_from_db()
        device = DevicesModel(
            **kwargs,
            date_added=datetime.now(),
            last_seen=datetime.now(),
            location=user.location
        )
        device.save()

        return CreateDevice(device=device)