@@ -37,19 +37,50 @@ def _exists(self, name: str):
37
37
except RestAPIError :
38
38
return False
39
39
40
- def _get_projects (self ):
41
- """Get all projects accessible by the user.
40
+ def _get_owned_projects (self ):
41
+ """Get all projects owned by the current user
42
42
43
43
# Returns
44
44
`List[Project]`: List of Project objects
45
45
# Raises
46
- `hopsworks.client.exceptions.RestAPIError`: If unable to get the projects
46
+ `hopsworks.client.exceptions.RestAPIError`: If unable to get the project teams
47
+ """
48
+ project_team_json = self ._get_project_teams ()
49
+ projects = []
50
+ if project_team_json :
51
+ # This information can be retrieved calling the /users/profile endpoint but is avoided as that
52
+ # requires an API key to have the USER scope which is not guaranteed on serverless
53
+ # Until there is a better solution this code is used to get the current user_id to check project ownership
54
+ current_user_uid = project_team_json [0 ]['user' ]['uid' ]
55
+ for project_team in project_team_json :
56
+ if project_team ["project" ]["owner" ]["uid" ] == current_user_uid :
57
+ projects .append (self ._get_project (project_team ["project" ]["name" ]))
58
+ return projects
59
+
60
+
61
+ def _get_project_teams (self ):
62
+ """Get all project teams for this user.
63
+
64
+ # Returns
65
+ `str`: List of Project teams
66
+ # Raises
67
+ `hopsworks.client.exceptions.RestAPIError`: If unable to get the project teams
47
68
"""
48
69
_client = client .get_instance ()
49
70
path_params = [
50
71
"project" ,
51
72
]
52
- project_team_json = _client ._send_request ("GET" , path_params )
73
+ return _client ._send_request ("GET" , path_params )
74
+
75
+ def _get_projects (self ):
76
+ """Get all projects accessible by the user.
77
+
78
+ # Returns
79
+ `List[Project]`: List of Project objects
80
+ # Raises
81
+ `hopsworks.client.exceptions.RestAPIError`: If unable to get the projects
82
+ """
83
+ project_team_json = self ._get_project_teams ()
53
84
projects = []
54
85
for project_team in project_team_json :
55
86
projects .append (self ._get_project (project_team ["project" ]["name" ]))
0 commit comments