@@ -114,18 +114,47 @@ public void checkPublisherAgreement(UserData user) {
114
114
if (personId == null ) {
115
115
throw new ErrorResultException ("You must log in with an Eclipse Foundation account and sign a Publisher Agreement before publishing any extension." );
116
116
}
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 ) {
119
120
throw new ErrorResultException ("You must sign a Publisher Agreement with the Eclipse Foundation before publishing any extension." );
120
121
}
121
- if (!publisherAgreementVersion .equals (agreement .version )) {
122
+ if (!publisherAgreementVersion .equals (profile . publisherAgreements . openVsx .version )) {
122
123
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 "
124
125
+ publisherAgreementVersion + "." );
125
126
}
126
127
});
127
128
}
128
129
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
+
129
158
/**
130
159
* Update the given user data with a profile obtained from Eclipse API.
131
160
*/
@@ -151,7 +180,6 @@ public void enrichUserJson(UserJson json, UserData user) {
151
180
}
152
181
153
182
var usableToken = true ;
154
- ErrorResultException exception = null ;
155
183
try {
156
184
// Add information on the publisher agreement
157
185
var agreement = getPublisherAgreement (user );
@@ -167,7 +195,7 @@ else if (publisherAgreementVersion.equals(agreement.version))
167
195
if (e .getStatus () == HttpStatus .FORBIDDEN ) {
168
196
usableToken = false ;
169
197
} else {
170
- exception = e ;
198
+ logger . info ( "Failed to enrich UserJson" , e ) ;
171
199
}
172
200
}
173
201
@@ -182,10 +210,30 @@ else if (publisherAgreementVersion.equals(agreement.version))
182
210
else
183
211
json .additionalLogins .add (eclipseLogin );
184
212
}
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
+ }
185
226
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 );
189
237
}
190
238
}
191
239
0 commit comments