Example #1
0
def copy_file(request):
    """
    Add file from import root directory into clipboard.
    """
    # Assumes incoming path is a full path
    path = request.POST.get('path')
    user = request.user

    # Project uid to check access
    uid = request.POST.get('uid') or 0
    project = Project.objects.filter(id=uid).first()

    if uid and not project:
        return ajax_error(msg="Project does not exist.")

    if project and not auth.is_readable(user=user, obj=project):
        return ajax_error(msg="You do not have access to copy this file")

    if not os.path.exists(path):
        return ajax_error(msg="File path does not exist.")

    if path.startswith(settings.IMPORT_ROOT_DIR) and not user.profile.trusted:
        return ajax_error(
            msg="Only trusted users can copy from this directory.")

    copied = auth.copy_file(request=request, fullpath=path)
    return ajax_success(msg=f"{len(copied)} files copied.")
Example #2
0
def job_file_copy(request, uid, path):
    # Get the root data where the file exists
    job = Job.objects.filter(uid=uid).first()
    fullpath = os.path.join(job.get_data_dir(), path)

    copied = auth.copy_file(request=request, fullpath=fullpath)
    messages.success(request, f"Copied file(s). Clipboard contains {len(copied)} files.")
    return redirect(reverse("job_view", kwargs=dict(uid=uid)))
Example #3
0
def file_copy(request):
    """
    Add file into clipboard.
    """
    path = request.POST.get('path')
    fullpath = os.path.abspath(os.path.join(settings.IMPORT_ROOT_DIR, path))
    if not os.path.exists(fullpath):
        return ajax_error(msg="File path does not exist.")

    copied = auth.copy_file(request=request, fullpath=fullpath)

    return ajax_success(msg=f"{len(copied)} files copied.")