コード例 #1
0
ファイル: schema.py プロジェクト: verenceLola/mrm_api
 def mutate(self, info, **kwargs):
     # mutation to create an event
     room_id, event = check_event_in_db(self, info, "cancelled", **kwargs)
     try:
         device_last_seen = parser.parse(
             kwargs['start_time']) + timedelta(minutes=10)
     except ValueError:
         raise GraphQLError("Invalid start time")
     update_device_last_seen(info, room_id, device_last_seen)
     if not event:
         event = EventsModel(
             event_id=kwargs['event_id'],
             room_id=room_id,
             event_title=kwargs['event_title'],
             start_time=kwargs['start_time'],
             end_time=kwargs['end_time'],
             number_of_participants=kwargs['number_of_participants'],
             checked_in=False,
             cancelled=True,
             auto_cancelled=True)
         event.save()
     calendar_event = get_single_calendar_event(kwargs['calendar_id'],
                                                kwargs['event_id'])
     event_reject_reason = 'after 10 minutes'
     if not notification.event_cancellation_notification(
             calendar_event, room_id, event_reject_reason):
         raise GraphQLError("Event cancelled but email not sent")
     return CancelEvent(event=event)
コード例 #2
0
ファイル: schema.py プロジェクト: marcdomain/mrm_api
    def mutate(self, info, **kwargs):
        room_id, event = check_event_in_db(self, info, "ended", **kwargs)
        if not event:
            event = EventsModel(event_id=kwargs['event_id'],
                                meeting_end_time=kwargs['meeting_end_time'])
            event.save()

        return EndEvent(event=event)
コード例 #3
0
    def sync_single_room_events(self, room):
        """
        This method gets data from the calendar api
        and syncs it with the local data

        """
        next_page = None
        next_sync_token = None
        while True:
            event_results = get_google_calendar_events(
                calendarId=room.calendar_id,
                syncToken=room.next_sync_token,
                pageToken=next_page)

            next_page = event_results.get("nextPageToken")
            room_events = event_results["items"]
            next_sync_token = event_results.get("nextSyncToken")
            for event in room_events:
                existing_event = EventsModel.query.filter_by(
                    event_id=event.get("id")).first()
                participants = event.get('attendees')
                number_of_attendees = 0
                if participants:
                    number_of_attendees = len(participants)

                if existing_event and event.get("status") == "cancelled":
                    existing_event.state = "archived"
                    existing_event.save()

                elif existing_event:
                    existing_event.event_title = event.get("summary")
                    existing_event.start_time = event["start"].get(
                        "dateTime") or event["start"].get("date")
                    existing_event.end_time = event["end"].get(
                        "dateTime") or event["end"].get("date")
                    existing_event.number_of_participants = number_of_attendees
                    existing_event.save()

                elif not event.get("status") == "cancelled":
                    new_event = EventsModel(
                        event_id=event.get("id"),
                        recurring_event_id=event.get("recurringEventId"),
                        room_id=room.id,
                        event_title=event.get("summary"),
                        start_time=event["start"].get("dateTime")
                        or event["start"].get("date"),
                        end_time=event["end"].get("dateTime")
                        or event["end"].get("date"),
                        number_of_participants=number_of_attendees,
                        checked_in=False,
                        cancelled=False)
                    new_event.save()
            if not next_page:
                break

        room.next_sync_token = next_sync_token
        room.save()
