From bd08c1b0d137a548f1e3657f5b567343a6090c8f Mon Sep 17 00:00:00 2001 From: w7089 Date: Wed, 31 May 2023 23:00:35 +0300 Subject: [PATCH 1/2] fix(cli): add _from_parent_attrs to user-project manager (#2558) --- gitlab/v4/cli.py | 2 +- gitlab/v4/objects/users.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/gitlab/v4/cli.py b/gitlab/v4/cli.py index 128bd5bd0..4bfa5ea93 100644 --- a/gitlab/v4/cli.py +++ b/gitlab/v4/cli.py @@ -46,7 +46,7 @@ def __init__( self.mgr_cls._path = self.mgr_cls._path.format(**self.parent_args) self.mgr = self.mgr_cls(gl) - + self.mgr._from_parent_attrs = self.parent_args if self.mgr_cls._types: for attr_name, type_cls in self.mgr_cls._types.items(): if attr_name in self.args.keys(): diff --git a/gitlab/v4/objects/users.py b/gitlab/v4/objects/users.py index e2f10574e..fe93e4a68 100644 --- a/gitlab/v4/objects/users.py +++ b/gitlab/v4/objects/users.py @@ -666,7 +666,7 @@ def list(self, **kwargs: Any) -> Union[RESTObjectList, List[RESTObject]]: if self._parent: path = f"/users/{self._parent.id}/projects" else: - path = f"/users/{kwargs['user_id']}/projects" + path = f"/users/{self._from_parent_attrs['user_id']}/projects" return ListMixin.list(self, path=path, **kwargs) From 326b07de548f3db10b2ba448e255e25cccd9fe3f Mon Sep 17 00:00:00 2001 From: Nejc Habjan Date: Thu, 12 Oct 2023 14:13:38 +0200 Subject: [PATCH 2/2] test(cli): add test for user-project list --- tests/functional/cli/test_cli_users.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tests/functional/cli/test_cli_users.py b/tests/functional/cli/test_cli_users.py index 740201336..8bf2fbcd4 100644 --- a/tests/functional/cli/test_cli_users.py +++ b/tests/functional/cli/test_cli_users.py @@ -12,3 +12,10 @@ def test_create_user_impersonation_token_with_scopes(gitlab_cli, user): ret = gitlab_cli(cmd) assert ret.success + + +def test_list_user_projects(gitlab_cli, user): + cmd = ["user-project", "list", "--user-id", user.id] + ret = gitlab_cli(cmd) + + assert ret.success