@@ -114,18 +114,47 @@ public void checkPublisherAgreement(UserData user) {
114114 if (personId == null ) {
115115 throw new ErrorResultException ("You must log in with an Eclipse Foundation account and sign a Publisher Agreement before publishing any extension." );
116116 }
117- var agreement = getPublisherAgreement (user );
118- if (agreement == null || agreement .version == null ) {
117+ var profile = getPublicProfile (personId );
118+ if (profile .publisherAgreements == null || profile .publisherAgreements .openVsx == null
119+ || profile .publisherAgreements .openVsx .version == null ) {
119120 throw new ErrorResultException ("You must sign a Publisher Agreement with the Eclipse Foundation before publishing any extension." );
120121 }
121- if (!publisherAgreementVersion .equals (agreement .version )) {
122+ if (!publisherAgreementVersion .equals (profile . publisherAgreements . openVsx .version )) {
122123 throw new ErrorResultException ("Your Publisher Agreement with the Eclipse Foundation is outdated (version "
123- + agreement .version + "). The current version is "
124+ + profile . publisherAgreements . openVsx .version + "). The current version is "
124125 + publisherAgreementVersion + "." );
125126 }
126127 });
127128 }
128129
130+ /**
131+ * Get the publicly available user profile.
132+ */
133+ public EclipseProfile getPublicProfile (String personId ) {
134+ checkApiUrl ();
135+ var urlTemplate = eclipseApiUrl + "account/profile/{personId}" ;
136+ var uriVariables = Map .of ("personId" , personId );
137+ var headers = new HttpHeaders ();
138+ headers .setAccept (Arrays .asList (MediaType .APPLICATION_JSON ));
139+ var request = new HttpEntity <Void >(headers );
140+
141+ try {
142+ var response = restTemplate .exchange (urlTemplate , HttpMethod .GET , request , String .class , uriVariables );
143+ return parseEclipseProfile (response );
144+ } catch (RestClientException exc ) {
145+ if (exc instanceof HttpStatusCodeException ) {
146+ var status = ((HttpStatusCodeException ) exc ).getStatusCode ();
147+ if (status == HttpStatus .NOT_FOUND )
148+ throw new ErrorResultException ("No Eclipse profile data available for user: " + personId );
149+ }
150+
151+ var url = UriComponentsBuilder .fromUriString (urlTemplate ).build (uriVariables );
152+ logger .error ("Get request failed with URL: " + url , exc );
153+ throw new ErrorResultException ("Request for retrieving user profile failed: " + exc .getMessage (),
154+ HttpStatus .INTERNAL_SERVER_ERROR );
155+ }
156+ }
157+
129158 /**
130159 * Update the given user data with a profile obtained from Eclipse API.
131160 */
@@ -151,7 +180,6 @@ public void enrichUserJson(UserJson json, UserData user) {
151180 }
152181
153182 var usableToken = true ;
154- ErrorResultException exception = null ;
155183 try {
156184 // Add information on the publisher agreement
157185 var agreement = getPublisherAgreement (user );
@@ -167,7 +195,7 @@ else if (publisherAgreementVersion.equals(agreement.version))
167195 if (e .getStatus () == HttpStatus .FORBIDDEN ) {
168196 usableToken = false ;
169197 } else {
170- exception = e ;
198+ logger . info ( "Failed to enrich UserJson" , e ) ;
171199 }
172200 }
173201
@@ -182,10 +210,30 @@ else if (publisherAgreementVersion.equals(agreement.version))
182210 else
183211 json .additionalLogins .add (eclipseLogin );
184212 }
213+ }
214+
215+ public void adminEnrichUserJson (UserJson json , UserData user ) {
216+ if (!isActive ()) {
217+ return ;
218+ }
219+
220+ json .publisherAgreement = new UserJson .PublisherAgreement ();
221+ var personId = user .getEclipsePersonId ();
222+ if (personId == null ) {
223+ json .publisherAgreement .status = "none" ;
224+ return ;
225+ }
185226
186- // Throw exception at end of method, so that JSON data is fully enriched
187- if (exception != null ) {
188- throw exception ;
227+ try {
228+ var profile = getPublicProfile (personId );
229+ if (profile .publisherAgreements == null || profile .publisherAgreements .openVsx == null || StringUtils .isEmpty (profile .publisherAgreements .openVsx .version ))
230+ json .publisherAgreement .status = "none" ;
231+ else if (publisherAgreementVersion .equals (profile .publisherAgreements .openVsx .version ))
232+ json .publisherAgreement .status = "signed" ;
233+ else
234+ json .publisherAgreement .status = "outdated" ;
235+ } catch (ErrorResultException e ) {
236+ logger .error ("Failed to get public profile" , e );
189237 }
190238 }
191239
0 commit comments