コード例 #4
0
 def update_recurring_event_status(self):
     """
     checks for events to cancel and updates the relevant data
     to the events model
     """
     print("cancelling events...")
     query = RoomModel.query
     now = datetime.utcnow().isoformat() + "Z"
     next_day = (datetime.utcnow() +
                 relativedelta(hours=24)).isoformat() + "Z"
     events = self.get_all_recurring_events(query, now, next_day)
     for event in events:
         start_date = event["start_date"]
         end_date = event["end_date"]
         new_recurring_event = EventsModel(
             event_id=event["event_id"],
             recurring_event=event["recurring_event_id"],
             room_id=event["room_id"],
             event_title=event["event_summary"],
             start_time=start_date,
             end_time=end_date,
             checked_in=False,
             cancelled=False)
         event_query = EventsModel.query
         calendar_id = event["calendar_id"]
         recurring_event_id = event["recurring_event_id"]
         service = Credentials().set_api_credentials()
         missed_checkins = event_query.filter(
             EventsModel.recuring_event_id == event["recurring_event_id"]
             and EventsModel.checked_in == "False")
         if missed_checkins.count() >= 3:
             event = service.events().get(
                 calendarId=calendar_id,
                 eventId=recurring_event_id).execute()
             attendees = event["attendees"]
             room_index = self.get_room_index_from_attendees(
                 attendees, calendar_id)
             event["attendees"][room_index]["responseStatus"] = "declined"
             service.events().patch(calendarId=calendar_id,
                                    eventId=recurring_event_id,
                                    body=event,
                                    sendUpdates="all").execute()
             event_in_database = EventsModel.query.filter_by(
                 id=event.get("id")).first()
             room_id = event_in_database.room_id
             event_reject_reason = "for 3 consecutive meetings"
             if not event_cancellation_notification(event, room_id,
                                                    event_reject_reason):
                 raise GraphQLError("Event cancelled but email not sent")
             for missed_checkin in missed_checkins:
                 missed_checkin.state = "archived"
                 missed_checkin.save()
         else:
             event_exists = event_query.filter_by(
                 event_id=event["event_id"])
             if not event_exists.count():
                 new_recurring_event.save()
コード例 #5
0
ファイル: schema.py プロジェクト: peterwade153/mrm_api
    def mutate(self, info, **kwargs):
        room_id = Events.check_status(self, info, **kwargs)
        cancelled_event = EventsModel(event_id=kwargs['event_id'],
                                      room_id=room_id,
                                      checked_in=False,
                                      cancelled=True)
        cancelled_event.save()

        return CancelEvent(event=cancelled_event)
コード例 #6
0
ファイル: schema.py プロジェクト: peterwade153/mrm_api
    def mutate(self, info, **kwargs):
        room_id = Events.check_status(self, info, **kwargs)
        new_event = EventsModel(event_id=kwargs['event_id'],
                                room_id=room_id,
                                checked_in=True,
                                cancelled=False)
        new_event.save()

        return EventCheckin(event=new_event)
コード例 #7
0
ファイル: schema.py プロジェクト: marcdomain/mrm_api
 def mutate(self, info, **kwargs):
     room_id, event = check_event_in_db(self, info, "checked_in", **kwargs)
     if not event:
         event = EventsModel(
             event_id=kwargs['event_id'],
             room_id=room_id,
             event_title=kwargs['event_title'],
             start_time=kwargs['start_time'],
             end_time=kwargs['end_time'],
             number_of_participants=kwargs['number_of_participants'],
             checked_in=True,
             cancelled=False)
         event.save()
     return EventCheckin(event=event)
コード例 #8
0
ファイル: schema.py プロジェクト: marcdomain/mrm_api
    def mutate(self, info, **kwargs):
        # mutation to create an event
        room_id, event = check_event_in_db(self, info, "cancelled", **kwargs)
        if not event:
            event = EventsModel(
                event_id=kwargs['event_id'],
                room_id=room_id,
                event_title=kwargs['event_title'],
                start_time=kwargs['start_time'],
                end_time=kwargs['end_time'],
                number_of_participants=kwargs['number_of_participants'],
                checked_in=False,
                cancelled=True)
            event.save()

        return CancelEvent(event=event)
