diff --git a/gspread/client.py b/gspread/client.py index e82e5be00..1a07bcb8a 100644 --- a/gspread/client.py +++ b/gspread/client.py @@ -330,6 +330,19 @@ def copy( if p.get("deleted"): continue + # .list_permissions() returns a list of permissions, + # even the folder permissions if the file is in a shared folder. + # We only want the permissions that are directly applied to the + # spreadsheet file, i.e. 'writer', 'commenter' and 'reader'. + perm_details = { + p_details.get("permissionType"): p_details.get("inherited") + for p_details in p.get("permissionDetails") + } + if p.get("role") in ("organizer", "fileOrganizer") and ( + perm_details.get("file") or perm_details.get("member") + ): + continue + # In case of domain type the domain extract the domain # In case of user/group extract the emailAddress # Otherwise use None for type 'Anyone' diff --git a/tox.ini b/tox.ini index 8e235edc1..33c1c1989 100644 --- a/tox.ini +++ b/tox.ini @@ -16,7 +16,7 @@ commands = pytest {posargs} tests/ extend-ignore = E203 extend-exclude = .tox,./env,./gspread/__init__.py max-line-length = 255 -max-complexity = 10 +max-complexity = 11 show-source = True statistics = True