Пример #1
0
 def create_user_db(self):
     # Create database just for users if does not exist
     my_client = mongoDBInterface.get_db_client()
     if not my_client.list_database_names().__contains__("Users"):
         mongoDBInterface.get_db_client()["Users"].create_collection(
             "users")
         mongoDBInterface.get_col("Users", "users")
     mongoDBInterface.get_col("Users", "users").insert_one(self.__dict__)
Пример #2
0
def get_projects():
    id_token = request.args.get('id_token')

    if id_token is None or id_token == "":
        response = {
            'message': "ID Token is not included with the request uri in args"
        }
        response = make_response(response)
        return response, 400

    requestor_email = get_email(id_token)

    if requestor_email is None:
        response = {'message': "ID Token has expired or is invalid"}
        response = make_response(response)
        return response, 400

    all_users_col = get_col("users", "users")
    requestor = all_users_col.find_one({"email": requestor_email})

    if requestor is None:
        response = {'message': "Not authorised to perform this action"}
        response = make_response(response)
        return response, 401

    my_client = get_db_client()
    names = my_client.list_database_names()
    names.remove("admin")
    names.remove("local")
    names.remove("users")
    response = {'projects': names}
    response = make_response(response)
    return response, 200
Пример #3
0
def create_project():
    id_token = request.args.get('id_token')

    if id_token is None or id_token == "":
        response = {
            'message': "ID Token is not included with the request uri in args"
        }
        response = make_response(response)
        return response, 400

    requestor_email = get_email(id_token)

    if requestor_email is None:
        response = {'message': "ID Token has expired or is invalid"}
        response = make_response(response)
        return response, 400

    if 'project_name' in request.json:
        project = request.json['project_name']
    else:
        response = {'message': "Missing project name"}
        response = make_response(response)
        return response, 400

    my_client = get_db_client()
    if re.match(r'^\w+$', project):
        response = {
            'message': "Project name can only be Alphanumerics and underscores"
        }
        response = make_response(response)
        return response, 400

    if project not in my_client.list_database_names():
        create_db_for_proj(project)
        project_user_col = get_col(project, "users")
        project_user_col.insert_one({
            'email': requestor_email,
            'isAdmin': True,
            'isContributor': True
        })
        add_project_to_user(requestor_email, project)
    else:
        response = {'message': "Project already exists"}
        response = make_response(response)
        return response, 400

    return "", 204
Пример #4
0
def delete_project(project_name):
    id_token = request.args.get('id_token')

    if id_token is None or id_token == "":
        response = {
            'message': "ID Token is not included with the request uri in args"
        }
        response = make_response(response)
        return response, 400

    requestor_email = get_email(id_token)

    if requestor_email is None:
        response = {'message': "ID Token has expired or is invalid"}
        response = make_response(response)
        return response, 400

    if project_name == "local" or project_name == "users" or project_name == "admin":
        response = {
            'message':
            "Cannot delete that project because it is not a user created project"
        }
        response = make_response(response)
        return response, 400

    user_col = get_col(project_name, "users")
    requestor = user_col.find_one({'email': requestor_email, 'isAdmin': True})
    if requestor is None:
        response = {'message': "Not authorised for that operation"}
        response = make_response(response)
        return response, 403

    my_client = get_db_client()
    names = my_client.list_database_names()
    if project_name in names:
        all_users = user_col.find({})
        for user in all_users:
            user_email = user['email']
            remove_project_from_user(user_email, project_name)
        my_client.drop_database(project_name)
    else:
        response = {'message': "Project does not exist"}
        response = make_response(response)
        return response, 400

    return "", 204
 def create_project_database(self):
     my_client = mongoDBInterface.get_db_client()
     if not my_client.list_database_names().__contains__(self.name):
         mongoDBInterface.create_db_for_proj(self.name)