コード例 #9
0
ファイル: base.py プロジェクト: marcdomain/mrm_api
    def setUp(self):
        app = self.create_app()
        self.app_test = app.test_client()
        with app.app_context():
            Base.metadata.create_all(bind=engine)

            command.stamp(self.alembic_configuration, 'head')
            command.downgrade(self.alembic_configuration, '-1')
            command.upgrade(self.alembic_configuration, 'head')

            admin_user = User(email="*****@*****.**",
                              location="Kampala",
                              name="Peter Walugembe",
                              picture="https://www.andela.com/walugembe")
            admin_user.save()
            lagos_admin = User(email="*****@*****.**",
                               location="Lagos",
                               name="Peter Adeoye",
                               picture="https://www.andela.com/adeoye")
            lagos_admin.save()
            global role
            role = Role(role="Admin")
            role.save()
            admin_user.roles.append(role)
            lagos_admin.roles.append(role)
            tag = Tag(name='Block-B',
                      color='green',
                      description='The description')
            tag.save()
            root_node = OfficeStructure(name='location', tag_id=1)
            root_node.save()
            leaf_node = OfficeStructure(name='wings', parent_id=1)
            leaf_node.save()

            location = Location(name='Kampala',
                                abbreviation='KLA',
                                structure_id=1)
            location.save()
            location_two = Location(name='Nairobi',
                                    abbreviation='NBO',
                                    structure_id=1)
            location_two.save()
            location_three = Location(name='Lagos',
                                      abbreviation='LOS',
                                      structure_id=1)
            location_three.save()
            tag_two = Tag(name='Block-C',
                          color='blue',
                          description='The description')
            tag_two.save()
            room = Room(
                name='Entebbe',
                room_type='meeting',
                capacity=6,
                location_id=location.id,
                calendar_id=
                '*****@*****.**',  # noqa: E501
                image_url=
                "https://www.officelovin.com/wp-content/uploads/2016/10/andela-office-main-1.jpg"
            )  # noqa: E501
            room.save()
            room.room_tags.append(tag)
            resource = Resource(name='Markers', quantity=3, room_id=room.id)
            resource.save()
            device = Devices(last_seen="2018-06-08T11:17:58.785136",
                             date_added="2018-06-08T11:17:58.785136",
                             name="Samsung",
                             location="Nairobi",
                             device_type="External Display")
            device.save()
            question_1 = Question(
                question_type="rate",
                question_title="Rating Feedback",
                question="How will you rate the brightness of the room",
                start_date="20 Nov 2018",
                end_date="28 Nov 2018",
                is_active=True)
            question_1.save()
            question_2 = Question(
                question_type="check",
                question_title="check Feedback",
                question="Is there anything missing in the room",
                start_date="20 Nov 2018",
                end_date="30 Nov 2018",
                is_active=True)
            event = Events(event_id="test_id5",
                           room_id=1,
                           event_title="Onboarding",
                           start_time="2018-07-11T09:00:00Z",
                           end_time="2018-07-11T09:45:00Z",
                           number_of_participants=4,
                           checked_in=False,
                           cancelled=False)
            event.save()
            question_2.save()
            question_3 = Question(question_type="input",
                                  question_title="input Feedback",
                                  question="Any other suggestion",
                                  start_date="20 Nov 2018",
                                  end_date="28 Nov 2018")
            question_3.save()
            response_1 = Response(
                question_id=1,
                room_id=1,
                rate=2,
                created_date=datetime.now(),
                resolved=False,
            )
            response_1.save()
            response_2 = Response(
                question_id=question_2.id,
                room_id=room.id,
                check=True,
                created_date=datetime.now(),
                resolved=True,
            )
            response_2.save()
            response_2.missing_resources.append(resource)
            structure = Structure(
                structure_id='b05fc5f2-b4aa-4f48-a8fb-30bdcc3fc968',
                level=1,
                name='Epic tower',
                parent_id="1",
                parent_title="parent_title",
                tag='Building',
                location_id=1,
                position=1,
            )
            structure.save()
            db_session.commit()
