Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closes #2540 & #2614 #2615

Merged
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,14 @@ public boolean isEmpty() {
public boolean isEmptyForDisplay() {
return isEmpty(true);
}

public boolean isGeospatial() {
return this.datasetFieldType.isGeospatial();
}

public boolean isVisibleThroughAnonymizedUrl() {
return this.datasetFieldType.isVisibleThroughAnonymizedUrl();
}

public DatasetField copy() {
return DatasetFieldUtil.copyDatasetField(this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ public class DatasetFieldType implements Serializable, Comparable<DatasetFieldTy
@Column(name="metadata", nullable = false)
@Convert(converter = JsonMapConverter.class)
private Map<String, Object> metadata = emptyMap();
private boolean visibleThroughAnonymizedUrl;

// -------------------- CONSTRUCTORS --------------------

Expand Down Expand Up @@ -281,6 +282,10 @@ public boolean isAdvancedSearchFieldType() {
return this.advancedSearchFieldType;
}

public boolean isVisibleThroughAnonymizedUrl() {
return this.visibleThroughAnonymizedUrl;
}

public List<DatasetFieldDefaultValue> getDatasetFieldDefaultValues() {
return datasetFieldDefaultValues;
}
Expand Down Expand Up @@ -413,6 +418,11 @@ public boolean isHasRequiredChildren() {
public boolean isHasParent() {
return this.parentDatasetFieldType != null;
}


public boolean isGeospatial() {
return this.fieldType == FieldType.GEOBOX;
}

@Override
public int compareTo(DatasetFieldType o) {
Expand Down Expand Up @@ -600,6 +610,10 @@ public void setAdvancedSearchFieldType(boolean advancedSearchFieldType) {
this.advancedSearchFieldType = advancedSearchFieldType;
}

public void setVisibleThroughAnonymizedUrl(final boolean visibleThroughAnonymizedUrl) {
this.visibleThroughAnonymizedUrl = visibleThroughAnonymizedUrl;
}

public void setDatasetFieldDefaultValues(List<DatasetFieldDefaultValue> datasetFieldDefaultValues) {
this.datasetFieldDefaultValues = datasetFieldDefaultValues;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ public List<DatasetField> getDatasetFields() {
public boolean isInclude() {
return include;
}

public boolean isVisibleThroughAnonymizedUrl() {
return this.datasetFieldType.isVisibleThroughAnonymizedUrl();
}

// -------------------- LOGIC --------------------

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,11 @@ public boolean isHasRequired() {
public String getIdString() {
return id.toString();
}

public boolean isVisibleThroughAnonymizedUrl() {
return this.datasetFieldTypes.stream()
.anyMatch(DatasetFieldType::isVisibleThroughAnonymizedUrl);
}

@Transient
private boolean showDatasetFieldTypes;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,4 @@ public boolean doesDvObjectClassHavePermissionForObject(Class<? extends DvObject
return false;

} // doesDvObjectClassHavePermissionForObject


}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package edu.harvard.iq.dataverse.persistence.user;


/**
* Guest user in the system. There's only one, so you get it with the static getter {@link #get()} (singleton pattern).
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,33 +1,42 @@
package edu.harvard.iq.dataverse.persistence.user;

import edu.harvard.iq.dataverse.common.BundleUtil;
import static edu.harvard.iq.dataverse.common.BundleUtil.getStringFromBundle;

import edu.harvard.iq.dataverse.persistence.DvObject;

/**
* A PrivateUrlUser is virtual in the sense that it does not have a row in the
* authenticateduser table. It exists so when a Private URL is enabled for a
* dataset, we can assign a read-only role ("member") to the identifier for the
* PrivateUrlUser. (We will make no attempt to internationalize the identifier,
* which is stored in the roleassignment table.)
* which is stored in the roleassignment table.)
*/
@SuppressWarnings("serial")
public class PrivateUrlUser implements User {

public static final String PREFIX = "#";

/**
* In the future, this could probably be dvObjectId rather than datasetId,
* if necessary. It's really just roleAssignment.getDefinitionPoint(), which
* is a DvObject.
* In the future, this could probably be dvObjectId rather than datasetId, if
* necessary. It's really just roleAssignment.getDefinitionPoint(), which is a
* DvObject.
*/
private final long datasetId;
private final boolean anonymized;

public PrivateUrlUser(long datasetId) {
public PrivateUrlUser(final long datasetId) {
this.datasetId = datasetId;
this.anonymized = false;
}

public long getDatasetId() {
return datasetId;
public PrivateUrlUser(final long datasetId, final boolean anonymized) {
this.datasetId = datasetId;
this.anonymized = anonymized;
}

public long getDatasetId() {
return this.datasetId;
}

/**
* By always returning false for isAuthenticated(), we prevent a
* name from appearing in the corner as well as preventing an account page
Expand All @@ -48,14 +57,19 @@ public boolean isSuperuser() {

@Override
public String getIdentifier() {
return PREFIX + datasetId;
return PREFIX + this.datasetId;
}
public boolean isAnonymized() {
return this.anonymized;
}

public boolean isAllowedToView(final DvObject object) {
return this.datasetId == object.getId();
}

@Override
public RoleAssigneeDisplayInfo getDisplayInfo() {
String title = BundleUtil.getStringFromBundle("dataset.privateurl.roleassigeeTitle");
return new RoleAssigneeDisplayInfo(title, null);
return new RoleAssigneeDisplayInfo(
getStringFromBundle("dataset.privateurl.roleassigeeTitle"), null);
}


}
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package edu.harvard.iq.dataverse.persistence.user;

import edu.harvard.iq.dataverse.persistence.DvObject;
import edu.harvard.iq.dataverse.persistence.JpaEntity;
import static javax.persistence.CascadeType.MERGE;
import static javax.persistence.GenerationType.IDENTITY;

import java.util.Objects;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Index;
import javax.persistence.JoinColumn;
Expand All @@ -16,7 +16,9 @@
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;
import java.util.Objects;

import edu.harvard.iq.dataverse.persistence.DvObject;
import edu.harvard.iq.dataverse.persistence.JpaEntity;

/**
* A role of a user in a Dataverse. A User may have many roles in a given Dataverse.
Expand All @@ -25,6 +27,7 @@
*
* @author michael
*/
@SuppressWarnings("serial")
@Entity
@Table(
uniqueConstraints = @UniqueConstraint(columnNames = {"assigneeIdentifier", "role_id", "definitionPoint_id"})
Expand All @@ -34,7 +37,7 @@
)
@NamedQueries({
@NamedQuery(name = "RoleAssignment.listByAssigneeIdentifier_DefinitionPointId",
query = "SELECT r FROM RoleAssignment r WHERE r.assigneeIdentifier=:assigneeIdentifier AND r.definitionPoint.id=:definitionPointId"),
query = "SELECT r FROM RoleAssignment r WHERE r.assigneeIdentifier=:assigneeIdentifier AND r.definitionPoint.id=:definitionPointId AND r.anonymized = :anonymized"),
@NamedQuery(name = "RoleAssignment.listByAssigneeIdentifier_DefinitionPointId_RoleId",
query = "SELECT r FROM RoleAssignment r WHERE r.assigneeIdentifier=:assigneeIdentifier AND r.definitionPoint.id=:definitionPointId and r.role.id=:roleId"),
@NamedQuery(name = "RoleAssignment.listByAssigneeIdentifier",
Expand All @@ -50,96 +53,117 @@
})
public class RoleAssignment implements java.io.Serializable, JpaEntity<Long> {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@GeneratedValue(strategy = IDENTITY)
private Long id;

@Column(nullable = false)
private String assigneeIdentifier;

@ManyToOne(cascade = {CascadeType.MERGE})
@ManyToOne(cascade = {MERGE})
@JoinColumn(nullable = false)
private DataverseRole role;

@ManyToOne(cascade = {CascadeType.MERGE})
@ManyToOne(cascade = {MERGE})
@JoinColumn(nullable = false)
private DvObject definitionPoint;

@Column(nullable = true)
private String privateUrlToken;

private boolean anonymized;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this new column also be considered in equals/toString below?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed


public RoleAssignment() {
}

public RoleAssignment(DataverseRole aRole, RoleAssignee anAssignee, DvObject aDefinitionPoint, String privateUrlToken) {
role = aRole;
assigneeIdentifier = anAssignee.getIdentifier();
definitionPoint = aDefinitionPoint;
public RoleAssignment(DataverseRole aRole, RoleAssignee anAssignee,
DvObject aDefinitionPoint, String privateUrlToken) {
this(aRole, anAssignee, aDefinitionPoint, privateUrlToken, false);
}

public RoleAssignment(DataverseRole aRole, RoleAssignee anAssignee,
DvObject aDefinitionPoint, String privateUrlToken, boolean anonymized) {
this.role = aRole;
this.assigneeIdentifier = anAssignee.getIdentifier();
this.definitionPoint = aDefinitionPoint;
this.privateUrlToken = privateUrlToken;
this.anonymized = anonymized;
}

public Long getId() {
return id;
return this.id;
}

public void setId(Long id) {
this.id = id;
}

public String getAssigneeIdentifier() {
return assigneeIdentifier;
return this.assigneeIdentifier;
}

public void setAssigneeIdentifier(String assigneeIdentifier) {
this.assigneeIdentifier = assigneeIdentifier;
}

public DataverseRole getRole() {
return role;
return this.role;
}

public void setRole(DataverseRole role) {
this.role = role;
}

public DvObject getDefinitionPoint() {
return definitionPoint;
return this.definitionPoint;
}

public void setDefinitionPoint(DvObject definitionPoint) {
this.definitionPoint = definitionPoint;
}

public String getPrivateUrlToken() {
return privateUrlToken;
return this.privateUrlToken;
}

public boolean isAnonymized() {
return this.anonymized;
}

public void setAnonymized(final boolean anonymized) {
this.anonymized = anonymized;
}

@Override
public int hashCode() {
int hash = 7;
hash = 97 * hash + Objects.hashCode(role);
hash = 97 * hash + Objects.hashCode(assigneeIdentifier);
int hash = Boolean.hashCode(this.anonymized);
hash = 97 * hash + Objects.hashCode(this.role);
hash = 97 * hash + Objects.hashCode(this.assigneeIdentifier);
return hash;
}

@Override
public boolean equals(Object obj) {
if (obj == null) {
public boolean equals(final Object obj) {
if (obj instanceof RoleAssignment) {
final RoleAssignment other = (RoleAssignment) obj;

return Objects.equals(getRole(), other.getRole())
&& Objects.equals(getAssigneeIdentifier(),
other.getAssigneeIdentifier())
&& Objects.equals(getDefinitionPoint(),
other.getDefinitionPoint())
&& this.anonymized == other.anonymized;
} else {
return false;
}
if (!(obj instanceof RoleAssignment)) {
return false;
}
final RoleAssignment other = (RoleAssignment) obj;

return (Objects.equals(getRole(), other.getRole())
&& Objects.equals(getAssigneeIdentifier(), other.getAssigneeIdentifier())
&& Objects.equals(getDefinitionPoint(), other.getDefinitionPoint()));

}

@Override
public String toString() {
return "RoleAssignment{" + "id=" + id + ", assignee=" + assigneeIdentifier + ", role=" + role + ", definitionPoint=" + definitionPoint + '}';
return "RoleAssignment{"
+ "id=" + id
+ ", assignee=" + assigneeIdentifier
+ ", role=" + role + ", definitionPoint=" + definitionPoint
+ ", anonymized=" + this.anonymized + '}';
}

}
Loading
Loading