Ejemplo n.º 1
0
    def get(self, name):
        """GET method send user his preference by preference nme

        Args:
            name (string): Name of user preference which user want download

        Returns:
            zipped preference file
            http response OK 200

        """
        current_user_name = get_jwt_identity()
        current_user = User.query.filter_by(username=current_user_name).first()
        preference_user = Preference_user.query.filter_by(
            user_id=current_user.id).first()
        user_preferences = Curent_user_preference.query.filter_by(
            preference_user_id=preference_user.id, name=name).first()
        print(user_preferences)
        Files.check_buffer(current_user, user_preferences.name, name)
        shutil.copytree(
            Constants.cloud_folder_path(current_user, user_preferences),
            "Buffer\\Preference_user_" + str(current_user.id) + f"/{name}",
            dirs_exist_ok=True)
        name_path = os.path.join(
            "Buffer\\Preference_user_" + str(current_user.id), name)

        shutil.make_archive(
            name_path, 'zip',
            "Buffer/Preference_user_" + str(current_user.id) + f"/{name}")

        return send_file("Buffer/Preference_user_" + str(current_user.id) +
                         f"/{name}.zip",
                         as_attachment=True)
Ejemplo n.º 2
0
def logout():
    """
    GET method

    Logout user from API and DELETE all files from locals folder

    Returns:
        response OK 200
    """
    if current_user.username == 'user':
        return "you are a standard user"
    name = current_user.username
    Files.prepear_to_logout()
    logout_user()

    return f"goodbye {name}"
Ejemplo n.º 3
0
    def post(self, id):
        """POST request which handle Core release folder path

        Args:
            id (int):  User id from DataBase
            request body (string): path tothe Relase folder

        Returns:
            Http response 200

        """

        current_user = User.query.filter_by(id=id).first()
        preference_user = Preference_user.query.filter_by(
            user_id=current_user.id).first()
        current_preference = Curent_user_preference.query.filter_by(
            preference_user_id=preference_user.id,
            current_user_preference=True).first()
        data = request.get_data()
        path = str(data).replace('\\\\', '\\')
        code, out, err = Files.run(["dotnet", path[2:-1]])
        path_to_output = Constants.cloud_folder_path(
            current_user, current_preference) + 'output.txt'
        file = open(path_to_output, 'w+')
        file.write(str(out))
        file.close()

        print(f"for user with id {id}", str(path))
        return HTTPStatus.OK
Ejemplo n.º 4
0
    def post(self):
        """
        POST method

        Point:
            Logging in user and manage his folders on cloud to local

        Args:
            request body (json):
                                {
                                    "preference_name":"Artify",
                                    "password":"******",
                                    "email":"*****@*****.**"
                                }

        Returns:
            string: <hello {username}, welcome on {preference_name}>
            response OK 200

        """

        data = request.get_json()
        password = data['password']
        email = data['email']
        preference_name = data['preference_name']
        Files.check_preference()


        user = User.query.filter_by(email=email).first()

        if not user and not check_password_hash(user.password, password):
            flash("wrong password or email ")
            return HTTPStatus.BAD_REQUEST
        if user.email != 'user':
            Files.prepear_to_logout()
        current_user = User.query.filter_by(id=user.id).first()
        preference_user = Preference_user.query.filter_by(user_id=current_user.id).first()
        current_preference = Curent_user_preference.query.filter_by(preference_user_id=preference_user.id,current_user_preference=True).first()

        if preference_name is None:
            preference_name=current_preference.name


        token = Files.prepear_to_login(user, preference_name, db)
        
        return token, 200
Ejemplo n.º 5
0
    def post(self):
        """POST method
            func set file by request and save it on Buffer then unzipped it
            and synchronization new and update files and

        Args:
            file from request (flask.request.files['file']): Zipped preference  which send user

        Returns:
            200 OK
        """

        file = request.files['file']
        if not file.filename:
            return flash("None selected script")
        if not file.filename.endswith(".zip"):
            return flash("this image not allowed")
        user_preference_user = Preference_user.query.filter_by(user_id=current_user.id).first()
        curent_preference = Curent_user_preference.query.filter_by(preference_user_id=user_preference_user.id,
                                                                   current_user_preference=True).first()
        name = file.filename.split('.')[0]
        name_path = os.path.join("Buffer\\Preference_user_" + str(current_user.id), os.path.join(curent_preference.name))
        path_f = os.path.join("Buffer\\Preference_user_" + str(current_user.id),  curent_preference.name+".zip")
        Files.check_buffer(current_user, curent_preference.name, name)
        Files.check_cloud_folder_structure(current_user, curent_preference)

        file.save(path_f)
        Utils.unzip_folder(path_f, name=name_path)
        Files.Upload_to_cloud(current_user, curent_preference, db, os.path.join(name_path, name))

        shutil.copytree(Constants.cloud_folder_path(current_user, curent_preference), Constants.PREFERENCE_PATH,
                        dirs_exist_ok=True)

        if os.path.exists(path_f):
            os.remove(path_f)
        if os.path.exists(name_path):
            shutil.rmtree(os.path.join("Buffer\\Preference_user_" + str(current_user.id)))

        return HTTPStatus.OK
