Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Shared GDrive parent folder in location argument being ignored when automatically converted from v1 #111

Closed
John-Balla-Omnium opened this issue Sep 11, 2023 · 9 comments
Labels

Comments

@John-Balla-Omnium
Copy link

Describe the bug

While trying to use a shared drive as a parent folder in the location argument of an attachment action, the shared folder ID is being ignored and the files are being saved to my personal 'My Drive' instead.

To Reproduce

Steps to reproduce the behavior:

Use the following thread:

  description: "Gmail2GDrive for Reports",
  settings: {
    // Place settings here
    maxBatchSize: 50,
    maxRuntime: 600,
    sleepTimeThreads: 100,
    sleepTimeMessages: 0,
    sleepTimeAttachments: 0,
    timezone: "Australia/Sydney",
  },
  global: {
    thread: {
      match: {
        query: "has:attachment in:inbox newer_than:1d",
      }
    },
  },
  threads: [
    {
      match: {
        query: "from:john.balla@xxxxxxxx.com.au to:john.balla@xxxxxxxx.com.au Report",
      },
      attachments: [
        {
          actions: [
            {
              args: {
                location: '\${id:11111111xxxxxxxx}/Reports-${message.date:format:yyyy-MM-dd}/${attachment.name}',
              },
              name: "attachment.store",
            },
          ],
        },
      ],
    },
  ],

Expected behavior

I would expect a folder called Reports-2023-09-11 to be created inside the shared folder with the attachment name from the file itself to be created inside that folder. Instead the folder appears in 'My Drive' (albiet formatted correctly and the attachment inside). Keep in mind when I use the following format, it works to save it to my 'My Drive', but this is expected:

'\Reports-${message.date:format:yyyy-MM-dd}/${attachment.name}'

Additional context

Affected version of gmail-processor: 6

Add any other context about the problem here.

I was having issues with the V1 to V2 config converter so I have been playing with the config ever since to try to get this to work like it did on V1.

@ahochsteger
Copy link
Owner

@John-Balla-Omnium there's a leading Backslash in the location configuration you should remove.
Try again and make sure to use the latest release.
Let me know if it works.

@John-Balla-Omnium
Copy link
Author

John-Balla-Omnium commented Sep 12, 2023

Sorry for misleading, the leading backslash was just another thing I tested, but it produces the same results either way, even when storing on My Drive. To add some detail, the result in the execution log looks like this:

Creating file 'Daily_Report_2023-07-05_08-00.pdf' in folder 'My Drive' ...

Whereas when I leave the ID off and set it to actually store on My Drive, the 'My Drive' output is replaced with 'Reports-2023-07-05', as expected.

For what it's worth, I'm having other problems too, like the global match query not working (in:inbox newer_than:1d is:unread), but these are likely due to the older emails being in threads and they are getting picked up in the thread with the new email that is new/unread/in inbox.

@ahochsteger
Copy link
Owner

ahochsteger commented Sep 13, 2023

@John-Balla-Omnium, can you please update to the latest version (release 2.1.0, version 9 in Google Apps Script) and try it again?
It fixes the broken Gmail2GDrive config conversion and fixes a logging bug that helps to diagnose errors.
In case you still have problems, please provide the log output you get.

@John-Balla-Omnium
Copy link
Author

John-Balla-Omnium commented Sep 14, 2023

I tested in version 7 yesterday, updated to 9 today, tested with the new config details. Still just the same Info logs, no error:

3:27:19 PM Info [2023-09-14T05:27:19.782Z] INFO: Processing of attachment hash 'df27d177_6d28effb_41d1058f_af8a012e_721345f0' (name:'Report_2023-09-14_08-00.pdf', type:application/pdf, size:496604) started ...
3:27:19 PM Info [2023-09-14T05:27:19.783Z] INFO: Executing action 'attachment.store' with args: {"location":"${id:1j9sF-Q7J5VqMAzts25NcH-3yZGV0TKyD}/MonthlyReports-${message.date:format:yyyy-MM-dd}/${attachment.name}","conflictStrategy":"keep"}
3:27:19 PM Info [2023-09-14T05:27:19.784Z] DEBUG: Calling method 'store' ...
3:27:19 PM Info [2023-09-14T05:27:19.786Z] INFO: Storing attachment 'Report_2023-09-14_08-00.pdf' to '/Report_2023-09-14_08-00.pdf' ...
3:27:20 PM Info [2023-09-14T05:27:20.024Z] INFO: Creating file 'Report_2023-09-14_08-00.pdf' in folder 'My Drive' ...
3:27:22 PM Info [2023-09-14T05:27:22.892Z] INFO: Action result: {"ok":true,"file":{}}

