Skip to content

Commit

Permalink
Merge pull request #911 from amvanbaren/simplify-publisher-agreement
Browse files Browse the repository at this point in the history
Simplify publisher agreement
  • Loading branch information
amvanbaren committed May 14, 2024
2 parents 0b4ec92 + 145befd commit 4a4193d
Show file tree
Hide file tree
Showing 12 changed files with 164 additions and 424 deletions.
10 changes: 9 additions & 1 deletion server/src/main/java/org/eclipse/openvsx/UserAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
import org.eclipse.openvsx.util.ErrorResultException;
import org.eclipse.openvsx.util.NotFoundException;
import org.eclipse.openvsx.util.UrlUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.CacheControl;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
Expand All @@ -44,6 +46,8 @@ public class UserAPI {

private final static int TOKEN_DESCRIPTION_SIZE = 255;

protected final Logger logger = LoggerFactory.getLogger(UserAPI.class);

private final RepositoryService repositories;
private final UserService users;
private final EclipseService eclipse;
Expand Down Expand Up @@ -108,7 +112,11 @@ public UserJson getUserData() {
json.role = user.getRole();
json.tokensUrl = createApiUrl(serverUrl, "user", "tokens");
json.createTokenUrl = createApiUrl(serverUrl, "user", "token", "create");
eclipse.enrichUserJson(json, user);
try {
eclipse.enrichUserJson(json, user);
} catch (ErrorResultException e) {
logger.error("Failed to enrich UserJson", e);
}
return json;
}

Expand Down
11 changes: 7 additions & 4 deletions server/src/main/java/org/eclipse/openvsx/admin/AdminService.java
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,12 @@ public UserPublishInfoJson getUserPublishInfo(String provider, String loginName)

var userPublishInfo = new UserPublishInfoJson();
userPublishInfo.user = user.toUserJson();
eclipse.enrichUserJson(userPublishInfo.user, user);
try {
eclipse.enrichUserJson(userPublishInfo.user, user);
} catch (ErrorResultException e) {
userPublishInfo.user.error = e.getMessage();
}

userPublishInfo.activeAccessTokenNum = (int) repositories.countActiveAccessTokens(user);
var extVersions = repositories.findLatestVersions(user);
var types = new String[]{DOWNLOAD, MANIFEST, ICON, README, LICENSE, CHANGELOG, VSIXMANIFEST};
Expand Down Expand Up @@ -296,9 +301,7 @@ public ResultJson revokePublisherContributions(String provider, String loginName
}

// Send a DELETE request to the Eclipse publisher agreement API
if (eclipse.isActive() && user.getEclipseData() != null
&& user.getEclipseData().publisherAgreement != null
&& user.getEclipseData().publisherAgreement.isActive) {
if (eclipse.isActive() && user.getEclipsePersonId() != null) {
eclipse.revokePublisherAgreement(user, admin);
}

Expand Down
251 changes: 60 additions & 191 deletions server/src/main/java/org/eclipse/openvsx/eclipse/EclipseService.java

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/********************************************************************************
* Copyright (c) 2020 TypeFox and others
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* SPDX-License-Identifier: EPL-2.0
********************************************************************************/
package org.eclipse.openvsx.eclipse;

import java.time.LocalDateTime;
import java.util.Objects;

public class PublisherAgreement {

public boolean isActive;

public String documentId;

/** Version of the last signed publisher agreement. */
public String version;

/** Timestamp of the last signed publisher agreement. */
public LocalDateTime timestamp;

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
PublisherAgreement that = (PublisherAgreement) o;
return isActive == that.isActive
&& Objects.equals(documentId, that.documentId)
&& Objects.equals(version, that.version)
&& Objects.equals(timestamp, that.timestamp);
}

@Override
public int hashCode() {
return Objects.hash(isActive, documentId, version, timestamp);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,13 @@
********************************************************************************/
package org.eclipse.openvsx.eclipse;

import java.time.LocalDateTime;
import java.util.function.Function;

import com.fasterxml.jackson.annotation.JsonProperty;

import org.eclipse.openvsx.entities.EclipseData;

/**
* https://eclipsefdn.github.io/openvsx-publisher-agreement-specs/#/paths/~1publisher_agreement/post
*/
public class PublisherAgreementResponse {

public EclipseData.PublisherAgreement createEntityData(Function<String, LocalDateTime> parseDate) {
var pub = new EclipseData.PublisherAgreement();
pub.isActive = true;
pub.documentId = documentID;
pub.version = version;
pub.timestamp = parseDate.apply(effectiveDate);
return pub;
}

/** Unique identifier for an addressable object in the API. */
@JsonProperty("PersonID")
String personID;
Expand All @@ -50,17 +36,10 @@ public EclipseData.PublisherAgreement createEntityData(Function<String, LocalDat
@JsonProperty("ReceivedDate")
String receivedDate;

/** Date string in the RFC 3339 format. */
@JsonProperty("ExpirationDate")
String expirationDate;

/** The signed document as a blob entity. */
@JsonProperty("ScannedDocumentBLOB")
String scannedDocumentBLOB;

@JsonProperty("ScannedDocumentBytes")
String scannedDocumentBytes;

/** The MIME type for the posted document blob. */
@JsonProperty("ScannedDocumentMime")
String scannedDocumentMime;
Expand All @@ -72,5 +51,4 @@ public EclipseData.PublisherAgreement createEntityData(Function<String, LocalDat
/** Comment about the document being posted. */
@JsonProperty("Comments")
String comments;

}
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,14 @@
package org.eclipse.openvsx.eclipse;

import jakarta.persistence.EntityManager;
import org.apache.commons.lang3.StringUtils;
import org.eclipse.openvsx.ExtensionService;
import org.eclipse.openvsx.entities.Extension;
import org.eclipse.openvsx.entities.PersonalAccessToken;
import org.eclipse.openvsx.entities.UserData;
import org.eclipse.openvsx.json.UserJson;
import org.eclipse.openvsx.repositories.RepositoryService;
import org.eclipse.openvsx.util.ErrorResultException;
import org.eclipse.openvsx.util.NamingUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -78,20 +81,19 @@ private boolean isCompliant(UserData user) {
if (user.getProvider() == null) {
return true;
}
var eclipseData = user.getEclipseData();
if (eclipseData == null || eclipseData.personId == null) {
if (user.getEclipsePersonId() == null) {
// The user has never logged in with Eclipse
return false;
}
if (eclipseData.publisherAgreement == null || !eclipseData.publisherAgreement.isActive) {
// We don't have any active PA in our DB, let's check their Eclipse profile
var profile = eclipseService.getPublicProfile(eclipseData.personId);
if (profile.publisherAgreements == null || profile.publisherAgreements.openVsx == null
|| profile.publisherAgreements.openVsx.version == null) {
return false;
}

var json = new UserJson();
try {
eclipseService.enrichUserJson(json, user);
return !json.publisherAgreement.status.equals("none");
} catch(ErrorResultException e) {
// no way to determine whether the user has a publisher agreement
return true;
}
return true;
}

private void deactivateExtensions(Streamable<PersonalAccessToken> accessTokens) {
Expand Down
79 changes: 0 additions & 79 deletions server/src/main/java/org/eclipse/openvsx/entities/EclipseData.java

This file was deleted.

This file was deleted.

16 changes: 7 additions & 9 deletions server/src/main/java/org/eclipse/openvsx/entities/UserData.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,7 @@ public class UserData implements Serializable {
@OneToMany(mappedBy = "user")
List<NamespaceMembership> memberships;

@Column(length = 4096)
@Convert(converter = EclipseDataConverter.class)
EclipseData eclipseData;
String eclipsePersonId;

@Column(length = 4096)
@Convert(converter = AuthTokenConverter.class)
Expand Down Expand Up @@ -150,12 +148,12 @@ public void setProviderUrl(String providerUrl) {
this.providerUrl = providerUrl;
}

public EclipseData getEclipseData() {
return eclipseData;
public String getEclipsePersonId() {
return eclipsePersonId;
}

public void setEclipseData(EclipseData eclipseData) {
this.eclipseData = eclipseData;
public void setEclipsePersonId(String eclipsePersonId) {
this.eclipsePersonId = eclipsePersonId;
}

public AuthToken getGithubToken() {
Expand Down Expand Up @@ -190,7 +188,7 @@ public boolean equals(Object o) {
&& Objects.equals(providerUrl, userData.providerUrl)
&& Objects.equals(tokens, userData.tokens)
&& Objects.equals(memberships, userData.memberships)
&& Objects.equals(eclipseData, userData.eclipseData)
&& Objects.equals(eclipsePersonId, userData.eclipsePersonId)
&& Objects.equals(githubToken, userData.githubToken)
&& Objects.equals(eclipseToken, userData.eclipseToken);
}
Expand All @@ -199,7 +197,7 @@ public boolean equals(Object o) {
public int hashCode() {
return Objects.hash(
id, role, loginName, fullName, email, avatarUrl, provider, authId, providerUrl, tokens, memberships,
eclipseData, githubToken, eclipseToken
eclipsePersonId, githubToken, eclipseToken
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -146,10 +146,8 @@ private IdPrincipal loadEclipseUser(OAuth2UserRequest userRequest) {
+ ") does not match your GitHub authentication ("
+ userData.getLoginName() + ").",
ECLIPSE_MISMATCH_GITHUB_ID);

eclipse.updateUserData(userData, profile);
if (profile.publisherAgreements == null) {
eclipse.getPublisherAgreement(userData, accessToken);
}
return principal;
} catch (ErrorResultException exc) {
throw new AuthenticationServiceException(exc.getMessage(), exc);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
ALTER TABLE user_data ADD COLUMN eclipse_person_id CHARACTER VARYING(255);
UPDATE user_data SET eclipse_person_id = eclipse_data::json->'personId';
ALTER TABLE user_data DROP COLUMN eclipse_data;

0 comments on commit 4a4193d

Please sign in to comment.