tidyverse / googledrive

Google Drive R API
https://googledrive.tidyverse.org/
Other
322 stars 47 forks source link

drive_mv in Shared Drive environment #377

Closed bllittle closed 2 years ago

bllittle commented 2 years ago

I would like to move files to another folder when uploading a new version so people have a record of previous files to refer to. drive_mv() worked fine for this in April 2021. Now when I try the same code in the same environment (and I continue with the same rights on the folders), I get the following error: Error: Client error: (403) Forbidden A shared drive item must have exactly one parent.

I've also tried this with the overwrite = TRUE parameter, but the same result. EDIT: Here is sample code:


for(ri in 163:length(recFilterSchools)){
  #    ri <- 3 # for testing
    curSchool <- recFilterSchools[ri]
    curFile <- paste0(fileInputPath,curSchool,".xlsx")
    fSave <- paste0(curSchool, fReName, fDate)
    fSchoolURLS <- google_Fldrs_Results %>% filter(SchoolNum==curSchool, FolderName==tList)
    fSchoolURLS_Arch <- google_Fldrs_Results %>% filter(SchoolNum==curSchool, ParentFolder==tList, FolderName=='Archive')
    targetDir <- fSchoolURLS$FileURL
    targetArch <- fSchoolURLS_Arch$FileURL
    parentID <- fSchoolURLS$LocationID
    schID <- fSchoolURLS$schID
    curMslRow <- msl_Results %>%
      filter(SCHOOL_NUMBER==curSchool)

    curSchoolName <- curMslRow$School
    drID <- drive_get(targetDir, verbose = TRUE)
    curFolderContents <- drive_ls(targetDir, 
                                  pattern= tList,
                                  type='spreadsheet')
    #     typeof(curFolderContents)
    #      fmRows <- nrow(curFolderContents)
    fmRows <- nrow(curFolderContents)
    if (fmRows>0){
      for (fm in 1:nrow(curFolderContents)){
        #        fm <-1
        mvFiles <- drive_mv(file=as_id(curFolderContents$id[fm]),
                            path=targetArch
                            ,name= curFolderContents$name[fm])
        drResources <- mvFiles$drive_resource[[1]]
        OutUploadedDF <- rbind(OutUploadedDF, data.frame(stringsAsFactors = FALSE,
                                                         FileID = mvFiles$id,
                                                         FileName = mvFiles$name,
                                                         FilePath = drResources$webViewLink,
                                                         FileParent = parentID,
                                                         FileType = drResources$mimeType,
                                                         DateUploaded  = format(Sys.time(),'%m/%d/%Y'),
                                                         schID = schID))

      }    
    }
  #more code below to upload new file to folder 
}

```thanks
jennybc commented 2 years ago

I would need to see a code snippet that allows me to create the situation and reproduce this. I can't troubleshoot based on the above.

bllittle commented 2 years ago

Hi @jennybc,

I updated with more code -- any thoughts?

Thanks, Bruce

Falnesio commented 2 years ago

Presenting same problem moving newly created test file into test folder in shared drive through drive_mv()

jennybc commented 2 years ago

I haven't delved into this deeply, but I will quickly share that I had a recent bulk file moving task involving a folder on a shared drive and there are definitely limits re: who can do such moves. I actually had to get our Google Workspace admin to elevate my privileges, watch me work on a Zoom call while sharing my screen, then I was de-privileged afterwards.

So my hunch, given my experience and that there's two of you now, is that what you're trying to do may actually not be allowed. Versus being a flaw in the googledrive package.

I could be wrong, but just wanted to mention this, so you can continue to troubleshoot or workaround, before I have time to engage more deeply with this issue.

bllittle commented 2 years ago

Thanks for the response. The error message isn't that it isn't allowed but refers to dual "parentage" having been depreciated. I have sufficient privilege, as I can move the files manually. So, I think there has been a change in Google policy on these objects that has impacted the package code.

On Wed, Oct 20, 2021 at 9:06 AM Jennifer (Jenny) Bryan < @.***> wrote:

I haven't delved into this deeply, but I will quickly share that I had a recent bulk file moving task involving a folder on a shared drive and there are definitely limits re: who can do such moves. I actually had to get our Google Workspace admin to elevate my privileges, watch me work on a Zoom call while sharing my screen, then I was de-privileged afterwards.

So my hunch, given my experience and that there's two of you now, is that what you're trying to do may actually not be allowed. Versus being a flaw in the googledrive package.

I could be wrong, but just wanted to mention this, so you can continue to troubleshoot or workaround, before I have time to engage more deeply with this issue.

ā€” You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/tidyverse/googledrive/issues/377#issuecomment-947759961, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACIY2CS76YW3MNYYDXKEZU3UH3LIPANCNFSM5FPSPV6Q . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

Falnesio commented 2 years ago

Thank you for the quick reply, and sorry for responding so late.

I am admin, but I checked to see if I have used the wrong account, and it was not the case. I got this:

Client error: (403) Forbidden A shared drive item must have exactly one parent.

jennybc commented 2 years ago

Yeah I think I know what the problem is. I'm pretty sure it's a relatively easy fix.

jennybc commented 2 years ago

I've been able to replicate the problem and fix it with #379. I remember initially being pleasantly surprised that I could just add a parent folder, w/o removing the previous one. As we've all experienced, that did work at one point in time. But it no longer does and, frankly, the current behaviour was always sort of implied by the docs. So now I add and remove parent(s) in one atomic operation.

I need to test this solution a bit more, before I merge it, but if anyone here wants to independently verify that this is basically the fix, feel free to install from that PR and report back.

Here are some ways to install googledrive from that PR:

install.packages("pak", repos = "https://r-lib.github.io/p/pak/dev/")
pak::pkg_install("tidyverse/googledrive#379")

# or
devtools::install_github("tidyverse/googledrive#379")
bllittle commented 2 years ago

I'll give it a shot tomorrow and let you know.

Thanks!

On Thu, Oct 28, 2021 at 7:53 PM Jennifer (Jenny) Bryan < @.***> wrote:

I've been able to replicate the problem and fix it with #379 https://github.com/tidyverse/googledrive/pull/379. I remember initially being pleasantly surprised that I could just add a parent folder, w/o removing the previous one. As we've all experienced, that did work at one point in time. But it no longer does and, frankly, the current behaviour was always sort of implied by the docs. So now I add and remove parent(s) in one atomic operation.

I need to test this solution a bit more, before I merge it, but if anyone here wants to independently verify that this is basically the fix, feel free to install from that PR and report back.

Here are some ways to install googledrive from that PR:

install.packages("pak", repos = "https://r-lib.github.io/p/pak/dev/")pak::pkg_install("tidyverse/googledrive#379")

ordevtools::install_github("tidyverse/googledrive#379")

ā€” You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/tidyverse/googledrive/issues/377#issuecomment-954346674, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACIY2CU75EFWFK2ZE43OGF3UJH47ZANCNFSM5FPSPV6Q . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

Falnesio commented 2 years ago

The solution has worked here. Thank you very much!

jennybc commented 2 years ago

More background, mostly for myself: the existing logic seems to work in a user's My Drive. But you do really have to remove parent +add parent if the file in question lives on a shared drive. This problem is currently only affecting people moving files around on a shared drive.

bllittle commented 2 years ago

Hi Jenny,

Sorry for coming back to this topic after so long. We're finally back in need of this and still getting the same error in the loaded googledrive package. Was the fix ever put into the production package?

I've been trying to load the "fix" package, but it hangs during the install stage (has been installing for the past 20 minutes as I write this).

The scenario we have that would make it nice to actually move a file from one folder to another is as follows:

Thanks for the great package otherwise.

Thanks, Bruce

On Fri, Oct 29, 2021 at 4:41 PM Jennifer (Jenny) Bryan < @.***> wrote:

More background, mostly for myself: the existing logic seems to work in a user's My Drive. But you do really have to remove parent +add parent if the file in question lives on a shared drive. This problem is currently only affecting people moving files around on a shared drive.

ā€” You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/tidyverse/googledrive/issues/377#issuecomment-955086341, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACIY2CR2R2MMA33OYSNIRA3UJMPIPANCNFSM5FPSPV6Q . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

bllittle commented 2 years ago

Well, now I have a red face.

After sending this, I stopped the install process. I got an "RStudio is not responding" message and allowed it to restart. I went back to the original load process and now it is indeed moving files.

At least you got a broader context of the need. šŸ˜Ž

Thanks again.

On Mon, Mar 7, 2022 at 4:28 PM The Bruce, Mile High @.***> wrote:

Hi Jenny,

Sorry for coming back to this topic after so long. We're finally back in need of this and still getting the same error in the loaded googledrive package. Was the fix ever put into the production package?

I've been trying to load the "fix" package, but it hangs during the install stage (has been installing for the past 20 minutes as I write this).

The scenario we have that would make it nice to actually move a file from one folder to another is as follows:

  • We are a large urban school district. I work in Central Office and help in planning standardized testing.
  • We deliver files with lists of students who are scheduled for standardized tests to schools via a series of shared folders. We must manage sharing on these folders because the information about the students that we share should only be seen by administrators and teachers at THAT school and not any of our other schools
  • We use outside vendors to supply the tests themselves. We get files from vendors on which students THEY think are scheduled for testing at a particular school.
  • Since families move, there are many instances when a student may change schools. Or, a parent may decide they do not wish for their child to participate in standardized testing. Anyway, there are many situations where the lists of students at a given school may change.
  • Due to that fact, we re-publish files on a weekly basis from early in the semester until testing is completed.
  • School level administrators have requested that we maintain prior files for reference. The preferred method is to MOVE this file into an "archive" folder. Without the move capability, we resort to renaming the file. But this results in many files an administrator must scroll through to get to the most recent student list file.

Thanks for the great package otherwise.

Thanks, Bruce

On Fri, Oct 29, 2021 at 4:41 PM Jennifer (Jenny) Bryan < @.***> wrote:

More background, mostly for myself: the existing logic seems to work in a user's My Drive. But you do really have to remove parent +add parent if the file in question lives on a shared drive. This problem is currently only affecting people moving files around on a shared drive.

ā€” You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/tidyverse/googledrive/issues/377#issuecomment-955086341, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACIY2CR2R2MMA33OYSNIRA3UJMPIPANCNFSM5FPSPV6Q . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

deschen1 commented 2 years ago

Not sure if entirely related this bug, but I have the same error/issue and it still doesn't work, see my SO post: https://stackoverflow.com/questions/73750125/trying-to-move-a-google-drive-file-with-googledrive-package-results-in-403-error

jennybc commented 2 years ago

@deschen1 Apparently I haven't released googledrive since I made this fix. This appears to the be only (substantive) change made since the last release.

So for now, you need to use the dev version.

deschen1 commented 2 years ago

Ah ok, that probably explains it.

Since we are here, do you have any idea/plan on next releases? I understand the desire to avoid the overhead of publishing a new release just for a supposedly minor bug fix, but since it's several people now making it so far to respond on the dev page of the package, I feel there's indeed an audience for an updated version. ;-)

jennybc commented 2 years ago

I have to release gargle soon for other reasons, so then it would make sense to release googledrive (which currently depends on dev gargle). I'll put this on my near-term todo list.