def post(self):
        try:
            form = request.form  #the form submitted
            SID = form["sessionId"]  #gets SID from cookie
            session = AuthenticationService.getSession(
                SID)  #uses SID to get session from db
            user = session["user"]  #gets user from session

            # found user, remove their datasets
            try:
                Dataset.objects(author=user).delete()
            except:
                return Response("Error deleting datasets.", status=403)
            # once datasets have been removed, remove user from users
            try:
                # log out before deletion
                sessionId = request.form["sessionId"]
                AuthenticationService.logout(sessionId)
                # remove user with query by email
                user.delete()
            except:
                return Response("Error deleting user.", status=403)
            return Response("Account deleted.", status=200)
        except:
            return Response("Error getting user from session.", status=403)
Exemplo n.º 2
0
def getDataset(datasetId):
    user = AuthenticationService.verifySessionAndReturnUser(
        request.cookies["SID"])
    dataset = Dataset.objects.get(id=datasetId)

    if dataset == None:
        return Response(
            "Unable to retrieve dataset information. Please try again later.",
            status=400)
    if (dataset.public == False and dataset.author != user):
        return Response("You do not have permission to access that dataset.",
                        status=403)

    Dataset.objects(id=datasetId).update_one(inc__views=1)
    AuthenticationService.updateRecentDatasets(request.cookies["SID"],
                                               datasetId)
    return Response(
        DatasetService.createDatasetInfoObject(dataset, withHeaders=True))
Exemplo n.º 3
0
def new():
    try:
        retList = []
        user = AuthenticationService.verifySessionAndReturnUser(
            request.cookies["SID"])
        # get users datasets by date created and sort by descending order
        newDatasets = Dataset.objects(author=user).order_by("-dateCreated")[:5]
        for dataset in newDatasets:
            if dataset == None:
                return Response("No datasets found", status=404)
            retList.append(DatasetService.createDatasetInfoObject(dataset))
        return Response(retList)
    except Exception as e:
        print(e)
        return Response("Couldn't retrieve recent datasets", status=400)
Exemplo n.º 4
0
    def createDataset(self, request, uploadTime):
        try:
            #keep track of when request was made
            user = AuthenticationService.verifySessionAndReturnUser(
                request.cookies["SID"])

            if (not user):
                return {"message": "Invalid session", "status": 400}

            #TODO: verify that these parameters exist
            uploadedFile = request.files['file']
            dataSetName = request.form.get("name")
            dataSetAuthor = user
            dataSetIsPublic = True if request.form.get(
                "permissions") == "Public" else False
            dataSetTags = request.form.get("tags").split(',')
            dataSetType = request.form.get("type")

            if (len(dataSetTags) == 1):
                if (dataSetTags[0] == ""):
                    dataSetTags.pop()

            data = pd.read_csv(uploadedFile)
            keys = list(data.columns)

            if (data.isnull().values.sum() > 0):
                raise ValueError

            #Add new tags to collection
            for tag in dataSetTags:
                newTag = Tag(name=tag, datasetType=dataSetType)
                newTag.validate()
                if not self.tagExist(newTag):
                    newTag.save()

            #Create and save dataset object
            dataset = Dataset(name=dataSetName,
                              author=dataSetAuthor,
                              keys=keys,
                              public=dataSetIsPublic,
                              tags=dataSetTags,
                              datasetType=dataSetType,
                              views=1)
            dataset.save()

            #Go back to the front of the file
            uploadedFile.seek(0)

            #Save to S3
            self.uploadToAWS(dataset.id, uploadedFile)

            uploadCompletedDate = str(datetime.datetime.now()).split(".")[0]

            headline = f"Your <b>{dataset.name}</b> dataset has finished processing. <br> <br> "
            uploadString = f"<b>Upload Received</b>: {uploadTime} <br> <br> <b>Upload Completed</b>: {uploadCompletedDate}<br> <br>"
            datasetLink = f"<b> Link below to view your dataset: </b> <br> <a href ='{app.rootUrl}/dataset/{dataset.id}'>{app.rootUrl}/dataset/{dataset.id}</a>."
            formattedMessage = headline + uploadString + datasetLink
            MailService.sendMessage(user, "Dataset successfully uploaded",
                                    formattedMessage)

            return dataset

        except ValidationError as e:
            print(e)
            return None