diff --git a/.config/pre-commit-config.yaml b/.config/pre-commit-config.yaml index 4da51ee..7524976 100644 --- a/.config/pre-commit-config.yaml +++ b/.config/pre-commit-config.yaml @@ -1,5 +1,5 @@ default_language_version: - python: python3.11 + python: python3.12 repos: - repo: https://github.com/pre-commit/pre-commit-hooks rev: v4.5.0 @@ -9,7 +9,7 @@ repos: exclude: test_scraper_.*\.json - id: check-ast - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.4.2 + rev: v0.4.8 hooks: # Run the linter. - id: ruff @@ -18,7 +18,7 @@ repos: - id: ruff-format args: [--config, .config/ruff.toml] - repo: https://github.com/astral-sh/uv-pre-commit - rev: 0.1.38 + rev: 0.2.9 hooks: # Run the pip compile - id: pip-compile diff --git a/requirements.txt b/requirements.txt index c1e27a6..53dd3ea 100755 --- a/requirements.txt +++ b/requirements.txt @@ -21,6 +21,7 @@ chardet==5.2.0 charset-normalizer==3.3.2 # via requests ckanapi==4.8 + # via hdx-python-api (pyproject.toml) click==8.1.7 # via typer coverage==7.5.3 @@ -28,6 +29,7 @@ coverage==7.5.3 cryptography==42.0.8 # via pyopenssl defopt==6.4.0 + # via hdx-python-api (pyproject.toml) distlib==0.3.8 # via virtualenv dnspython==2.6.1 @@ -39,22 +41,27 @@ docopt==0.6.2 docutils==0.21.2 # via defopt email-validator==2.1.1 + # via hdx-python-api (pyproject.toml) et-xmlfile==1.1.0 # via openpyxl filelock==3.14.0 # via virtualenv frictionless==5.17.0 # via hdx-python-utilities -google-auth==2.29.0 +google-auth==2.30.0 # via # google-auth-oauthlib # gspread google-auth-oauthlib==1.2.0 # via gspread gspread==6.1.2 + # via hdx-python-api (pyproject.toml) hdx-python-country==3.7.2 + # via hdx-python-api (pyproject.toml) hdx-python-utilities==3.6.9 - # via hdx-python-country + # via + # hdx-python-api (pyproject.toml) + # hdx-python-country humanize==4.9.0 # via frictionless identify==2.5.36 @@ -63,7 +70,7 @@ idna==3.7 # via # email-validator # requests -ijson==3.2.3 +ijson==3.3.0 # via hdx-python-utilities inflect==7.2.1 # via quantulum3 @@ -84,10 +91,13 @@ jsonschema==4.22.0 jsonschema-specifications==2023.12.1 # via jsonschema libhxl==5.2.1 - # via hdx-python-country + # via + # hdx-python-api (pyproject.toml) + # hdx-python-country loguru==0.7.2 # via hdx-python-utilities makefun==1.15.2 + # via hdx-python-api (pyproject.toml) markdown-it-py==3.0.0 # via rich marko==2.0.3 @@ -99,6 +109,7 @@ mdurl==0.1.2 more-itertools==10.2.0 # via inflect ndg-httpsclient==0.5.1 + # via hdx-python-api (pyproject.toml) nodeenv==1.9.1 # via pre-commit num2words==0.5.13 @@ -122,8 +133,10 @@ ply==3.11 pockets==0.9.1 # via sphinxcontrib-napoleon pre-commit==3.7.1 + # via hdx-python-api (pyproject.toml) pyasn1==0.6.0 # via + # hdx-python-api (pyproject.toml) # ndg-httpsclient # pyasn1-modules # rsa @@ -138,12 +151,17 @@ pydantic-core==2.18.4 pygments==2.18.0 # via rich pyopenssl==24.1.0 - # via ndg-httpsclient + # via + # hdx-python-api (pyproject.toml) + # ndg-httpsclient pyphonetics==0.5.3 # via hdx-python-country pytest==8.2.2 - # via pytest-cov + # via + # hdx-python-api (pyproject.toml) + # pytest-cov pytest-cov==5.0.0 + # via hdx-python-api (pyproject.toml) python-dateutil==2.8.2 # via # frictionless @@ -161,6 +179,7 @@ pyyaml==6.0.1 # pre-commit # tableschema-to-template quantulum3==0.9.1 + # via hdx-python-api (pyproject.toml) ratelimit==2.2.1 # via hdx-python-utilities referencing==0.35.1 @@ -169,6 +188,7 @@ referencing==0.35.1 # jsonschema-specifications requests==2.32.3 # via + # hdx-python-api (pyproject.toml) # ckanapi # frictionless # libhxl diff --git a/src/hdx/data/user.py b/src/hdx/data/user.py index 98c41ef..821ea93 100755 --- a/src/hdx/data/user.py +++ b/src/hdx/data/user.py @@ -289,16 +289,21 @@ def get_organizations( organizations.append(org) return organizations - def check_organization_access(self, organization: str) -> bool: + def check_organization_access( + self, organization: str, permission: str = "read" + ) -> bool: """Check user is a member of a given organization. Args: organization (str): Organization id or name. + permission (str): Permission to check for. Defaults to 'read'. Returns: bool: True if the logged in user is a member of the organization. """ - for organization_dict in self.get_organization_dicts(): + for organization_dict in self.get_organization_dicts( + permission=permission + ): if organization_dict["id"] == organization: return True if organization_dict["name"] == organization: @@ -323,7 +328,7 @@ def get_current_user_organization_dicts( user = User(configuration=configuration) try: return user.configuration.call_remoteckan( - cls.actions()["listorgs"] + cls.actions()["listorgs"], {"permission": permission} ) except Exception: return [] @@ -355,16 +360,21 @@ def get_current_user_organizations( return organizations @classmethod - def check_current_user_organization_access(cls, organization: str) -> bool: + def check_current_user_organization_access( + cls, organization: str, permission: str = "read" + ) -> bool: """Check logged in user is a member of a given organization. Args: organization (str): Organization id or name. + permission (str): Permission to check for. Defaults to 'read'. Returns: bool: True if the logged in user is a member of the organization. """ - for organization_dict in cls.get_current_user_organization_dicts(): + for organization_dict in cls.get_current_user_organization_dicts( + permission=permission + ): if organization_dict["id"] == organization: return True if organization_dict["name"] == organization: