-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
BXC-4216 - Patron Role/Permission for accessing reduced quality images (
#1653) * Add viewReducedResolutionImages permission and canViewReducedQuality role. Remove unused methods. Add test coverage. Refactor roles to inherit permissions from each other, since almost all of them build off another role * Remove unused PermissionHelper methods. Add test coverage for still used methods * Shorten name * Require new permission for image downloads below full resolution * Only show reduced resolution image downloads in dropdown when viewReducedResImages is granted, and only show full size and original when viewOriginals granted. Update tests to include new permission * Allow new role to be added in admin ui * Add new permission to list of permitted patron roles/permissions, add CdrAcl property. Add additional tests to verify new permission works during evaluation and setting * For file record pages, if the user can access any download options (low res or original) then the download button will appear instead of the restricted content block. Add additional restrictedContent tests to verify this, check the dropdown has the right options, and some refactoring to DRY up code * Fix dropdown references now that there is an extra option. Add an extra test to verify new permission works in patron settings * Disable enum naming rule * Fix that collections were disallowing canViewReducedQuality. Reduce number of templates in restrictedContent.vue based on feedback
- Loading branch information
Showing
31 changed files
with
460 additions
and
546 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
141 changes: 141 additions & 0 deletions
141
auth-api/src/test/java/edu/unc/lib/boxc/auth/api/UserRoleTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,141 @@ | ||
package edu.unc.lib.boxc.auth.api; | ||
|
||
import edu.unc.lib.boxc.model.api.rdf.CdrAcl; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.util.Arrays; | ||
import java.util.Collections; | ||
import java.util.Set; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertFalse; | ||
import static org.junit.jupiter.api.Assertions.assertIterableEquals; | ||
import static org.junit.jupiter.api.Assertions.assertNull; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
/** | ||
* @author bbpennel | ||
*/ | ||
public class UserRoleTest { | ||
@Test | ||
public void canViewReducedQualityPermissionsTest() { | ||
var subject = UserRole.canViewReducedQuality; | ||
var expectedPermissions = Set.of( | ||
Permission.viewMetadata, Permission.viewAccessCopies, Permission.viewReducedResImages); | ||
assertSetMatchesExactly(expectedPermissions, subject.getPermissions()); | ||
} | ||
|
||
@Test | ||
public void canViewReducedQualityPermissionNamesTest() { | ||
var subject = UserRole.canViewReducedQuality; | ||
var expectedNames = Set.of(Permission.viewMetadata.name(), Permission.viewAccessCopies.name(), | ||
Permission.viewReducedResImages.name()); | ||
assertSetMatchesExactly(expectedNames, subject.getPermissionNames()); | ||
} | ||
|
||
@Test | ||
public void administratorPermissionsTest() { | ||
var subject = UserRole.administrator; | ||
var expectedPermissions = Set.of(Permission.values()); | ||
assertSetMatchesExactly(expectedPermissions, subject.getPermissions()); | ||
} | ||
|
||
@Test | ||
public void getUserRolesWithNoPermissionsTest() { | ||
// Listing no permissions returns all user roles | ||
assertSetMatchesExactly(Set.of(UserRole.values()), UserRole.getUserRoles(Collections.emptyList())); | ||
} | ||
|
||
@Test | ||
public void getUserRolesMatchesMultipleRolesTest() { | ||
var expected = Set.of(UserRole.canIngest, UserRole.canManage, | ||
UserRole.unitOwner, UserRole.administrator); | ||
var result = UserRole.getUserRoles(Arrays.asList(Permission.viewAccessCopies, Permission.ingest)); | ||
assertSetMatchesExactly(expected, result); | ||
} | ||
|
||
@Test | ||
public void getUserRolesWithPermissionOrderMembersTest() { | ||
var expected = Set.of(UserRole.canProcess, UserRole.canManage, | ||
UserRole.unitOwner, UserRole.administrator); | ||
var result = UserRole.getUserRolesWithPermission(Permission.orderMembers); | ||
assertSetMatchesExactly(expected, result); | ||
} | ||
|
||
@Test | ||
public void getStaffRolesTest() { | ||
var expected = Arrays.asList(UserRole.canAccess, UserRole.canIngest, UserRole.canDescribe, | ||
UserRole.canProcess, UserRole.canManage, UserRole.unitOwner, UserRole.administrator); | ||
assertIterableEquals(expected, UserRole.getStaffRoles()); | ||
} | ||
|
||
@Test | ||
public void getPatronRolesTest() { | ||
var expected = Arrays.asList(UserRole.none, UserRole.canDiscover, UserRole.canViewMetadata, | ||
UserRole.canViewAccessCopies, UserRole.canViewReducedQuality, UserRole.canViewOriginals); | ||
assertIterableEquals(expected, UserRole.getPatronRoles()); | ||
} | ||
|
||
@Test | ||
public void getRoleByPropertyValidTest() { | ||
assertEquals(UserRole.canAccess, UserRole.getRoleByProperty(CdrAcl.canAccess.getURI())); | ||
} | ||
|
||
@Test | ||
public void getRoleByPropertyNotFoundTest() { | ||
assertNull(UserRole.getRoleByProperty("http://example.com/ohno")); | ||
} | ||
|
||
@Test | ||
public void getPredicateTest() { | ||
assertEquals("canManage", UserRole.canManage.getPredicate()); | ||
} | ||
|
||
@Test | ||
public void getPropertyTest() { | ||
assertEquals(CdrAcl.canManage, UserRole.canManage.getProperty()); | ||
} | ||
|
||
@Test | ||
public void getURITest() { | ||
assertEquals(CdrAcl.canManage, UserRole.canManage.getProperty()); | ||
} | ||
|
||
@Test | ||
public void isStaffRoleTrueTest() { | ||
assertTrue(UserRole.canManage.isStaffRole()); | ||
} | ||
|
||
@Test | ||
public void isStaffRoleFalseTest() { | ||
assertFalse(UserRole.canViewReducedQuality.isStaffRole()); | ||
} | ||
|
||
@Test | ||
public void isPatronRoleFalseTest() { | ||
assertFalse(UserRole.canManage.isPatronRole()); | ||
} | ||
|
||
@Test | ||
public void isPatronRoleTrueTest() { | ||
assertTrue(UserRole.canViewReducedQuality.isPatronRole()); | ||
} | ||
|
||
@Test | ||
public void equalsTrueTest() { | ||
assertTrue(UserRole.none.equals(CdrAcl.none.getURI())); | ||
} | ||
|
||
@Test | ||
public void equalsFalseTest() { | ||
assertFalse(UserRole.none.equals("hello")); | ||
} | ||
|
||
// Compare that two sets are exactly equal, order insensitive. | ||
// junits assertIterableEquals is not reliable with sets since it depends on order, and we aren't importing hamcrest | ||
private <T> void assertSetMatchesExactly(Set<T> expected, Set<T> actual) { | ||
var message = "Actual set values did not match expected:\nActual: " + actual + "\nExpected: " + expected; | ||
assertTrue(actual.containsAll(expected), message); | ||
assertEquals(expected.size(), actual.size(), message); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.