gspread icon indicating copy to clipboard operation
gspread copied to clipboard

Add Users For Protected Ranges

Open tompbarry opened this issue 2 years ago • 2 comments

Is your feature request related to a problem? Please describe. After copying a spreadsheet using client.copy and then opening the new sheet using client.open, the protected ranges are still correctly defined as in the source spreadsheet; however, the Editors for the protected ranges have been changed to just myself.

Describe the solution you'd like I would like to be able to add the other users that had edit rights to protected ranges on the new sheet.

Describe alternatives you've considered I've considered deleting and redefining the protected ranges so more than one editor can be added; but that seems like it's not needed.

The com.google.api.services.sheets.v4.model contains a Class Editors that appears to allow additions/removal of editors for protected ranges as shown at https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets/sheets#Editors

Google Apps Script also contains an addEditor https://developers.google.com/apps-script/reference/spreadsheet/protection?hl=en#addeditorsemailaddresses function for protected ranges.

Additional context

tompbarry avatar Jun 29 '22 16:06 tompbarry

Hi thank you for raising this issue.

I checked and I confirmed the protected ranges are not copied over to the new spreadsheet.

I can work that out and add a new option to the copy method and offers to copy the protected ranges. This will be costly though. Much like the other (already existent) options, we need to list all protected ranges then created them by batch (if the API allows it by batch, otherwise it will be one by one).

I am adding this feature to the next release.

lavigne958 avatar Jul 16 '22 18:07 lavigne958

Hi @tompbarry I had a look at this issue, I have a draft code that does the job but the API has some issues. When sending the request to create the new protected ranges it fails, every time I try to copy the original protected range to the new sheet, the new sheets ends up with 2 protected ranges, one that has an issue and we can't delete it/edit it, the other one that is only read-only.

I am removing this issue from the next milestone as I have no idea how to counter that problem for now. I will keep track of that and keep testing.

lavigne958 avatar Aug 10 '22 15:08 lavigne958