Ejemplo n.º 6
0
    def post(self):
        """
        Args:
            file from request (flask.request.files['file']): script which send user

        func set file by request and save it on server in folder 'data-storage/Script/' and
        send Core message with name of script.

        Returns:
            200 OK
        """
        current_user_name = get_jwt_identity()
        current_user = User.query.filter_by(username=current_user_name).first()
        data = request.get_json()
        file_name = data['name']
        file_content = data['data']
        extention = data['type']

        user_preference_user = Preference_user.query.filter_by(
            user_id=current_user.id).first()
        if user_preference_user is None:
            return "please log in "
        curent_preference = Curent_user_preference.query.filter_by(
            preference_user_id=user_preference_user.id,
            current_user_preference=True).first()

        file = open(
            os.path.join(
                Constants.cloud_script_folder_path(current_user,
                                                   curent_preference),
                file_name + '.' + extention), 'w')
        file.write(file_content)
        file.close()
        if not os.path.exists("Cloud"):
            os.mkdir("Cloud")
        Files.check_cloud_folder(current_user, curent_preference)
        Files.check_preference()

        shutil.copy(
            Constants.cloud_script_folder_path(current_user, curent_preference)
            + file_name + '.' + extention, Constants.SCRIPT_FOLDER_PATH)
        Files.upload_file(current_user, curent_preference,
                          file_name + '.' + extention, db)

        return HTTPStatus.OK
Ejemplo n.º 7
0
    def post(self):
        """
        Args:
            file from request (flask.request.files['file']): script which send user

        func set file by request and save it on server in folder 'data-storage/Script/' and
        send Core message with name of script.

        Returns:
            200 OK
        """
        current_user_name = get_jwt_identity()
        current_user = User.query.filter_by(username=current_user_name).first()
        file = request.files['file']
        if not file.filename:
            return flash("None selected script")
        if not Utils.allowed_script_type(filename=file.filename):
            return flash("this image not allowed")
        user_preference_user = Preference_user.query.filter_by(
            user_id=current_user.id).first()
        if user_preference_user is None:
            return "please log in "
        curent_preference = Curent_user_preference.query.filter_by(
            preference_user_id=user_preference_user.id,
            current_user_preference=True).first()

        if not os.path.exists("Cloud"):
            os.mkdir("Cloud")
        Files.check_cloud_folder(current_user, curent_preference)
        Files.check_preference()

        file.save(
            os.path.join(
                Constants.cloud_script_folder_path(current_user,
                                                   curent_preference),
                file.filename))
        shutil.copy(
            Constants.cloud_script_folder_path(current_user, curent_preference)
            + file.filename, Constants.SCRIPT_FOLDER_PATH)
        Files.upload_file(current_user, curent_preference, file.filename, db)

        return HTTPStatus.OK
Ejemplo n.º 8
0
    def post(self):
        """
                Args:
                    file from request (flask.request.files['file']): resource which send user

                func set file by request and save it on server in Cloud.

                Returns:
                    200 OK
                """
        current_user_name = get_jwt_identity()
        current_user = User.query.filter_by(username=current_user_name).first()
        file = request.files['file']
        if not file.filename:
            return flash("None selected resource")
        user_preference_user = Preference_user.query.filter_by(
            user_id=current_user.id).first()
        if user_preference_user is None:
            return "please log in "
        curent_preference = Curent_user_preference.query.filter_by(
            preference_user_id=user_preference_user.id,
            current_user_preference=True).first()

        Files.check_cloud_folder(current_user, curent_preference)
        Files.check_preference()
        file.save(
            os.path.join(
                Constants.cloud_resource_folder_path(current_user,
                                                     curent_preference),
                file.filename))
        shutil.copy(
            Constants.cloud_resource_folder_path(
                current_user, curent_preference) + file.filename,
            Constants.RESOURCE_FOLDER_PATH)

        Files.upload_file(current_user, curent_preference, file.filename, db)
        return HTTPStatus.OK