* @param name
* @param parent
* @param creator
- * @param owner
*/
private void createFolder(String name, Folder parent, User creator) {
Folder folder = new Folder();
auditInfo.setModificationDate(now);
user.setAuditInfo(auditInfo);
user.generateAuthToken();
+ user.generateWebDAVPassword();
dao.create(user);
// Make sure we get an ID in the user object.
dao.flush();
Folder folder = dao.getEntityById(Folder.class, folderId);
if(!folder.hasModifyACLPermission(user))
throw new InsufficientPermissionsException("You don't have the necessary permissions");
+ // Delete previous entries
+ for (Permission perm: folder.getPermissions())
+ dao.delete(perm);
folder.getPermissions().clear();
for (PermissionDTO dto : permissions) {
if (dto.getUser()!=null && dto.getUser().getId().equals(folder.getOwner().getId()) && (!dto.hasRead() || !dto.hasWrite() || !dto.hasModifyACL()))
throw new InsufficientPermissionsException("Can't remove permissions from owner");
+ // Don't include 'empty' permission
+ if (!dto.getRead() && !dto.getWrite() && !dto.getModifyACL()) continue;
folder.addPermission(getPermission(dto));
}
dao.update(folder);
else
throw new InsufficientPermissionsException("Only the owner can change the read-for-all flag");
- if (permissions != null && !permissions.isEmpty()) {
- file.getPermissions().clear();
- for (PermissionDTO dto : permissions) {
- if (dto.getUser()!=null && dto.getUser().getId().equals(file.getOwner().getId()) && (!dto.hasRead() || !dto.hasWrite() || !dto.hasModifyACL()))
- throw new InsufficientPermissionsException("Can't remove permissions from owner");
- file.addPermission(getPermission(dto));
+ // Update the file if there was a change.
+ if (readForAll != null || permissions != null && !permissions.isEmpty()) {
+ if (permissions != null && !permissions.isEmpty()) {
+ // Delete previous entries
+ for (Permission perm: file.getPermissions())
+ dao.delete(perm);
+ file.getPermissions().clear();
+ for (PermissionDTO dto : permissions) {
+ if (dto.getUser()!=null && dto.getUser().getId().equals(file.getOwner().getId()) && (!dto.hasRead() || !dto.hasWrite() || !dto.hasModifyACL()))
+ throw new InsufficientPermissionsException("Can't remove permissions from owner");
+ // Don't include 'empty' permission
+ if (!dto.getRead() && !dto.getWrite() && !dto.getModifyACL()) continue;
+ file.addPermission(getPermission(dto));
+ }
}
- }
- // Update the file if there was a change.
- if (readForAll != null || permissions != null && !permissions.isEmpty())
dao.update(file);
-
+ }
}
@Override
/**
* Gets the quota for specified userId
- * @param userId
- * @return
- */
- private Long getQuota(@SuppressWarnings("unused") Long userId){
- Long quota = getConfiguration().getLong("quota", new Long(52428800L));
- return quota;
- }
+ * @param userId
+ * @return
+ */
+ private Long getQuota(@SuppressWarnings("unused") Long userId){
+ Long quota = getConfiguration().getLong("quota", new Long(52428800L));
+ return quota;
+ }
public void rebuildSolrIndex() {
MessageProducer sender = null;
private void createFileBody(String name, String mimeType, File uploadedFile,
FileHeader header, AuditInfo auditInfo, User owner)
throws FileNotFoundException, QuotaExceededException {
+
+ long currentTotalSize = 0;
+ if (!header.isVersioned() && header.getCurrentBody() != null && header.getBodies() != null)
+ currentTotalSize = header.getTotalSize();
+ Long quotaLeft = getQuotaLeft(header.getOwner().getId());
+ if(quotaLeft < uploadedFile.length()-currentTotalSize) {
+ uploadedFile.delete();
+ throw new QuotaExceededException("Not enough free space available");
+ }
+
FileBody body = new FileBody();
// if no mime type or the generic mime type is defined by the client, then try to identify it from the filename extension
|| "octet/stream".equals(mimeType) || "application/unknown".equals(mimeType))
body.setMimeType(identifyMimeType(name));
else
- body.setMimeType(mimeType);
+ body.setMimeType(mimeType);
body.setAuditInfo(auditInfo);
body.setFileSize(uploadedFile.length());
body.setOriginalFilename(name);
}
}
- Long quotaLeft = getQuotaLeft(owner.getId());
- if(quotaLeft < uploadedFile.length())
- throw new QuotaExceededException("Not enough free space available");
dao.flush();
header.addBody(body);
return true;
}
+ /**
+ * Reset WebDAV password for given user.
+ *
+ * @param userId
+ * @return the new password
+ * @throws ObjectNotFoundException
+ */
+ @Override
+ public String resetWebDAVPassword(Long userId) throws ObjectNotFoundException {
+ if (userId == null)
+ throw new ObjectNotFoundException("No user specified");
+ User user = dao.getEntityById(User.class, userId);
+ user.generateWebDAVPassword();
+ return user.getWebDAVPassword();
+ }
+
}