-
Notifications
You must be signed in to change notification settings - Fork 543
restored suppressing host dataverse field #11865
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
Changes from all commits
e043bf1
32dd076
84149b3
db03fff
d641b71
34cf465
44e8647
2e841e7
40351f5
1687097
7376590
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| ### Suppression of the Host Dataverse field | ||
|
|
||
| When creating a dataset, the _host dataverse_ field is not shown when the user can only add datasets to one collection. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -953,96 +953,90 @@ public List<Dataverse> findPermittedCollections(DataverseRequest request, Authen | |
|
|
||
| public List<Dataverse> findPermittedCollections(DataverseRequest request, AuthenticatedUser user, int permissionBit, String searchTerm) { | ||
| if (user != null) { | ||
| // IP Group - Only check IP if a User is calling for themself | ||
| String ipRangeSQL = "FALSE"; | ||
| if (request != null | ||
| && request.getAuthenticatedUser() != null | ||
| && !request.getAuthenticatedUser().isSuperuser() | ||
| && request.getSourceAddress() != null | ||
| && request.getAuthenticatedUser().getUserIdentifier().equalsIgnoreCase(user.getUserIdentifier())) { | ||
| IpAddress ip = request.getSourceAddress(); | ||
| if (ip instanceof IPv4Address) { | ||
| IPv4Address ipv4 = (IPv4Address) ip; | ||
| ipRangeSQL = ipv4.toBigInteger() + " BETWEEN ipv4range.bottomaslong AND ipv4range.topaslong"; | ||
| } else if (ip instanceof IPv6Address) { | ||
| IPv6Address ipv6 = (IPv6Address) ip; | ||
| long[] vals = ipv6.toLongArray(); | ||
| if (vals.length == 4) { | ||
| ipRangeSQL = """ | ||
| (@0 BETWEEN ipv6range.bottoma AND ipv6range.topa | ||
| AND @1 BETWEEN ipv6range.bottomb AND ipv6range.topb | ||
| AND @2 BETWEEN ipv6range.bottomc AND ipv6range.topc | ||
| AND @3 BETWEEN ipv6range.bottomd AND ipv6range.topd) | ||
| """; | ||
| for (int i = 0; i < vals.length; i++) { | ||
| ipRangeSQL = ipRangeSQL.replace("@" + i, String.valueOf(vals[i])); | ||
| } | ||
| } | ||
| } | ||
| var sqlCode = getBaseQueryForAllPermittedDataverses(request, user, permissionBit); | ||
| if (searchTerm == null || searchTerm.isEmpty()) { | ||
| return em.createNativeQuery(sqlCode, Dataverse.class).getResultList(); | ||
| } else if (user.isSuperuser()) { | ||
| Query query = em.createNativeQuery(sqlCode.concat(WHERE).concat(SEARCH_PARAMS), Dataverse.class); | ||
| setSearchParamValues(searchTerm, query); | ||
| return query.getResultList(); | ||
| } | ||
| String sqlCode; | ||
| if (user.isSuperuser()) { | ||
| sqlCode = LIST_ALL_DATAVERSES_SUPERUSER_HAS_PERMISSION; | ||
|
|
||
| if (searchTerm == null || searchTerm.isEmpty()) { | ||
| return em.createNativeQuery(sqlCode, Dataverse.class).getResultList(); | ||
| } else { | ||
| sqlCode = LIST_ALL_DATAVERSES_SUPERUSER_HAS_PERMISSION.concat(WHERE).concat(SEARCH_PARAMS); | ||
| else { | ||
| Query query = em.createNativeQuery(sqlCode.concat(AND).concat(SEARCH_PARAMS), Dataverse.class); | ||
| setSearchParamValues(searchTerm, query); | ||
| return query.getResultList(); | ||
| } | ||
| } | ||
| return null; | ||
| } | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm puzzled how to assemble the URL for testing linkingDataverses with the API.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Weird, Intellij does not blame me for the code inside getIpRange and setSearchParamValues but github does blame me.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The following command looks more like the intellij result |
||
|
|
||
| String pattern = searchTerm.toLowerCase(); | ||
| String pattern1 = pattern + "%"; | ||
| String pattern2 = "% " + pattern + "%"; | ||
| public boolean hasMultiplePermittedCollections(DataverseRequest request, AuthenticatedUser user, int permissionBit) { | ||
| if (user != null) { | ||
| var sqlCode = getBaseQueryForAllPermittedDataverses(request, user, permissionBit) + " LIMIT 2"; | ||
| var resultList = em.createNativeQuery(sqlCode, Dataverse.class).getResultList(); | ||
| return resultList.size() > 1; | ||
| } | ||
| return false; | ||
| } | ||
|
|
||
| // Adjust the queries for very short, 1 | ||
| if (pattern.length() == 1) { | ||
| pattern1 = pattern; | ||
| pattern2 = pattern + " %"; | ||
| } | ||
| Query query = em.createNativeQuery(sqlCode, Dataverse.class); | ||
| query.setParameter(1, "%dataverse"); | ||
| query.setParameter(2, pattern1); | ||
| query.setParameter(3, pattern2); | ||
| query.setParameter(4, "%dataverse"); | ||
| query.setParameter(5, pattern1); | ||
| query.setParameter(6, pattern2); | ||
| return query.getResultList(); | ||
| private String getBaseQueryForAllPermittedDataverses(DataverseRequest request, AuthenticatedUser user, int permissionBit) { | ||
| if (user.isSuperuser()) { | ||
| return LIST_ALL_DATAVERSES_SUPERUSER_HAS_PERMISSION; | ||
| } else { | ||
| return LIST_ALL_DATAVERSES_USER_HAS_PERMISSION | ||
| .replace("@USERID", String.valueOf(user.getId())) | ||
| .replace("@PERMISSIONBIT", String.valueOf(permissionBit)) | ||
| .replace("@IPRANGESQL", getIpRange(request, user)); | ||
| } | ||
| } | ||
|
|
||
| } | ||
| } else { | ||
| if (searchTerm == null || searchTerm.isEmpty()) { | ||
| sqlCode = LIST_ALL_DATAVERSES_USER_HAS_PERMISSION | ||
| .replace("@USERID", String.valueOf(user.getId())) | ||
| .replace("@PERMISSIONBIT", String.valueOf(permissionBit)) | ||
| .replace("@IPRANGESQL", ipRangeSQL); | ||
| return em.createNativeQuery(sqlCode, Dataverse.class).getResultList(); | ||
| } else { | ||
| String pattern = searchTerm.toLowerCase(); | ||
| String pattern1 = pattern + "%"; | ||
| String pattern2 = "% " + pattern + "%"; | ||
|
|
||
| // Adjust the queries for very short, 1 | ||
| if (pattern.length() == 1) { | ||
| pattern1 = pattern; | ||
| pattern2 = pattern + " %"; | ||
| private String getIpRange(DataverseRequest request, AuthenticatedUser user) { | ||
| // IP Group - Only check IP if a User is calling for themself | ||
| String ipRangeSQL = "FALSE"; | ||
| if (request != null | ||
| && request.getAuthenticatedUser() != null | ||
| && !request.getAuthenticatedUser().isSuperuser() | ||
| && request.getSourceAddress() != null | ||
| && request.getAuthenticatedUser().getUserIdentifier().equalsIgnoreCase(user.getUserIdentifier())) { | ||
| IpAddress ip = request.getSourceAddress(); | ||
| if (ip instanceof IPv4Address) { | ||
| IPv4Address ipv4 = (IPv4Address) ip; | ||
| ipRangeSQL = ipv4.toBigInteger() + " BETWEEN ipv4range.bottomaslong AND ipv4range.topaslong"; | ||
| } else if (ip instanceof IPv6Address) { | ||
| IPv6Address ipv6 = (IPv6Address) ip; | ||
| long[] vals = ipv6.toLongArray(); | ||
| if (vals.length == 4) { | ||
| ipRangeSQL = """ | ||
| (@0 BETWEEN ipv6range.bottoma AND ipv6range.topa | ||
| AND @1 BETWEEN ipv6range.bottomb AND ipv6range.topb | ||
| AND @2 BETWEEN ipv6range.bottomc AND ipv6range.topc | ||
| AND @3 BETWEEN ipv6range.bottomd AND ipv6range.topd) | ||
| """; | ||
| for (int i = 0; i < vals.length; i++) { | ||
| ipRangeSQL = ipRangeSQL.replace("@" + i, String.valueOf(vals[i])); | ||
| } | ||
|
|
||
| sqlCode = LIST_ALL_DATAVERSES_USER_HAS_PERMISSION.concat(AND).concat(SEARCH_PARAMS) | ||
| .replace("@USERID", String.valueOf(user.getId())) | ||
| .replace("@PERMISSIONBIT", String.valueOf(permissionBit)) | ||
| .replace("@IPRANGESQL", ipRangeSQL); | ||
|
|
||
| Query query = em.createNativeQuery(sqlCode, Dataverse.class); | ||
| query.setParameter(1, "%dataverse"); | ||
| query.setParameter(2, pattern1); | ||
| query.setParameter(3, pattern2); | ||
| query.setParameter(4, "%dataverse"); | ||
| query.setParameter(5, pattern1); | ||
| query.setParameter(6, pattern2); | ||
| return query.getResultList(); | ||
| } | ||
| } | ||
| } | ||
| return null; | ||
| return ipRangeSQL; | ||
| } | ||
|
|
||
| private void setSearchParamValues(String searchTerm, Query query) { | ||
| String pattern = searchTerm.toLowerCase(); | ||
| String pattern1 = pattern + "%"; | ||
| String pattern2 = "% " + pattern + "%"; | ||
|
|
||
| // Adjust the queries for very short, 1 | ||
| if (pattern.length() == 1) { | ||
| pattern1 = pattern; | ||
| pattern2 = pattern + " %"; | ||
| } | ||
| query.setParameter(1, "%dataverse"); | ||
| query.setParameter(2, pattern1); | ||
| query.setParameter(3, pattern2); | ||
| query.setParameter(4, "%dataverse"); | ||
| query.setParameter(5, pattern1); | ||
| query.setParameter(6, pattern2); | ||
| } | ||
|
|
||
| /** | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.