Example #1
0
    def attachments_delete(self, request):
        """Retrieve metainfo for a single attachments for a timeline card"""

        current_user = endpoints.get_current_user()
        if current_user is None:
            raise endpoints.UnauthorizedException("Authentication required.")

        card = ndb.Key("TimelineItem", request.itemId).get()

        if card is None or card.user != current_user:
            raise endpoints.NotFoundException("Attachment not found.")

        if card.attachments is not None:
            for att in card.attachments:
                if att.id == request.attachmentId:
                    # Delete attachment from blobstore
                    blobkey = blobstore.BlobKey(request.attachmentId)
                    blobstore.delete(blobkey)

                    # Remove attachment from timeline card
                    card.attachments.remove(att)
                    card.put()

                    return AttachmentResponse(id=att.id)

        raise endpoints.NotFoundException("Attachment not found.")
Example #2
0
    def timeline_get(self, card):
        """Get card with ID for the current user"""

        if not card.from_datastore or card.user != endpoints.get_current_user():
            raise endpoints.NotFoundException("Card not found.")

        return card
Example #3
0
    def contacts_get(self, contact):
        """Get contact with ID for the current user"""

        if not contact.from_datastore or contact.user != endpoints.get_current_user():
            raise endpoints.NotFoundException("Contact not found.")

        return contact
Example #4
0
    def contacts_update(self, contact):
        """Update Contact with ID for the current user"""

        if not contact.from_datastore or contact.user != endpoints.get_current_user():
            raise endpoints.NotFoundException("Card not found.")

        contact.put()
        return contact
Example #5
0
    def timeline_update(self, card):
        """Update card with ID for the current user"""

        if not card.from_datastore or card.user != endpoints.get_current_user():
            raise endpoints.NotFoundException("Card not found.")

        if card.isDeleted:
            raise endpoints.NotFoundException("Card has been deleted")

        if card.htmlPages is not None and len(card.htmlPages) > 0 and card.bundleId is not None:
            raise endpoints.BadRequestException("Can't mix HTML and Card bundle.")

        card.put()

        channel.send_message(card.user.email(), json.dumps({"id": card.id}))

        return card
Example #6
0
    def subscription_delete(self, subscription):
        """Remove an existing subscription for the current user."""

        if not subscription.from_datastore or subscription.user != endpoints.get_current_user():
            raise endpoints.NotFoundException("Card not found.")

        subscription.key.delete()

        return subscription
Example #7
0
    def contacts_delete(self, contact):
        """Remove an existing Contact for the current user."""

        if not contact.from_datastore or contact.user != endpoints.get_current_user():
            raise endpoints.NotFoundException("Contact not found.")

        contact.key.delete()

        return contact
Example #8
0
    def contacts_delete(self, contact):
        """Remove an existing Contact for the current user."""

        if not contact.from_datastore or contact.user != endpoints.get_current_user(
        ):
            raise endpoints.NotFoundException("Contact not found.")

        contact.key.delete()

        # TODO: Check if a success HTTP code can be returned with an empty body
        return contact
Example #9
0
    def locations_get(self, location):
        """Retrieve a single location for the current user.

        ID can be a specific location ID or "latest" to retrieve the
        latest known position of the user.
        """

        if not location.from_datastore or location.user != endpoints.get_current_user():
            raise endpoints.NotFoundException("Location not found.")

        return location
 def task_delete(self, a_task):
     """ Task Delete. """
     if not a_task.from_datastore:
         raise endpoints.NotFoundException("Task not found.")
     #TODO: Check if current user is in this TaskList
     # Remove the key from the TaskList
     parent_task_list = TaskList.get_by_id(a_task.task_list_id)
     parent_task_list.task_keys.remove(a_task.key)
     parent_task_list.put()
     a_task.key.delete()
     return Task(text="deleted", task_list_id=0)
Example #11
0
    def subscription_delete(self, subscription):
        """Remove an existing subscription for the current user."""

        if not subscription.from_datastore or subscription.user != endpoints.get_current_user(
        ):
            raise endpoints.NotFoundException("Card not found.")

        subscription.key.delete()

        # TODO: Check if a success HTTP code can be returned with an empty body
        return subscription
Example #12
0
    def timeline_update(self, card):
        """Update card with ID for the current user"""

        if not card.from_datastore or card.user != endpoints.get_current_user(
        ):
            raise endpoints.NotFoundException("Card not found.")

        card.put()

        channel.send_message(card.user.email(), json.dumps({"id": card.id}))

        return card
Example #13
0
    def attachments_get(self, request):
        """Retrieve metainfo for a single attachments for a timeline card"""

        current_user = endpoints.get_current_user()
        if current_user is None:
            raise endpoints.UnauthorizedException("Authentication required.")

        card = ndb.Key("TimelineItem", request.itemId).get()

        if card is None or card.user != current_user:
            raise endpoints.NotFoundException("Attachment not found.")

        if card.attachments is not None:
            for att in card.attachments:
                if att.id == request.attachmentId:
                    return AttachmentResponse(id=att.id,
                                              contentType=att.contentType,
                                              contentUrl=att.contentUrl,
                                              isProcessingContent=att.isProcessingContent)

        raise endpoints.NotFoundException("Attachment not found.")
 def TaskListDelete(self, a_task_list):
     """ Delete a TaskList. """
     if not a_task_list.from_datastore:
         raise endpoints.NotFoundException("TaskList not found.")
     #TODO: Check if current user is in this TaskList
     # Delete all the tasks
     for a_task_key in a_task_list.task_keys:
         a_task_key.delete()
     # Remove all the references in the TaskUsers
     TaskList.flush_task_users(a_task_list.id, [])
     a_task_list.key.delete()
     return TaskList(title="deleted")
Example #15
0
    def attachments_list(self, request):
        """Retrieve attachments for a timeline card"""

        current_user = endpoints.get_current_user()
        if current_user is None:
            raise endpoints.UnauthorizedException("Authentication required.")

        card = ndb.Key("TimelineItem", request.itemId).get()

        if card is None or card.user != current_user:
            raise endpoints.NotFoundException("Card not found.")

        attachments = []

        if card.attachments is not None:
            for att in card.attachments:
                attachments.append(AttachmentResponse(id=att.id,
                                                      contentType=att.contentType,
                                                      contentUrl=att.contentUrl,
                                                      isProcessingContent=att.isProcessingContent))

        return AttachmentList(items=attachments)
Example #16
0
def get_job_by_id(request, job_id):
    job = Job.get_by_id(job_id)
    if job is None:
        raise endpoints.NotFoundException(request)
    return job
 def task_list_get(self, a_task_list):
     """ TaskList get. """
     #TODO: Check if current user is in this TaskList
     if not a_task_list.from_datastore:
         raise endpoints.NotFoundException("TaskList not found.")
     return a_task_list
Example #18
0
 def rose_meme_delete(self, a_meme):
     if not a_meme.from_datastore:
         raise endpoints.NotFoundException('Meme not Found')
     a_meme.key.delete()
     return Meme(image_url='Deleted')
Example #19
0
    def timeline_delete(self, card):
        """Remove an existing card for the current user.

        This will set all properties except the ID to None and set isDeleted to true
        """

        if not card.from_datastore or card.user != endpoints.get_current_user(
        ):
            raise endpoints.NotFoundException("Contact not found.")

        if card.isDeleted:
            raise endpoints.NotFoundException("Card has been deleted")

        # Delete attachments
        keys = []
        if card.attachments is not None:
            for att in card.attachments:
                keys.append(blobstore.BlobKey(att.id))
        blobstore.delete_async(keys)

        card.attachments = []
        card.bundleId = None
        card.canonicalUrl = None
        card.created = None
        card.creator = None
        card.displayTime = None
        card.html = None
        card.htmlPages = []
        card.inReplyTo = None
        card.isBundleCover = None
        card.isPinned = None
        card.menuItems = []
        card.notification = None
        card.recipients = []
        card.sourceItemId = None
        card.speakableText = None
        card.text = None
        card.title = None
        card.updated = None
        card.isDeleted = True
        card.put()

        # Notify Glass emulator
        channel.send_message(card.user.email(), json.dumps({"id": card.id}))

        # Notify timeline DELETE subscriptions
        data = {}
        data["collection"] = "timeline"
        data["itemId"] = card.id
        operation = Operation.DELETE
        data["operation"] = operation.name

        header = {"Content-type": "application/json"}

        query = Subscription.query().filter(
            Subscription.user == endpoints.get_current_user())
        query = query.filter(Subscription.collection == "timeline")
        query = query.filter(Subscription.operation == operation)
        for subscription in query.fetch():
            data["userToken"] = subscription.userToken
            data["verifyToken"] = subscription.verifyToken

            req = urllib2.Request(subscription.callbackUrl, json.dumps(data),
                                  header)
            try:
                urllib2.urlopen(req)
            except:
                logging.error(sys.exc_info()[0])

        return card
Example #20
0
    def action_insert(self, action):
        """Perform an action on a timeline card for the current user.

        This isn't part of the actual Mirror API but necessary for the emulator
        to send actions to the subscribed services.

        Returns just a simple success message
        """

        current_user = endpoints.get_current_user()
        if current_user is None:
            raise endpoints.UnauthorizedException("Authentication required.")

        card = ndb.Key("TimelineItem", action.itemId).get()
        if card is None or card.user != current_user:
            raise endpoints.NotFoundException("Card not found.")

        data = None
        operation = None

        if action.action == MenuAction.SHARE:
            operation = Operation.UPDATE
            data = {}
            data["collection"] = "timeline"
            data["itemId"] = action.itemId
            data["operation"] = operation.name
            data["userActions"] = [{"type": MenuAction.SHARE.name}]

        if action.action == MenuAction.REPLY or action.action == MenuAction.REPLY_ALL:
            operation = Operation.INSERT
            data = {}
            data["collection"] = "timeline"
            data["itemId"] = action.itemId
            data["operation"] = operation.name
            data["userActions"] = [{"type": MenuAction.REPLY.name}]

        if action.action == MenuAction.DELETE:
            operation = Operation.DELETE
            data = {}
            data["collection"] = "timeline"
            data["itemId"] = action.itemId
            data["operation"] = operation.name
            data["userActions"] = [{"type": MenuAction.DELETE.name}]

        if action.action == MenuAction.CUSTOM:
            operation = Operation.UPDATE
            data = {}
            data["collection"] = "timeline"
            data["itemId"] = action.itemId
            data["operation"] = operation.name
            data["userActions"] = [{
                "type": MenuAction.CUSTOM.name,
                "payload": action.value
            }]

        if data is not None and operation is not None:
            header = {"Content-type": "application/json"}

            query = Subscription.query().filter(
                Subscription.user == current_user)
            query = query.filter(Subscription.collection == "timeline")
            query = query.filter(Subscription.operation == operation)
            for subscription in query.fetch():
                data["userToken"] = subscription.userToken
                data["verifyToken"] = subscription.verifyToken

                req = urllib2.Request(subscription.callbackUrl,
                                      json.dumps(data), header)
                try:
                    urllib2.urlopen(req)
                except:
                    logging.error(sys.exc_info()[0])

        # Report back to Glass emulator
        channel.send_message(current_user.email(),
                             json.dumps({"id": action.itemId}))

        return ActionResponse(success=True)