示例#1
0
def media_upload(request, *args, **kwargs):
    shop = get_shop(request)
    try:
        folder_id = int(
            request.POST.get("folder_id") or request.GET.get("folder_id") or 0)
        path = request.POST.get("path") or request.GET.get("path") or None
        if folder_id != 0:
            folder = _get_folder_query(shop, request.user).get(pk=folder_id)
        elif path:
            folder = get_or_create_folder(shop, path, request.user)
        else:
            folder = None  # Root folder upload. How bold!
    except Exception as exc:
        return JsonResponse(
            {"error": "Error! Invalid folder `%s`." % force_text(exc)},
            status=400)

    if subfolder_of_users_root(request.user, folder) or has_permission(
            request.user, "media.upload-to-folder"):
        return _process_form(request, folder)

    return JsonResponse(
        {
            "error":
            _("You do not have permission to upload content to this folder")
        },
        status=400)
示例#2
0
    def handle_post_rename_folder(self, data):
        shop = get_shop(self.request)
        folder = _get_folder_query(shop, self.user).get(pk=data["id"])

        # If the folder is not sheard between one or more shop and
        # the folder is in the subfolder tree of the users root folder or the user has folder renaming permissions.
        # Then they are alloed to change rename the folder.
        if not _is_folder_shared(folder) and folder.media_folder.all(
        ).values_list("owners", flat=True)[0] is None and (
                subfolder_of_users_root(self.user, folder)
                or has_permission(self.user, "media.rename-folder")):
            folder.name = data["name"]
            try:
                folder.save(update_fields=("name", ))
                return JsonResponse({
                    "success": True,
                    "message": _("Folder was renamed.")
                })
            except IntegrityError:
                message = _("Folder can't be renamed to %s." % (data["name"]))
                return JsonResponse({"success": False, "message": message})

        message = _(
            "Can't rename this folder, either you don't have permssion to do it "
            "or it's a shared folder between more then one shop or it has a owner"
        )
        return JsonResponse({"success": False, "message": message})
示例#3
0
    def handle_post_delete_folder(self, data):
        shop = get_shop(self.request)
        folder = _get_folder_query(shop, self.user).get(pk=data["id"])

        # If the folder is not sheard between one or more shop and
        # the folder is in the subfolder tree of the users root folder or the user has the folder delete permissions.
        # Then they are alloed to delete the folder.
        if not _is_folder_shared(folder) and (
                subfolder_of_users_root(self.user, folder)
                or has_permission(self.user, "media.delete-folder")):
            new_selected_folder_id = folder.parent_id  # This will be changed by the delete function so save it here.
            try:
                message = delete_folder(folder)
            except models.ProtectedError:
                message = _("This folder is protected and cannot be deleted.")
                return JsonResponse({"success": False, "message": message})
            else:
                return JsonResponse({
                    "success": True,
                    "message": message,
                    "newFolderId": new_selected_folder_id
                })

        message = _(
            "Can't delete this folder, either you don't have permssion to do it "
            "or it's a shared folder between more then one shop")
        return JsonResponse({"success": False, "message": message})
示例#4
0
文件: views.py 项目: yurkobb/shuup
    def handle_post_new_folder(self, data):
        shop = get_shop(self.request)
        parent_id = int(data.get("parent", 0))
        if parent_id > 0:
            parent = _get_folder_query(shop, self.user).get(pk=parent_id)
        else:
            parent = None

        # A users can preform create subfolder under their own root folder no matter their permissions
        if parent and subfolder_of_users_root(self.user, parent):
            return self._create_folder(data["name"], parent, shop)

        # Allows users with teh specifyied permission to create a subfolder
        elif has_permission(self.user, "media.create-folder"):
            return self._create_folder(data["name"], parent, shop)

        else:
            return JsonResponse(
                {"error": _("You do not have permissions to create a subfolder here."), "folder": {"id": parent.id}}
            )