Skip to content

Commit e192a2f

Browse files
committed
Merge PR burnash#1515: Fixed APIError: [403] when copying permissions
This PR addresses issue burnash#1507 which caused a 403 error when copying permissions from a spreadsheet located in a shared drive. Key changes: - Filters out folder-level permissions (organizer/fileOrganizer roles) - Only copies permissions directly applied to spreadsheet files (writer, commenter, reader) - Enhanced typing annotations to resolve mypy complaints - All 141 unit tests pass successfully Status: Safe to merge - narrowly scoped bug fix, well tested
2 parents 8bc3374 + 8cfc93b commit e192a2f

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

gspread/client.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,19 @@ def copy(
330330
if p.get("deleted"):
331331
continue
332332

333+
# .list_permissions() returns a list of permissions,
334+
# even the folder permissions if the file is in a shared folder.
335+
# We only want the permissions that are directly applied to the
336+
# spreadsheet file, i.e. 'writer', 'commenter' and 'reader'.
337+
perm_details = {
338+
p_details.get("permissionType"): p_details.get("inherited")
339+
for p_details in p.get("permissionDetails")
340+
}
341+
if p.get("role") in ("organizer", "fileOrganizer") and (
342+
perm_details.get("file") or perm_details.get("member")
343+
):
344+
continue
345+
333346
# In case of domain type the domain extract the domain
334347
# In case of user/group extract the emailAddress
335348
# Otherwise use None for type 'Anyone'

tox.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ commands = pytest {posargs} tests/
1616
extend-ignore = E203
1717
extend-exclude = .tox,./env,./gspread/__init__.py,./.venv*
1818
max-line-length = 255
19-
max-complexity = 10
19+
max-complexity = 11
2020
show-source = True
2121
statistics = True
2222

0 commit comments

Comments
 (0)