Skip to content

Commit

Permalink
Merge pull request #1848 from UNC-Libraries/zip-files-development
Browse files Browse the repository at this point in the history
Merge Zip files development into main
  • Loading branch information
bbpennel authored Dec 4, 2024
2 parents c722d36 + 2077a63 commit c177bb7
Show file tree
Hide file tree
Showing 45 changed files with 1,123 additions and 346 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ mvn -pl '!clamav-java' verify
### Running JavaScript tests
```
# JavaScript Tests
npm --prefix static/js/admin/vue-permissions-editor run test
npm --prefix static/js/admin/vue-cdr-admin run test
npm --prefix static/js/vue-cdr-access run test
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public class AccessPrincipalConstants {
public final static String PATRON_NAMESPACE = "unc:patron:";
public final static String IP_PRINC_NAMESPACE = PATRON_NAMESPACE + "ipp:";
public final static String ADMIN_ACCESS_PRINC = "admin_access";
public final static String ON_CAMPUS_PRINC = "unc:patron:ipp:on_campus";

public final static Pattern PATRON_PRINC_PATTERN =
Pattern.compile("(" + PUBLIC_PRINC
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
package edu.unc.lib.boxc.operations.impl.download;

import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import edu.unc.lib.boxc.auth.api.models.AccessGroupSet;
import edu.unc.lib.boxc.auth.api.models.AgentPrincipals;
import edu.unc.lib.boxc.auth.fcrepo.models.AgentPrincipalsImpl;

public class DownloadBulkRequest {
private String workPidString;
@JsonDeserialize(as = AgentPrincipalsImpl.class)
private AgentPrincipals agent;
private AccessGroupSet principals;

public DownloadBulkRequest(String workPidString, AgentPrincipals agent) {
public DownloadBulkRequest(String workPidString, AccessGroupSet principals) {
this.workPidString = workPidString;
this.agent = agent;
this.principals = principals;
}

public String getWorkPidString() {
Expand All @@ -22,11 +22,11 @@ public void setWorkPidString(String workPidString) {
this.workPidString = workPidString;
}

public AgentPrincipals getAgent() {
return agent;
public AccessGroupSet getPrincipals() {
return principals;
}

public void setAgent(AgentPrincipals agent) {
this.agent = agent;
public void setPrincipals(AccessGroupSet principals) {
this.principals = principals;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import edu.unc.lib.boxc.auth.api.models.AccessGroupSet;
import edu.unc.lib.boxc.auth.api.services.AccessControlService;
import edu.unc.lib.boxc.fcrepo.exceptions.ServiceException;
import edu.unc.lib.boxc.model.api.exceptions.NotFoundException;
import edu.unc.lib.boxc.model.api.objects.ContentObject;
import edu.unc.lib.boxc.model.api.objects.FileObject;
import edu.unc.lib.boxc.model.api.objects.RepositoryObjectLoader;
Expand All @@ -29,11 +28,12 @@ public class DownloadBulkService {
private AccessControlService aclService;
private RepositoryObjectLoader repoObjLoader;
private Path basePath;
private int fileLimit;

public Path downloadBulk(DownloadBulkRequest request) {
var pidString = request.getWorkPidString();
var workPid = PIDs.get(pidString);
var agentPrincipals = request.getAgent().getPrincipals();
var agentPrincipals = request.getPrincipals();
aclService.assertHasAccess(
"User does not have permissions to view the Work for download",
workPid, agentPrincipals, Permission.viewOriginal);
Expand Down Expand Up @@ -61,7 +61,14 @@ private void zipFiles(WorkObject workObject, AccessGroupSet agentPrincipals, Pat
}

Map<String, Integer> duplicates = new HashMap<>();
int count = 0;
for (ContentObject memberObject : memberObjects ) {
if (count == fileLimit) {
break;
}
if (!(memberObject instanceof FileObject)) {
continue;
}
var fileObject = (FileObject) memberObject;
if (aclService.hasAccess(memberObject.getPid(), agentPrincipals, Permission.viewOriginal)) {
var binObj = fileObject.getOriginalFile();
Expand All @@ -82,6 +89,7 @@ private void zipFiles(WorkObject workObject, AccessGroupSet agentPrincipals, Pat

IOUtils.copy(binaryStream, zipOut);
}
count++;
}
}
}
Expand Down Expand Up @@ -111,4 +119,8 @@ public void setRepoObjLoader(RepositoryObjectLoader repoObjLoader) {
public void setBasePath(Path basePath) {
this.basePath = basePath;
}

public void setFileLimit(int fileLimit) {
this.fileLimit = fileLimit;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
import edu.unc.lib.boxc.auth.api.models.AccessGroupSet;
import edu.unc.lib.boxc.auth.api.models.AgentPrincipals;
import edu.unc.lib.boxc.auth.api.services.AccessControlService;
import edu.unc.lib.boxc.model.api.exceptions.NotFoundException;
import edu.unc.lib.boxc.model.api.exceptions.ObjectTypeMismatchException;
import edu.unc.lib.boxc.model.api.ids.PID;
import edu.unc.lib.boxc.model.api.objects.BinaryObject;
import edu.unc.lib.boxc.model.api.objects.FileObject;
import edu.unc.lib.boxc.model.api.objects.RepositoryObjectLoader;
import edu.unc.lib.boxc.model.api.objects.Tombstone;
import edu.unc.lib.boxc.model.api.objects.WorkObject;
import edu.unc.lib.boxc.model.fcrepo.ids.PIDs;
import org.apache.commons.io.IOUtils;
Expand Down Expand Up @@ -64,6 +64,8 @@ public class DownloadBulkServiceTest {
private WorkObject parentWork;
@Mock
private FileObject fileObject1, fileObject2;
@Mock
private Tombstone tombstone;
@TempDir
public Path zipStorageBasePath;

Expand All @@ -75,10 +77,11 @@ public void init() throws Exception {
service.setAclService(aclService);
service.setRepoObjLoader(repoObjLoader);
service.setBasePath(zipStorageBasePath);
service.setFileLimit(5);
parentPid = PIDs.get(PARENT_UUID);
fileObject1Pid = PIDs.get(CHILD1_UUID);
fileObject2Pid = PIDs.get(CHILD2_UUID);
request = new DownloadBulkRequest(PARENT_UUID, mockAgent);
request = new DownloadBulkRequest(PARENT_UUID, mockAccessSet);

when(mockAgent.getUsername()).thenReturn("user");
when(mockAgent.getPrincipals()).thenReturn(mockAccessSet);
Expand Down Expand Up @@ -154,6 +157,31 @@ public void noOriginalFilesTest() throws IOException {
assertZipFiles(List.of(), List.of());
}

@Test
public void tombstoneTest() throws IOException {
when(repoObjLoader.getWorkObject(eq(parentPid))).thenReturn(parentWork);
when(parentWork.getMembers()).thenReturn(List.of(tombstone));
service.downloadBulk(request);
// the zip file should be empty
assertZipFiles(List.of(), List.of());
}

@Test
public void fileLimitTest() throws IOException {
when(repoObjLoader.getWorkObject(any(PID.class))).thenReturn(parentWork);
when(parentWork.getMembers()).thenReturn(List.of(fileObject1, fileObject2));
makeBinaryObject(fileObject1, FILENAME1);
makeBinaryObject(fileObject2, FILENAME2);
when(aclService.hasAccess(eq(fileObject1Pid), any(),
eq(Permission.viewOriginal))).thenReturn(true);
when(aclService.hasAccess(eq(fileObject2Pid), any(),
eq(Permission.viewOriginal))).thenReturn(true);
service.setFileLimit(1);
service.downloadBulk(request);
// the zip file should have one entry
assertZipFiles(List.of(FILENAME1), List.of("flower"));
}

@Test
public void successTest() throws IOException {
when(repoObjLoader.getWorkObject(eq(parentPid))).thenReturn(parentWork);
Expand Down
1 change: 0 additions & 1 deletion static/css/cdrui_styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@
.thumbnail {
display: block;
position:relative;
float: left;
margin: 0 0 20px 0;
text-align: center;
object-fit: contain;
Expand Down
66 changes: 32 additions & 34 deletions static/css/sass/cdr_ui_styles.scss
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ $box-shadow: inset 3px 3px 10px -1px $box-shadow-color, 0px 16px 22px -15px $box
*
**/
.search-query-text {
margin: 40px 20px 40px 25px;
margin: 40px 20px 20px 25px;
font-size: 24px;

h2 {
Expand All @@ -147,13 +147,6 @@ form.search {
}
}

.browse-search {
.button.is-focused,
.button:focus {
color: #363636;
}
}

a.search-result-num {
background-color: $container-blue;
color: white !important;
Expand Down Expand Up @@ -420,11 +413,7 @@ p.no-search-results {

#child-files_filter {
margin-bottom: 25px;

label {
float: right;
width: 250px;
}
margin-top: -50px;
}

.input::placeholder, .input {
Expand All @@ -439,14 +428,19 @@ img.data-thumb {
max-width: 60px;
}

.child-records {
font-size: 16px;
margin: 30px 50px 25px 50px;
.file-list-header {
margin: 30px 0 5px;

h3 {
font-size: 16px;
margin-bottom: 30px;
margin: 0;
padding: 0;
}
}

.child-records {
font-size: 16px;
overflow: visible;

.fa.default-img-icon {
font-size: 32px;
Expand All @@ -459,14 +453,6 @@ img.data-thumb {
}
}

.is-icon {
background-color: $container-blue;
border: 1px solid $container-blue;
border-radius: 5px;
color: white;
padding: 7px;
}

.no-download {
background-color: #B8B8B8;
border-color: #B8B8B8;
Expand Down Expand Up @@ -614,7 +600,6 @@ img.data-thumb {

.full_record_top {
border-bottom: 1px solid $light-gray;
padding-bottom: 25px;

.collinfo {
width: 100%;
Expand Down Expand Up @@ -719,7 +704,7 @@ table.dataTable {
.actionlink {
a.action {
font-size: 16px;
padding: 15px 15px 30px 15px;
padding: 15px;
}
}
}
Expand All @@ -729,7 +714,6 @@ table.dataTable {
.restricted-access {
border: 1px solid;
border-radius: 5px;
padding: 15px;

.button {
text-align: left;
Expand Down Expand Up @@ -827,11 +811,6 @@ table.dataTable {
margin-bottom: 10px;
}

.button.is-focused,
.button:focus {
color: white;
}

/* MODs display for work and file pages, plus modalMetadata.vue component */
#mods_data_display {
margin: auto;
Expand Down Expand Up @@ -905,6 +884,21 @@ table.dataTable {
display: inline-flex;
}

.button.is-link.is-hovered,
.button.is-link:hover {
background-color: #276cda;
border-color: transparent;
color: #fff;
}

.navbar-link.is-active,
.navbar-link:hover,
a.navbar-item.is-active,
a.navbar-item:hover {
background-color: #fafafa;
color: #3273dc;
}

/*** End of Bulma overrides ***/

/* Following Bulma breakpoints */
Expand Down Expand Up @@ -1042,6 +1036,10 @@ table.dataTable {
}
}

#child-files_filter {
margin-top: -25px;
}

.dataTables_wrapper {
.dataTables_filter {
float: left !important;
Expand Down Expand Up @@ -1143,7 +1141,7 @@ iframe {

.clover-viewer {
margin: auto;
width: 90%;
width: 95%;
}

#information-toggle {
Expand Down
2 changes: 1 addition & 1 deletion static/js/vue-cdr-access/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bulma/0.7.2/css/bulma.min.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bulma@1.0.2/css/versions/bulma-no-dark-mode.min.css">
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.5.0/css/all.css">
<link rel="stylesheet" type="text/css" href="/static/css/cdr_access.css" />

Expand Down
Loading

0 comments on commit c177bb7

Please sign in to comment.