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

Conversation

lbownik
Copy link
Contributor

@lbownik lbownik commented Dec 30, 2024

No description provided.

@lbownik lbownik requested a review from diasf December 30, 2024 14:57
@lbownik lbownik force-pushed the 2540_Create_double_blind_review_ready_Anonymized_Private_URL branch from 9030d40 to 4be2290 Compare December 30, 2024 15:13
@@ -178,7 +185,8 @@ public DatasetPage(DataverseSession session, EjbDataverseEngine commandEngine,
DatasetThumbnailService datasetThumbnailService, DatasetSummaryService datasetSummaryService,
GuestbookResponseServiceBean guestbookResponseService, ConfirmEmailServiceBean confirmEmailService,
AuthenticationServiceBean authenticationService, DatasetPageFacade datasetPageFacade,
CitationFactory citationFactory, UningestInfoService uningestInfoService) {
CitationFactory citationFactory, UningestInfoService uningestInfoService,
SettingsWrapper settingsWrapper) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Added but not used.

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

@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

this.displayCitation = displayCitation;

public boolean displayCitation() {
return ! this.session.isViewedFromAnonymizedPrivateUrl(this.dataset);
Copy link
Contributor

Choose a reason for hiding this comment

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

You added DatasetPage.isViewedFromAnonymizedPrivateUrl but didn't use it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

i did in metadataTab.xhtml
<ui:param name="isViewedFromAnonymizedPrivateUrl" value="#{DatasetPage.isViewedFromAnonymizedPrivateUrl()}"/>

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah I know, just thought it could also be used here and in the method below as well. But not insisting.

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


boolean isAnonymized();

boolean isAffiliatedWith(DvObject object);
Copy link
Contributor

Choose a reason for hiding this comment

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

The isAffiliatedWith name is a bit misleading. In dataverse affiliation is usually used between users and organizations. Not sure actually if it's worth having this method for all users, it seems to make sense only for PrivateUrlUser, so maybe we could just have it there (same for isAnonymized)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Having these methods in User class hierarchy simplifies client code and is more elegant than using instanceof operator (my opintion, you may disagree)
isAffiliatedWith - so maybe "isRelatedWith" or isAllowedToView ? (any proposals) ?

Copy link
Contributor

Choose a reason for hiding this comment

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

Having these methods in User class hierarchy simplifies client code and is more elegant than using instanceof operator (my opintion, you may disagree)

Would agree that instanceof is usually a sign of sub-optimal design. But adding methods to an interface which will only be used for a specific implementation does also violate the interface segregation principle. And it looks like that's the case here as the only place we use those two new methods are for instances of PrivateUrlUser:

    public boolean isViewedFromPrivateUrl(final DvObject dataset) {
        return getUser() instanceof PrivateUrlUser && getUser().isAffiliatedWith(dataset);
    }
    
    public boolean isViewedFromAnonymizedPrivateUrl(final DvObject dataset) {
        return getUser().isAnonymized() && isViewedFromPrivateUrl(dataset);
    }

By that I mean, the above methods specifically have ...PrivateUrl(.. in their name, so we're not concerned about any other types of users.

isAffiliatedWith - so maybe "isRelatedWith" or isAllowedToView ? (any proposals) ?

If we're accepting that we're in the context of PrivateUrlUser, then I would say you don't need that method at all and could just do:

    public boolean isViewedFromPrivateUrl(final DvObject dataset) {
        return getPrivateUrlUser().exists(u -> u.getDatasetId() == dataset.getId());
    }
    
    public boolean isViewedFromAnonymizedPrivateUrl(final DvObject dataset) {
        return getPrivateUrlUser().exists(PrivateUrlUser::isAnonymized) && isViewedFromPrivateUrl(dataset);
    }

    private Option<PrivateUrlUser> getPrivateUrlUser() {
        return Option.of(getUser()).filter(PrivateUrlUser.class::isInstance).map(PrivateUrlUser.class::cast);
    }

Just a proposition. If you want to keep the method in PrivateUrlUser, then isAllowedToView would be fine, I think.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes I'm aware that I have conflicting situation here - striving for encapsulation and genericness naturally violates interface segregation principle (eg. Object.hashCode violates it) - it is a contentious issue

I renamed isAffiliatedWith into isAllowedToView and changed Guest.isAllowedToView to return true as this makes more sense (though Guest.isAllowedToView implementation is not used in any usecase)

Copy link
Contributor

Choose a reason for hiding this comment

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

yes I'm aware that I have conflicting situation here - striving for encapsulation and genericness naturally violates interface segregation principle (eg. Object.hashCode violates it) - it is a contentious issue

So let's change it, and remove those methods from User. Genericness is not giving us anything here, as we don't even make reasonable use of it right from the start.

I agreed on isAllowedToView name only under the condition that it's for PrivateUrlUser only. For other implementations of User the method (at least with the current implementation) doesn't make much sense. It's not like someone who calls user.isAllowedToView(dataset) would get a correct response which would account for access permissions.

@diasf diasf assigned lbownik and unassigned diasf Jan 8, 2025
@lbownik lbownik assigned diasf and unassigned diasf and lbownik Jan 8, 2025
@lbownik lbownik requested a review from diasf January 8, 2025 12:09
@diasf diasf assigned lbownik and unassigned diasf Jan 8, 2025
@lbownik lbownik merged commit 0121540 into develop Jan 8, 2025
1 check passed
@lbownik lbownik deleted the 2540_Create_double_blind_review_ready_Anonymized_Private_URL branch January 8, 2025 14:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants