use of org.craftercms.studio.api.v1.dal.SiteFeed in project studio by craftercms.
the class StudioAuditLogProcessingTask method processAuditLog.
private void processAuditLog(String site) throws SiteNotFoundException {
logger.debug("Getting last verified commit for site: " + site);
SiteFeed siteFeed = siteService.getSite(site);
if (checkSiteUuid(site, siteFeed.getSiteUuid())) {
String lastSyncedCommit = siteService.getLastSyncedGitlogCommitId(site);
if (StringUtils.isNotEmpty(lastSyncedCommit)) {
logger.debug("Update gitlog for site " + site + " from last synced commit " + lastSyncedCommit);
contentRepository.updateGitlog(site, lastSyncedCommit, batchSizeGitLog);
processAuditLogFromRepo(site, batchSizeAudited);
}
}
}
use of org.craftercms.studio.api.v1.dal.SiteFeed in project studio by craftercms.
the class StudioAuditLogProcessingTask method processAuditLogFromRepo.
private void processAuditLogFromRepo(String siteId, int batchSize) throws SiteNotFoundException {
List<GitLog> unauditedGitlogs = contentRepository.getUnauditedCommits(siteId, batchSize);
if (unauditedGitlogs != null) {
SiteFeed siteFeed = siteService.getSite(siteId);
for (GitLog gl : unauditedGitlogs) {
if (contentRepository.commitIdExists(siteId, gl.getCommitId())) {
String prevCommitId = gl.getCommitId() + PREVIOUS_COMMIT_SUFFIX;
List<RepoOperation> operations = contentRepository.getOperationsFromDelta(siteId, prevCommitId, gl.getCommitId());
for (RepoOperation repoOperation : operations) {
Map<String, String> activityInfo = new HashMap<String, String>();
String contentClass;
AuditLog auditLog;
switch(repoOperation.getAction()) {
case CREATE:
case COPY:
contentClass = contentService.getContentTypeClass(siteId, repoOperation.getPath());
if (repoOperation.getPath().endsWith(DmConstants.XML_PATTERN)) {
activityInfo.put(DmConstants.KEY_CONTENT_TYPE, contentClass);
}
logger.debug("Insert audit log for site: " + siteId + " path: " + repoOperation.getPath());
auditLog = auditServiceInternal.createAuditLogEntry();
auditLog.setOperation(OPERATION_CREATE);
auditLog.setOperationTimestamp(repoOperation.getDateTime());
auditLog.setSiteId(siteFeed.getId());
auditLog.setActorId(repoOperation.getAuthor());
auditLog.setActorDetails(repoOperation.getAuthor());
auditLog.setPrimaryTargetId(siteId + ":" + repoOperation.getPath());
auditLog.setPrimaryTargetType(TARGET_TYPE_CONTENT_ITEM);
auditLog.setPrimaryTargetValue(repoOperation.getPath());
auditLog.setPrimaryTargetSubtype(contentService.getContentTypeClass(siteId, repoOperation.getPath()));
auditLog.setOrigin(ORIGIN_GIT);
auditServiceInternal.insertAuditLog(auditLog);
break;
case UPDATE:
contentClass = contentService.getContentTypeClass(siteId, repoOperation.getPath());
if (repoOperation.getPath().endsWith(DmConstants.XML_PATTERN)) {
activityInfo.put(DmConstants.KEY_CONTENT_TYPE, contentClass);
}
logger.debug("Insert audit log for site: " + siteId + " path: " + repoOperation.getPath());
auditLog = auditServiceInternal.createAuditLogEntry();
auditLog.setOperation(OPERATION_UPDATE);
auditLog.setOperationTimestamp(repoOperation.getDateTime());
auditLog.setSiteId(siteFeed.getId());
auditLog.setActorId(repoOperation.getAuthor());
auditLog.setActorDetails(repoOperation.getAuthor());
auditLog.setOrigin(ORIGIN_GIT);
auditLog.setPrimaryTargetId(siteId + ":" + repoOperation.getPath());
auditLog.setPrimaryTargetType(TARGET_TYPE_CONTENT_ITEM);
auditLog.setPrimaryTargetValue(repoOperation.getPath());
auditLog.setPrimaryTargetSubtype(contentService.getContentTypeClass(siteId, repoOperation.getPath()));
auditServiceInternal.insertAuditLog(auditLog);
break;
case DELETE:
contentClass = contentService.getContentTypeClass(siteId, repoOperation.getPath());
if (repoOperation.getPath().endsWith(DmConstants.XML_PATTERN)) {
activityInfo.put(DmConstants.KEY_CONTENT_TYPE, contentClass);
}
logger.debug("Insert audit log for site: " + siteId + " path: " + repoOperation.getPath());
auditLog = auditServiceInternal.createAuditLogEntry();
auditLog.setOperation(OPERATION_DELETE);
auditLog.setOperationTimestamp(repoOperation.getDateTime());
auditLog.setSiteId(siteFeed.getId());
auditLog.setOrigin(ORIGIN_GIT);
auditLog.setActorId(repoOperation.getAuthor());
auditLog.setActorDetails(repoOperation.getAuthor());
auditLog.setPrimaryTargetId(siteId + ":" + repoOperation.getPath());
auditLog.setPrimaryTargetType(TARGET_TYPE_CONTENT_ITEM);
auditLog.setPrimaryTargetValue(repoOperation.getPath());
auditLog.setPrimaryTargetSubtype(contentService.getContentTypeClass(siteId, repoOperation.getPath()));
auditServiceInternal.insertAuditLog(auditLog);
break;
case MOVE:
contentClass = contentService.getContentTypeClass(siteId, repoOperation.getMoveToPath());
if (repoOperation.getMoveToPath().endsWith(DmConstants.XML_PATTERN)) {
activityInfo.put(DmConstants.KEY_CONTENT_TYPE, contentClass);
}
logger.debug("Insert audit log for site: " + siteId + " path: " + repoOperation.getMoveToPath());
auditLog = auditServiceInternal.createAuditLogEntry();
auditLog.setOperation(OPERATION_MOVE);
auditLog.setOperationTimestamp(repoOperation.getDateTime());
auditLog.setSiteId(siteFeed.getId());
auditLog.setActorId(repoOperation.getAuthor());
auditLog.setActorDetails(repoOperation.getAuthor());
auditLog.setOrigin(ORIGIN_GIT);
auditLog.setPrimaryTargetId(siteId + ":" + repoOperation.getMoveToPath());
auditLog.setPrimaryTargetType(TARGET_TYPE_CONTENT_ITEM);
auditLog.setPrimaryTargetValue(repoOperation.getMoveToPath());
auditLog.setPrimaryTargetSubtype(contentService.getContentTypeClass(siteId, repoOperation.getMoveToPath()));
auditServiceInternal.insertAuditLog(auditLog);
break;
default:
logger.error("Error: Unknown repo operation for site " + siteId + " operation: " + repoOperation.getAction());
break;
}
}
}
contentRepository.markGitLogAudited(siteId, gl.getCommitId());
}
}
}
use of org.craftercms.studio.api.v1.dal.SiteFeed in project studio by craftercms.
the class StudioAbstractAccessDecisionVoter method isSiteMember.
protected boolean isSiteMember(String siteId, User currentUser) {
try {
int total = siteService.getSitesPerUserTotal(currentUser.getUsername());
List<SiteFeed> sitesFeed = siteService.getSitesPerUser(currentUser.getUsername(), 0, total);
Set<String> sites = new HashSet<String>();
for (SiteFeed site : sitesFeed) {
sites.add(site.getSiteId());
}
return sites.contains(siteId);
} catch (UserNotFoundException e) {
logger.info("User is not site member", e);
return false;
} catch (ServiceLayerException e) {
logger.warn("Error getting user membership", e);
return false;
}
}
use of org.craftercms.studio.api.v1.dal.SiteFeed in project studio by craftercms.
the class StudioAbstractAccessDecisionVoter method isSiteAdmin.
protected boolean isSiteAdmin(String siteId, User currentUser) {
try {
int total = siteService.getSitesPerUserTotal(currentUser.getUsername());
List<SiteFeed> sitesFeed = siteService.getSitesPerUser(currentUser.getUsername(), 0, total);
Map<String, Long> sites = new HashMap<String, Long>();
for (SiteFeed site : sitesFeed) {
sites.put(site.getSiteId(), site.getId());
}
boolean toRet = sites.containsKey(siteId);
if (toRet) {
List<Group> userGroups = userServiceInternal.getUserGroups(sites.get(siteId), currentUser.getUsername());
for (Group g : userGroups) {
if (g.getGroupName().equals(studioConfiguration.getProperty(CONFIGURATION_DEFAULT_ADMIN_GROUP))) {
toRet = true;
break;
}
}
toRet = userGroups.contains(studioConfiguration.getProperty(CONFIGURATION_DEFAULT_ADMIN_GROUP));
}
return toRet;
} catch (UserNotFoundException e) {
logger.info("User is not site member", e);
return false;
} catch (ServiceLayerException e) {
logger.error("Error getting user memberships", e);
return false;
}
}
use of org.craftercms.studio.api.v1.dal.SiteFeed in project studio by craftercms.
the class ContentServiceImpl method createFolder.
@Override
@ValidateParams
public boolean createFolder(@ValidateStringParam(name = "site") String site, @ValidateSecurePathParam(name = "path") String path, @ValidateStringParam(name = "name") String name) throws SiteNotFoundException {
boolean toRet = false;
String commitId = _contentRepository.createFolder(site, path, name);
if (commitId != null) {
SiteFeed siteFeed = siteService.getSite(site);
AuditLog auditLog = auditServiceInternal.createAuditLogEntry();
auditLog.setOperation(OPERATION_CREATE);
auditLog.setSiteId(siteFeed.getId());
auditLog.setActorId(securityService.getCurrentUser());
auditLog.setPrimaryTargetId(site + ":" + path + FILE_SEPARATOR + name);
auditLog.setPrimaryTargetType(TARGET_TYPE_FOLDER);
auditLog.setPrimaryTargetValue(path + FILE_SEPARATOR + name);
auditServiceInternal.insertAuditLog(auditLog);
contentRepository.insertGitLog(site, commitId, 1, 1);
siteService.updateLastCommitId(site, commitId);
toRet = true;
}
return toRet;
}
Aggregations