mirror of
https://github.com/sismics/docs.git
synced 2024-11-22 05:57:57 +01:00
missing document updated events
This commit is contained in:
parent
d1a8fa38b0
commit
229d845a42
@ -10,10 +10,12 @@ import com.sismics.docs.core.dao.UserDao;
|
||||
import com.sismics.docs.core.dao.criteria.UserCriteria;
|
||||
import com.sismics.docs.core.dao.dto.RouteStepDto;
|
||||
import com.sismics.docs.core.dao.dto.UserDto;
|
||||
import com.sismics.docs.core.event.DocumentUpdatedAsyncEvent;
|
||||
import com.sismics.docs.core.event.RouteStepValidateEvent;
|
||||
import com.sismics.docs.core.model.context.AppContext;
|
||||
import com.sismics.docs.core.model.jpa.Acl;
|
||||
import com.sismics.docs.core.model.jpa.Document;
|
||||
import com.sismics.util.context.ThreadLocalContext;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@ -26,17 +28,17 @@ public class RoutingUtil {
|
||||
/**
|
||||
* Update routing ACLs according to the current route step.
|
||||
*
|
||||
* @param sourceId Source ID
|
||||
* @param documentId Document ID
|
||||
* @param currentStep Current route step
|
||||
* @param previousStep Previous route step
|
||||
* @param userId User ID
|
||||
*/
|
||||
public static void updateAcl(String sourceId, RouteStepDto currentStep, RouteStepDto previousStep, String userId) {
|
||||
public static void updateAcl(String documentId, RouteStepDto currentStep, RouteStepDto previousStep, String userId) {
|
||||
AclDao aclDao = new AclDao();
|
||||
|
||||
if (previousStep != null) {
|
||||
// Remove the previous ACL
|
||||
aclDao.delete(sourceId, PermType.READ, previousStep.getTargetId(), userId, AclType.ROUTING);
|
||||
aclDao.delete(documentId, PermType.READ, previousStep.getTargetId(), userId, AclType.ROUTING);
|
||||
}
|
||||
|
||||
if (currentStep != null) {
|
||||
@ -44,10 +46,16 @@ public class RoutingUtil {
|
||||
Acl acl = new Acl();
|
||||
acl.setPerm(PermType.READ);
|
||||
acl.setType(AclType.ROUTING);
|
||||
acl.setSourceId(sourceId);
|
||||
acl.setSourceId(documentId);
|
||||
acl.setTargetId(currentStep.getTargetId());
|
||||
aclDao.create(acl, userId);
|
||||
}
|
||||
|
||||
// Raise a document updated event
|
||||
DocumentUpdatedAsyncEvent event = new DocumentUpdatedAsyncEvent();
|
||||
event.setUserId(userId);
|
||||
event.setDocumentId(documentId);
|
||||
ThreadLocalContext.get().addAsyncEvent(event);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -96,7 +96,9 @@ public class AclResource extends BaseResource {
|
||||
// Avoid duplicates
|
||||
if (!aclDao.checkPermission(acl.getSourceId(), acl.getPerm(), Lists.newArrayList(acl.getTargetId()))) {
|
||||
aclDao.create(acl, principal.getId());
|
||||
|
||||
|
||||
// TODO Update event for direct and indirect documents
|
||||
|
||||
// Returns the ACL
|
||||
JsonObjectBuilder response = Json.createObjectBuilder()
|
||||
.add("perm", acl.getPerm().name())
|
||||
@ -167,6 +169,8 @@ public class AclResource extends BaseResource {
|
||||
|
||||
// Delete the ACL
|
||||
aclDao.delete(sourceId, perm, targetId, principal.getId(), AclType.USER);
|
||||
|
||||
// TODO Update event for direct and indirect documents
|
||||
|
||||
// Always return OK
|
||||
JsonObjectBuilder response = Json.createObjectBuilder()
|
||||
|
@ -800,7 +800,7 @@ public class DocumentResource extends BaseResource {
|
||||
// Update relations
|
||||
updateRelationList(id, relationList);
|
||||
|
||||
// Raise a document updated event (with the document to update Lucene)
|
||||
// Raise a document updated event
|
||||
DocumentUpdatedAsyncEvent documentUpdatedAsyncEvent = new DocumentUpdatedAsyncEvent();
|
||||
documentUpdatedAsyncEvent.setUserId(principal.getId());
|
||||
documentUpdatedAsyncEvent.setDocumentId(id);
|
||||
|
@ -180,12 +180,6 @@ public class RouteResource extends BaseResource {
|
||||
throw new ClientException("ValidationError", "Invalid transition for this route step type");
|
||||
}
|
||||
|
||||
// Validate the step and update ACLs
|
||||
routeStepDao.endRouteStep(routeStepDto.getId(), routeStepTransition, comment, principal.getId());
|
||||
RouteStepDto newRouteStep = routeStepDao.getCurrentStep(documentId);
|
||||
RoutingUtil.updateAcl(documentId, newRouteStep, routeStepDto, principal.getId());
|
||||
RoutingUtil.sendRouteStepEmail(documentId, routeStepDto);
|
||||
|
||||
// Execute actions
|
||||
if (routeStepDto.getTransitions() != null) {
|
||||
try (JsonReader reader = Json.createReader(new StringReader(routeStepDto.getTransitions()))) {
|
||||
@ -206,6 +200,12 @@ public class RouteResource extends BaseResource {
|
||||
}
|
||||
}
|
||||
|
||||
// Validate the step and update ACLs
|
||||
routeStepDao.endRouteStep(routeStepDto.getId(), routeStepTransition, comment, principal.getId());
|
||||
RouteStepDto newRouteStep = routeStepDao.getCurrentStep(documentId);
|
||||
RoutingUtil.updateAcl(documentId, newRouteStep, routeStepDto, principal.getId());
|
||||
RoutingUtil.sendRouteStepEmail(documentId, routeStepDto);
|
||||
|
||||
JsonObjectBuilder response = Json.createObjectBuilder()
|
||||
.add("readable", aclDao.checkPermission(documentId, PermType.READ, getTargetIdList(null)));
|
||||
if (newRouteStep != null) {
|
||||
|
@ -6,12 +6,14 @@ import com.sismics.docs.core.constant.AclType;
|
||||
import com.sismics.docs.core.constant.PermType;
|
||||
import com.sismics.docs.core.dao.AclDao;
|
||||
import com.sismics.docs.core.dao.ShareDao;
|
||||
import com.sismics.docs.core.event.DocumentUpdatedAsyncEvent;
|
||||
import com.sismics.docs.core.model.jpa.Acl;
|
||||
import com.sismics.docs.core.model.jpa.Share;
|
||||
import com.sismics.rest.exception.ClientException;
|
||||
import com.sismics.rest.exception.ForbiddenClientException;
|
||||
import com.sismics.rest.util.ValidationUtil;
|
||||
import com.sismics.util.JsonUtil;
|
||||
import com.sismics.util.context.ThreadLocalContext;
|
||||
|
||||
import javax.json.Json;
|
||||
import javax.json.JsonObjectBuilder;
|
||||
@ -81,6 +83,12 @@ public class ShareResource extends BaseResource {
|
||||
acl.setTargetId(share.getId());
|
||||
aclDao.create(acl, principal.getId());
|
||||
|
||||
// Raise a document updated event
|
||||
DocumentUpdatedAsyncEvent event = new DocumentUpdatedAsyncEvent();
|
||||
event.setUserId(principal.getId());
|
||||
event.setDocumentId(documentId);
|
||||
ThreadLocalContext.get().addAsyncEvent(event);
|
||||
|
||||
// Returns the created ACL
|
||||
JsonObjectBuilder response = Json.createObjectBuilder()
|
||||
.add("perm", acl.getPerm().name())
|
||||
@ -130,6 +138,12 @@ public class ShareResource extends BaseResource {
|
||||
// Delete the share
|
||||
ShareDao shareDao = new ShareDao();
|
||||
shareDao.delete(id);
|
||||
|
||||
// Raise a document updated event
|
||||
DocumentUpdatedAsyncEvent event = new DocumentUpdatedAsyncEvent();
|
||||
event.setUserId(principal.getId());
|
||||
event.setDocumentId(acl.getSourceId());
|
||||
ThreadLocalContext.get().addAsyncEvent(event);
|
||||
|
||||
// Always return OK
|
||||
JsonObjectBuilder response = Json.createObjectBuilder()
|
||||
|
@ -331,7 +331,9 @@ public class TagResource extends BaseResource {
|
||||
if (!aclDao.checkPermission(id, PermType.WRITE, getTargetIdList(null))) {
|
||||
throw new NotFoundException();
|
||||
}
|
||||
|
||||
|
||||
// TODO Update event for associated documents
|
||||
|
||||
// Delete the tag
|
||||
TagDao tagDao = new TagDao();
|
||||
tagDao.delete(id, principal.getId());
|
||||
|
Loading…
Reference in New Issue
Block a user