コード例 #10
0
ファイル: base.py プロジェクト: verenceLola/mrm_api
    def setUp(self, mock_verify_calendar_id):
        app = self.create_app()
        self.app_test = app.test_client()
        with app.app_context():
            Base.metadata.create_all(bind=engine)

            command.stamp(self.alembic_configuration, 'head')
            command.downgrade(self.alembic_configuration, '-1')
            command.upgrade(self.alembic_configuration, 'head')

            admin_user = User(email="*****@*****.**",
                              name="Peter Walugembe",
                              picture="https://www.andela.com/walugembe")
            admin_user.location = "Kampala"
            admin_user.save()
            lagos_admin = User(email="*****@*****.**",
                               location="Lagos",
                               name="Peter Adeoye",
                               picture="https://www.andela.com/adeoye")
            lagos_admin.save()
            global role
            role = Role(role="Admin")
            role.save()
            role_2 = Role(role="Test")
            role_2.save()
            role_3 = Role(role="Super Admin")
            role_3.save()
            admin_user.roles.append(role)
            lagos_admin.roles.append(role)
            tag = Tag(name='Block-B',
                      color='green',
                      description='The description')
            tag.save()

            location = Location(name='Kampala', abbreviation='KLA')
            location.save()
            location_two = Location(name='Nairobi', abbreviation='NBO')
            location_two.save()
            location_three = Location(name='Lagos', abbreviation='LOS')
            location_three.save()
            tag_two = Tag(name='Block-C',
                          color='blue',
                          description='The description')
            tag_two.save()
            room = Room(
                name='Entebbe',
                room_type='meeting',
                capacity=6,
                location_id=location.id,
                structure_id='851ae8b3-48dd-46b5-89bc-ca3f8111ad87',
                calendar_id=
                '*****@*****.**',  # noqa: E501
                image_url=
                "https://www.officelovin.com/wp-content/uploads/2016/10/andela-office-main-1.jpg",  # noqa: E501
                room_labels=["1st Floor", "Wing A"])
            room.save()
            room.room_tags.append(tag)
            room_2 = Room(
                name='Tana',
                room_type='meeting',
                capacity=14,
                location_id=location.id,
                structure_id='851ae8b3-48dd-46b5-89bc-ca3f8111ad87',
                calendar_id=
                '*****@*****.**',  # noqa: E501
                image_url=
                "https://www.officelovin.com/wp-content/uploads/2016/10/andela-office-main-1.jpg",  # noqa: E501
                room_labels=["1st Floor", "Wing B"])
            room_2.save()
            room_2.room_tags.append(tag)
            resource = Resource(name='Markers', quantity=3)
            resource.save()
            device = Devices(last_seen="2018-06-08T11:17:58.785136",
                             date_added="2018-06-08T11:17:58.785136",
                             name="Samsung",
                             location="Kampala",
                             device_type="External Display",
                             room_id=1,
                             state="active")
            device.save()
            question_1 = Question(
                question_type="rate",
                question_title="Rating Feedback",
                question="How will you rate the brightness of the room",
                start_date="20 Nov 2018",
                end_date="28 Nov 2018",
                is_active=True)
            question_1.save()
            question_2 = Question(
                question_type="check",
                question_title="check Feedback",
                question="Is there anything missing in the room",
                check_options=['apple tv', 'whiteboard', 'maker pen'],
                start_date="20 Nov 2018",
                end_date="30 Nov 2018",
                is_active=True)
            event = Events(event_id="test_id5",
                           room_id=1,
                           event_title="Onboarding",
                           start_time="2018-07-11T09:00:00Z",
                           end_time="2018-07-11T09:45:00Z",
                           number_of_participants=4,
                           checked_in=False,
                           cancelled=False)
            event.save()
            question_2.save()
            question_3 = Question(question_type="input",
                                  question_title="input Feedback",
                                  question="Any other suggestion",
                                  start_date="20 Nov 2018",
                                  end_date="28 Nov 2018")
            question_3.save()
            question_4 = Question(question_type="check",
                                  question_title="Missing item",
                                  question="Anything missing in the room?",
                                  check_options=['duster'],
                                  start_date="20 Nov 2018",
                                  end_date="30 Nov 2018",
                                  is_active=True)
            question_4.save()
            response_1 = Response(
                question_id=1,
                room_id=1,
                question_type="rate",
                created_date=datetime.now(),
                response="1",
                resolved=False,
            )
            response_1.save()

            response_2 = Response(
                question_id=question_2.id,
                room_id=room.id,
                question_type="check",
                created_date=datetime.now(),
                response=['marker pen', 'apple tv'],
                resolved=True,
            )
            response_2.save()
            response_2.missing_resources.append(resource)

            response_3 = Response(question_id=question_4.id,
                                  room_id=room_2.id,
                                  question_type="check",
                                  created_date=datetime.now(),
                                  response=['duster'],
                                  resolved=True,
                                  state="archived")
            response_3.save()

            structure = Structure(
                structure_id='b05fc5f2-b4aa-4f48-a8fb-30bdcc3fc968',
                level=1,
                name='Epic tower',
                parent_id="1",
                parent_title="parent_title",
                tag='Building',
                location_id=1,
                position=1,
            )
            structure.save()
            parent_node = OfficeStructure(
                id='C56A4180-65AA-42EC-A945-5FD21DEC0518',
                name='Epic Tower',
                tag='Lagos Building',
                location_id=1)
            parent_node.save()
            child_node = OfficeStructure(
                id='C56A4180-65AA-42EC-A945-5FD21DEC0519',
                name='Gold Coast',
                tag='First Floor',
                parent_id='C56A4180-65AA-42EC-A945-5FD21DEC0518',
                location_id=1)
            child_node.save()
            db_session.commit()
            f = open('mrm.err.log', 'a+')
            f.write('[2019-08-06 13:22:32 +0000] [1574] [ERROR] Error /logs\r')
            f.write('Traceback (most recent call last):\r')
            f.write('if pattern.search(line):\r')