def files_set_public_or_private(self, request, set_public, files_queryset, folders_queryset):

        if not self.has_change_permission(request):
            raise PermissionDenied

        if request.method != 'POST':
            return None

        check_files_edit_permissions(request, files_queryset)
        check_folder_edit_permissions(request, folders_queryset)

        # We define it like that so that we can modify it inside the set_files
        # function
        files_count = [0]

        def set_files(files):
            for f in files:
                if f.is_public != set_public:
                    f.is_public = set_public
                    f.save()
                    files_count[0] += 1

        def set_folders(folders):
            for f in folders:
                set_files(f.files)
                set_folders(f.children.all())

        set_files(files_queryset)
        set_folders(folders_queryset)

        if set_public:
            self.message_user(request, _("Successfully disabled permissions for %(count)d files.") % {
                "count": files_count[0],
            })
        else:
            self.message_user(request, _("Successfully enabled permissions for %(count)d files.") % {
                "count": files_count[0],
            })

        return None
Action which enables or disables permissions for selected files and files in selected folders to clipboard (set them private or public).
dataset/ETHPy150Open django-leonardo/django-leonardo/leonardo/module/media/admin/folder/admin.py/FolderAdmin.files_set_public_or_private