Giter Site home page Giter Site logo

Recursive ownership change? about gam HOT 24 CLOSED

gam-team avatar gam-team commented on May 13, 2024
Recursive ownership change?

from gam.

Comments (24)

Servovicis avatar Servovicis commented on May 13, 2024

I tried something like this a few months ago to no avail. Ended up writing a C++ program instead to generate the gam commands run them and process the output.

basically created a list of folders to process and added to that list when processing a folder to do a isparent query.
went something along the lines of
command = m_GamLocation + "gam all users show filelist query "('" + m_FolderList[count] + "' in parents";

I would love to see other approaches, as I'm sure many are much, much better than mine.

from gam.

njcheng avatar njcheng commented on May 13, 2024

Thanks for the suggestion - how did you get the children of the folder? I'm assuming you then had to handle the auth and everything yourself in C++? That's what I was trying to avoid.

from gam.

Servovicis avatar Servovicis commented on May 13, 2024

I used the gam command above to get a list of all files and folders that had the parent of the folder in question. Basically it comes down to gam all users show filelist query " folderID " in parents
Take the id's from this list, add the folders to your processing list and go again. All the C++ script handles is generating the Gam command, having gam run it, and processing gam's output while keeping a list of folders that still need to be processed.

from gam.

brianyoungblood avatar brianyoungblood commented on May 13, 2024

came across this thread and have a need to alter the owner and permissions of subfolders and files recursively. is this approach discussed here still the best approach. Google permissions, owners of subfolders and files being mixed between several people is confusing for me and our users. ie when something is deleted or comes up missing especially, so I'm hoping to broadly change permissions to prevent this from happening.

from gam.

roynasser avatar roynasser commented on May 13, 2024

I'd also like to find a solution, even if a script, that can query for the latest additions and apply appropriate permissions for example...

One thing that ticks me is that despite preserving sharing options most of the time on sub-items (folders/files), GDrive wont preserve the "writerscantshare" attribute...

If anyone has a shell or python or perl or whatever script they are willing to share, or at least something similar I can adapt I'd love to see it... Unfortunately I am not experienced at all with c++ so the time it would take me to just get into it isnt too worth it right now... :)

If anyone has something similar though, I'd like to see it/improve on it... The alternative would be Powertools for drive, but its so buggy and their support is so sluggish I really cant see myself being happy with it.... (I like the functionality, but its just laden with bugs...)

from gam.

Servovicis avatar Servovicis commented on May 13, 2024

I'd post my old code, but I don't have access to it anymore. I'd be interested is seeing others attempts on this, but right now the best approach I have is creating 2 lists, adding the root folder to the first list, and running a search on all files querying isParent on the files for members of the 1st list that have yet to be checked, adding new folders to the 1st list, and files to the second. Once no unchecked folders exist in the first list, make changes to all entries in both lists as needed. As I'm sure you can imagine, this is a very time consuming process.

from gam.

Servovicis avatar Servovicis commented on May 13, 2024

It could be sped up by taking the ID's of isParent of all files in Drive in the first pass, then processing that data to make a folder tree to get your relevant IDs to process. Again though, a timely process, but not likely to find one faster.

from gam.

roynasser avatar roynasser commented on May 13, 2024

One option I thought of is using (not sure if its easy or available - I dont see it in the GAM documentation), a vault search / drive audit to find out changed/added items?

An initial pass through everything would be required/advisable though... And another option in addition to any strategy is to read the current "state" and not re-issue changes on files/folders that already have the required perms...

from gam.

Servovicis avatar Servovicis commented on May 13, 2024

Not sure Vault is accessible via API's for anything other then licencing.

Current permissions is expensive on time, If time isn't a factor and you want to modify files as little as possible, do it. If time is a factor and modifying files each run doesn't matter, then it takes about as much time to change the permissions on every file as it does to get those permissions in the first place. From there, Time can be saved by keeping a record of the last time you made changes to the file, and if no changes need to be made, just checking the last time it was modified. If it wasn't modified since the last time the program worked with it, then leave it alone.

from gam.

roynasser avatar roynasser commented on May 13, 2024

Gotcha... thanks for that... if anyone knows any script which does something similar I'd like to be pointed in the direction so I can modify it for this case... ;)

from gam.

Servovicis avatar Servovicis commented on May 13, 2024

This GAM fork might cover your needs.
https://github.com/lerklompen/GAM/releases

from gam.

roynasser avatar roynasser commented on May 13, 2024

I understand from #217 that this will probably be merged in?

I wonder if it would be possible to add a permission change to claim... or at least a writerscantshare option... Claim isnt all that useful from a permission standpoint if you cant limit sharing imo...

But then again, its just me talking while I should be coding :p LOL

PS: I did some tests trying to list files with the filelist GAM command, and then using that CSV to issue a writerscantshare, problem is it doesnt allow me to search within a specific folder only... Still looking for a way to get that without haing to do too much recursion... I was hoping for a drive search, or a field with the entire path, which seems to not exist :(

from gam.

roynasser avatar roynasser commented on May 13, 2024

If someone else is also interested in this, one thing that I am putting together is a command that lists all files modified after a certain date, and applies the writerscantshare attribute...

Its really quite simple as I'm just listing all files that belong to a certain user, and has a modified date > a certain time, and its running the gam command to update the permissions... One thing that I'm looking for is a way of filtering the filelist method... Drive API doesnt recognize a search parameters for writerscantshare (or the equivalent field name), so I cant use that in the query... But the CSV does output the column, so I'm thinking maybe there is an CLI csv filterer that would filter based on a column value.... that way I can constantly list the files and only run the GAM update to the ones that have the incorrect flag.

If anyone has come across such a thing i'd like to have a pointer... all I found were libs for other lanugages, etc... nothing CLI...

For now I think I'll use a combination of claim with this in order to claim all files/subfolders every X hours, and then apply the writerscantshare update on all files that are modified within the last X hours... Not fool proof, but it will work for now...

Another thing which could be useful is a way of getting/choosing the drive file name when exporting a CSV from GAM with the "todrive" option... That way I can use something to get that file, filter it, and then send that file as a CSV for GAM to use as input...

Currently its looking something like this:

./gam.py all users show filelist query "modifiedDate > '`date -v -1d '+%m-%d-%yT%H:%M:00'`' and trashed = false and '[email protected]' in owners" originalfilename id | ./gam.py csv - gam user [email protected] update drivefile id ~id writerscantshare

This will apply a writerscantshare on all files owned by MAINDADMIN on all drives (maybe this isnt necessary? maybe I can only scan mainadmin as a user instead of all...will try it out) and applies only to files modified in the last 24hs... (you could add -xx:xx to get to the correct timezone but if its running once a day it should be ok)

from gam.

roynasser avatar roynasser commented on May 13, 2024

PS: just realized modifiedDate is only working with <... > or >= give a 400 invalid query....

more debugging to do :/

from gam.

brianyoungblood avatar brianyoungblood commented on May 13, 2024

Great CLI tool called csvkit you might see useful.https://github.com/wireservice/csvkit

from gam.

lerklompen avatar lerklompen commented on May 13, 2024

If you already use the "claim" command you find all the manipulated fileID's in the output - you could direct the output to a file and parse the ID's to a new list for further processing!

I could absolutely add functionality to the "claim" command. Just so that I'm clear on what you are asking for: you would like to be able to limit sharing of "claimed" files: "Prevent editors from changing access and adding new people"? This must be set per file (not possible on "folder level" as I understand). As of now the previous "owner" simply becomes "editor".

Just to point out - I used the "recursive" functions found in the "show filetree" command. I'm also thinking of expanding the functionality of this command to be able to output a csv of a certain folder (based on the folderID) including subfolders, plus a somewhat clearer output (regarding file/folder structure). Ross Scrogs already has made some improvements to the command in his "future" versions of GAM (using more API calls, which I would like to avoid...).

I don't know if my commands will be merged - they might need some refining before that is a possibility. But at least I made a "pull request", then I will have to see what they think of it. Our organisation is already using the functionality to transfer files on a daily basis from certain shared folders.

/Mattias

from gam.

roynasser avatar roynasser commented on May 13, 2024

Thanks for the pointer @brianyoungblood

And thanks for the input @lerklompen ... Yes, my "idea" would be that claim has an option "writerscantshare" just like the GAM update method has... Yes, basically it will set "Prevent editors from changing access and adding new people", making it so that only the owner/admin can share files. The permissions initially inherit from the father, as per my tests, however this particular setting doesnt inherit... Doesnt make much sense IMO but google drive "sharing" and "corporate permissions/ACL" still butt-heads very often... so we need to always look at workarounds :(

from gam.

lerklompen avatar lerklompen commented on May 13, 2024

Now added a switch "writerscantshare" to the claim command. You can try out the source code (if you are on linux/mac, or if you prepped windows to run python commands).
https://github.com/lerklompen/GAM/tree/branch-3.63

Note that this new switch requires an extra API call per file! So it will "cost" more plus take longer time.

I will draft a new release including new windows binaries soon!

Edit - New release up:
https://github.com/lerklompen/GAM/releases

/Mattias

from gam.

roynasser avatar roynasser commented on May 13, 2024

Thia appear to be working quite well...Really awesom!!! However is it ecevuting a claim + writerscantshare on every file or only on changed/added files? Maybe it would be possible to use modified date/create date to prevent havign to do too many calls? I'm currently at about 500,000 files... :/

from gam.

roynasser avatar roynasser commented on May 13, 2024

Apparently it lists all files, but only reissues permissions for the required ones...

I'm gong to explore better a combination of claim with specific permissions (recursively if possible)... If anyone has some script already doing this it would be nice... Otherwise I'll try and whip together and post when done.

@lerklompen using your latest GAM release without issues! 👍

from gam.

pirx242 avatar pirx242 commented on May 13, 2024

Hello All!

Any news about this "claim folder" functionality?

Looks like i have "GAM 4.28.01 - https://github.com/taers232c/GAMADV-X"

And when i try "claim folder" i get this:


gam.py user <claiming.user> claim folder 0B1yXh5N...
Command: gam.py user <claiming.user> claim >>>folder<<< 0B1yXh5...

ERROR: Invalid argument: Expected
Help: Documentation is at https://github.com/jay0lee/GAM/wiki

Do i have the wrong version of GAM?

from gam.

taers232c avatar taers232c commented on May 13, 2024

from gam.

rasqual avatar rasqual commented on May 13, 2024

I'll add that Ross is doing even more work on this . . . as I type this. ;-)

from gam.

stale avatar stale commented on May 13, 2024

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.

from gam.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.