If you notice that 'My Drive' is still being defaulted to for the location whenever I put in the parent folder id. If I state the name of the folder instead of the parent folder id, I can get it to save to that folder, as long as it is in My Drive, but obviously the same doesn't work for Shared Drives.

I kept testing a bit and found if I put just the parent folder id and no sub-directory folder, like so:
"${id:1j9sF-Q7J5VqMAzts25NcH-3yZGV0TKyD}/${attachment.name}",
then I get the following error:

3:42:34 PM Info [2023-09-14T05:42:34.469Z] INFO: Storing attachment 'Report_2023-09-14_08-00.pdf' to '' ...
3:42:34 PM Error [2023-09-14T05:42:34.472Z] ERROR: Action attachment.store caused an error: {}
3:42:34 PM Info [2023-09-14T05:42:34.473Z] INFO: Action result: {"ok":false,"error":{}}
3:42:35 PM Error
Error: Error "Error: Invalid location format: " during execution of action attachment.store using args {"location":"${id:1j9sF-Q7J5VqMAzts25NcH-3yZGV0TKyD}/${attachment.name}","conflictStrategy":"keep"}!
handleActionResult @ GmailProcessorLib.gs:3164
(anonymous) @ GmailProcessorLib.gs:3185
(anonymous) @ GmailProcessorLib.gs:3174
executeActions @ GmailProcessorLib.gs:3170
processEntity @ GmailProcessorLib.gs:3088
processConfigs @ GmailProcessorLib.gs:3073
processEntity @ GmailProcessorLib.gs:3555
processConfigs @ GmailProcessorLib.gs:3531

@John-Balla-Omnium
Copy link
Author

Also, the latest update fixed my issue with the match query (things like is:unread now work), and the config conversion also works now.

@ahochsteger
Copy link
Owner

@John-Balla-Omnium thanks for your analysis, so far.
May there be a problem with the permissions for the shared folder?
Is the owner of the shared folder another user as the one running Gmail Processor?

@John-Balla-Omnium
Copy link
Author

John-Balla-Omnium commented Sep 14, 2023

I've tested both a shared folder id which is owned by another user and a My Drive folder id, but it was working on v1 up until the v2 release. Also I've checked permissions haven't changed but I can't rule out some unknown change yet. I'll try testing on a separate account later and let you know if it works.

@John-Balla-Omnium
Copy link
Author

Tested over the weekend, it had nothing to do with the permissions, turns out that the template literal format of the id parameter was unnecessary / bugged. Here's the version of the location arg that finally worked:
location: "{id:1j9sF-Q7J5VqMAzts25NcH-3yZGV0TKyD}/Reports-${message.date:format:yyyy-MM-dd}/${attachment.name}",
vs the version that is suggested in the docs:
location: "${id:1j9sF-Q7J5VqMAzts25NcH-3yZGV0TKyD}/Reports-${message.date:format:yyyy-MM-dd}/${attachment.name}",

@ahochsteger ahochsteger changed the title Shared GDrive parent folder in location argument being ignored Shared GDrive parent folder in location argument being ignored when automatically converted from v1 Sep 18, 2023
@ahochsteger
Copy link
Owner

@John-Balla-Omnium thanks four finding the root-cause, indeed there was a bug in the converter for v1 that caused to put a $ before {id:... which is fixed now and will be available in a new release 2.1.2 (GAS version 11) in a few minutes.

github-actions bot pushed a commit that referenced this issue Sep 18, 2023
## [2.1.2](2.1.1...2.1.2) (2023-09-18)

### Bug Fixes

* wrong conversion of location with folder IDs ([0993562](0993562)), closes [#111](#111)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants