@@ -2110,12 +2110,83 @@ def get_all_projects(self, included_archived=None, expand=None):
21102110 return self .projects (included_archived , expand )
21112111
21122112 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.
21142135 If no user is logged in, it returns the list of projects that are visible when using anonymous access.
21152136 :param included_archived: boolean whether to include archived projects in response, default: false
21162137 :param expand:
21172138 :return:
21182139 """
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+
21192190 params = {}
21202191 if included_archived :
21212192 params ["includeArchived" ] = included_archived
@@ -2180,7 +2251,7 @@ def archive_project(self, key):
21802251 """
21812252 base_url = self .resource_url ("project" )
21822253 url = "{base_url}/{key}/archive" .format (base_url = base_url , key = key )
2183- return self .put (url )
2254+ return self .post (url )
21842255
21852256 def project (self , key , expand = None ):
21862257 """
0 commit comments