@@ -2110,12 +2110,83 @@ def get_all_projects(self, included_archived=None, expand=None):
2110
2110
return self .projects (included_archived , expand )
2111
2111
2112
2112
def projects (self , included_archived = None , expand = None ):
2113
- """Returns all projects which are visible for the currently logged-in user.
2113
+ """
2114
+ Returns all projects which are visible for the currently logged-in user.
2115
+ If no user is logged in, it returns the list of projects that are visible when using anonymous access.
2116
+ :param included_archived: boolean whether to include archived projects in response, default: false
2117
+ :param expand:
2118
+ :return:
2119
+ """
2120
+ if self .cloud :
2121
+ return self .projects_from_cloud (
2122
+ included_archived = included_archived ,
2123
+ expand = expand ,
2124
+ )
2125
+ else :
2126
+ return self .projects_from_server (
2127
+ included_archived = included_archived ,
2128
+ expand = expand ,
2129
+ )
2130
+
2131
+ def projects_from_cloud (self , included_archived = None , expand = None ):
2132
+ """
2133
+ Returns all projects which are visible for the currently logged-in user.
2134
+ Cloud version should use the ``paginated``endpoint to get pages of projects, as the old endpoint is deprecated.
2114
2135
If no user is logged in, it returns the list of projects that are visible when using anonymous access.
2115
2136
:param included_archived: boolean whether to include archived projects in response, default: false
2116
2137
:param expand:
2117
2138
:return:
2118
2139
"""
2140
+ if not self .cloud :
2141
+ raise ValueError ("``projects_from_cloud`` method is only available for Jira Cloud platform" )
2142
+
2143
+ projects = self .paginated_projects (
2144
+ included_archived = included_archived ,
2145
+ expand = expand ,
2146
+ )
2147
+ while not projects .get ("isLast" ):
2148
+ projects ["values" ].extend (
2149
+ self .paginated_projects (
2150
+ included_archived = included_archived ,
2151
+ expand = expand ,
2152
+ url = projects ["nextPage" ],
2153
+ )["values" ]
2154
+ )
2155
+ return projects ["values" ]
2156
+
2157
+ def paginated_projects (self , included_archived = None , expand = None , url = None ):
2158
+ """
2159
+ Returns a page of projects which are visible for the currently logged-in user.
2160
+ Method to be used only for Jira Cloud platform, until tests on Jira Server are executed.
2161
+ If no user is logged in, it returns the list of projects that are visible when using anonymous access.
2162
+ :param included_archived: boolean whether to include archived projects in response, default: false
2163
+ :param expand:
2164
+ :param url: url to get the next page of projects, default: false (first page)
2165
+ :return:
2166
+ """
2167
+ if not self .cloud :
2168
+ raise ValueError ("``projects_from_cloud`` method is only available for Jira Cloud platform" )
2169
+
2170
+ params = {}
2171
+ if included_archived :
2172
+ params ["includeArchived" ] = included_archived
2173
+ if expand :
2174
+ params ["expand" ] = expand
2175
+ page_url = url or self .resource_url ("project/search" )
2176
+ is_url_absolute = bool (page_url .lower ().startswith ("http" ))
2177
+ return self .get (page_url , params = params , absolute = is_url_absolute )
2178
+
2179
+ def projects_from_server (self , included_archived = None , expand = None ):
2180
+ """
2181
+ Returns all projects which are visible for the currently logged-in user.
2182
+ If no user is logged in, it returns the list of projects that are visible when using anonymous access.
2183
+ :param included_archived: boolean whether to include archived projects in response, default: false
2184
+ :param expand:
2185
+ :return:
2186
+ """
2187
+ if self .cloud :
2188
+ raise ValueError ("``projects_from_server`` method is only available for Jira Server platform" )
2189
+
2119
2190
params = {}
2120
2191
if included_archived :
2121
2192
params ["includeArchived" ] = included_archived
@@ -2180,7 +2251,7 @@ def archive_project(self, key):
2180
2251
"""
2181
2252
base_url = self .resource_url ("project" )
2182
2253
url = "{base_url}/{key}/archive" .format (base_url = base_url , key = key )
2183
- return self .put (url )
2254
+ return self .post (url )
2184
2255
2185
2256
def project (self , key , expand = None ):
2186
2257
"""
0 commit comments