Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/maven/fixes/9.1' into maven/rele…
Browse files Browse the repository at this point in the history
…ase/9.1
  • Loading branch information
metaventis-build committed Nov 4, 2024
2 parents ea06204 + 418c9ad commit e01e766
Show file tree
Hide file tree
Showing 27 changed files with 339 additions and 166 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2022,6 +2022,8 @@ public static synchronized Set<String> getUsagePermissions(){
usagePermissions.add(PERMISSION_READ_PREVIEW);
usagePermissions.add(PERMISSION_READ_ALL);
usagePermissions.add(PERMISSION_CONSUMER);
usagePermissions.add(PERMISSION_DOWNLOAD_CONTENT);
usagePermissions.add(PERMISSION_EMBED);
usagePermissions.add(PERMISSION_COMMENT);
usagePermissions.add(PERMISSION_RATE);
usagePermissions.add(PERMISSION_RATE_READ);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ private enum ReportType {
@JobFieldDescription(description = "When set to true, the job will generate a yearly report as well (only on 1st January)")
private boolean generateYearly = false;

@JobFieldDescription(description = "When set to true, the job will generate a quaternary report as well (only on 1st of January, April, July and October)")
private boolean generateQuaternary = false;
@JobFieldDescription(description = "When set to true, the job will generate a quarterly report as well (only on 1st of January, April, July and October)")
private boolean generateQuarterly = false;

@JobFieldDescription(description = "use a custom date (month) to run the job for. Note: The job will run the month BEFORE the given date!", sampleValue = "YYYY-MM-DD")
private Date customDate = null;
Expand Down Expand Up @@ -142,7 +142,7 @@ private Void createStats() {
}

LocalDate lastMonth = localDate.minusMonths(1);
LocalDate from = LocalDate.of(lastMonth.getYear(), lastMonth.getMonth(), 1);
LocalDate from = lastMonth.withDayOfMonth(1);

YearMonth month = YearMonth.from(from);
LocalDate to = month.atEndOfMonth();
Expand All @@ -158,13 +158,15 @@ private Void createStats() {
generateSchoolReportByTimeRange(mediacenter, startDate, endDate, ReportType.Monthly);

if (generateYearly && localDate.getMonthValue() == 1) {
from = localDate.minusYears(1);
from = localDate.minusYears(1).withDayOfMonth(1);
startDate = Date.from(from.atStartOfDay().toInstant(ZoneOffset.UTC));
generateReportByTimeRange(mediacenter, startDate, endDate, ReportType.Yearly);
}

if (generateQuaternary && List.of(1, 4, 7, 10).contains(localDate.getMonthValue())) {
from = localDate.minusMonths(3);
if (generateQuarterly && List.of(1, 4, 7, 10).contains(localDate.getMonthValue())) {
from = lastMonth.withMonth(lastMonth.getMonth().firstMonthOfQuarter().getValue())
.withDayOfMonth(1);

startDate = Date.from(from.atStartOfDay().toInstant(ZoneOffset.UTC));
generateReportByTimeRange(mediacenter, startDate, endDate, ReportType.Quarterly);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import lombok.extern.slf4j.Slf4j;
import org.alfresco.repo.security.authentication.AuthenticationUtil;
import org.alfresco.service.cmr.repository.InvalidNodeRefException;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.StoreRef;
import org.apache.commons.lang3.NotImplementedException;
import org.apache.commons.lang3.StringUtils;
Expand All @@ -30,9 +29,7 @@
import java.io.ByteArrayOutputStream;
import java.io.OutputStreamWriter;
import java.nio.charset.StandardCharsets;
import java.time.LocalDate;
import java.time.ZoneId;
import java.time.ZoneOffset;
import java.time.*;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -62,11 +59,11 @@ enum TrackingMode {
}

public enum ReportType {
@JobFieldDescription(description = "The job will generate a monthly report (only on 1st of January, April, July and October)")
@JobFieldDescription(description = "The job will generate a monthly report (beginning from the 1st of the month)")
Monthly,
@JobFieldDescription(description = "The job will generate a quaternary report (only on 1st of January, April, July and October)")
@JobFieldDescription(description = "The job will generate a quaternary report (beginning from the 1st day of the quartal)")
Quarterly,
@JobFieldDescription(description = "The job will generate a yearly report (only on 1st of January)")
@JobFieldDescription(description = "The job will generate a yearly report (beginning from 1st of January)")
Yearly,
}

Expand All @@ -89,7 +86,7 @@ public enum ReportType {
@JobFieldDescription(description = "List of grouped (custom) fields to be fetched from the tracking data", sampleValue = "field1")
private List<String> groupFields = Collections.emptyList();

@JobFieldDescription(description = "use a custom date (month) to run the job for. Note: The job will run the month BEFORE the given date!", sampleValue = "YYYY-MM-DD")
@JobFieldDescription(description = "use a custom date (month) to run the job for. Note: The job will run to the given date from the first of the given month, quartal or year!", sampleValue = "YYYY-MM-DD")
private Date customDate = null;

@JobFieldDescription(description = "Defines the reporting period", sampleValue = "Monthly")
Expand All @@ -109,6 +106,9 @@ public enum ReportType {
@JobFieldDescription(description = "List of aspects to filter by", sampleValue = "[]")
private List<String> aspectFilters = Collections.emptyList();

@JobFieldDescription(description = "force run, even if the date is currently not the 1st")
private boolean force = false;

@Autowired
private TrackingService trackingService;

Expand All @@ -119,7 +119,7 @@ public enum ReportType {
@Override
protected void executeInternal(JobExecutionContext jobExecutionContext) throws JobExecutionException {
LocalDate now = LocalDate.now();
if (customDate == null && now.getDayOfMonth() != 1) {
if (!force && now.getDayOfMonth() != 1) {
logger.error("Job not running because of date: " + now.getDayOfMonth());
return;
}
Expand All @@ -128,22 +128,22 @@ protected void executeInternal(JobExecutionContext jobExecutionContext) throws J
}

private Void createStats() {
LocalDate to = LocalDate.now();
if (this.customDate != null) {
LocalDate now = LocalDate.now();
LocalDate to = now.minusDays(1);

if (customDate != null) {
to = customDate.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
}
to = to.minusDays(1);

LocalDate from;
LocalDate from = to.withDayOfMonth(1);
switch (type) {
case Monthly:
from = to.minusMonths(1).plusDays(1);
break;
case Yearly:
from = to.minusYears(1).minusMonths(1).plusDays(1);
from = from.withMonth(1);
break;
case Quarterly:
from = to.minusMonths(3).plusDays(1);
from = from.withMonth(from.getMonth().firstMonthOfQuarter().getValue());
break;
default:
throw new NotImplementedException(type.name());
Expand All @@ -154,7 +154,7 @@ private Void createStats() {
List<StatisticEntryNode> nodeStatisics = trackingService.getNodeStatisics(
TrackingService.GroupingType.Node,
Date.from(from.atStartOfDay().toInstant(ZoneOffset.UTC)),
Date.from(to.atStartOfDay().toInstant(ZoneOffset.UTC)),
Date.from(to.plusDays(1).atStartOfDay().toInstant(ZoneOffset.UTC)),
"",
additionalFields,
groupFields,
Expand Down Expand Up @@ -198,19 +198,29 @@ private String generateFilename(LocalDate from, LocalDate to) {
switch (type) {
case Yearly:
sb.append(from.format(DateTimeFormatter.ofPattern(("yyyy"))));
if(to.getMonthValue() != 12 && to.getDayOfMonth() != to.lengthOfMonth()){
sb.append("_interim");
}
break;
case Quarterly:
sb.append(from.format(DateTimeFormatter.ofPattern(("yyyy"))));
sb.append("-Q");
sb.append(to.getMonthValue()/3);
sb.append(to.getMonthValue() / 3);
if(to.getMonth().firstMonthOfQuarter().getValue() + 3 != to.getMonthValue() && to.getDayOfMonth() != to.lengthOfMonth()){
sb.append("_interim");
}
break;
case Monthly:
sb.append(from.format(DateTimeFormatter.ofPattern(("yyyy-MM"))));
if(to.getDayOfMonth() != to.lengthOfMonth()){
sb.append("_interim");
}
break;
default:
throw new NotImplementedException(type.name());
}
}

sb.append(".csv");
return sb.toString();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,71 +1,21 @@
package org.edu_sharing.repository.server.jobs.quartz;


import org.alfresco.repo.security.authentication.AuthenticationUtil;
import org.alfresco.repo.transaction.RetryingTransactionHelper;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.StoreRef;
import org.alfresco.service.cmr.security.PermissionService;
import org.edu_sharing.repository.server.jobs.quartz.annotation.JobDescription;
import org.edu_sharing.service.permission.TimedPermission;
import org.edu_sharing.service.permission.TimedPermissionMapper;
import org.edu_sharing.service.permission.PermissionService;
import org.quartz.JobExecutionContext;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.Date;
import java.util.List;

@JobDescription(description = "")
@JobDescription(description = "Updates permission of timed permissions")
@SuppressWarnings("SpringJavaInjectionPointsAutowiringInspection")
public class TimedPermissionJob extends AbstractInterruptableJob {

@Autowired
private TimedPermissionMapper timedPermissionMapper;

@Autowired
private PermissionService permissionService;

@Autowired
private RetryingTransactionHelper retryingTransactionHelper;

@Override
protected void executeInterruptable(JobExecutionContext jobExecutionContext) {

List<TimedPermission> permissionsToAdd = timedPermissionMapper.findAllByFromAfterAndNotActivated(new Date());
List<TimedPermission> permissionsToRemove = timedPermissionMapper.findAllByToBefore(new Date());


for (TimedPermission timedPermission : permissionsToAdd) {
retryingTransactionHelper.doInTransaction(() ->
AuthenticationUtil.runAsSystem(() -> {
permissionService.setPermission(
new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, timedPermission.getNode_id()),
timedPermission.getAuthority(),
timedPermission.getPermission(),
true);

if(timedPermission.getTo() == null){
timedPermissionMapper.delete(timedPermission);
}else {
timedPermission.setActivated(true);
timedPermissionMapper.save(timedPermission);
}
return null;
}));
}

for (TimedPermission timedPermission : permissionsToRemove) {
retryingTransactionHelper.doInTransaction(() ->
AuthenticationUtil.runAsSystem(() -> {
permissionService.deletePermission(
new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, timedPermission.getNode_id()),
timedPermission.getAuthority(),
timedPermission.getPermission());

timedPermissionMapper.delete(timedPermission);
return null;
}));
}


permissionService.updateTimedPermissions();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import org.edu_sharing.repository.client.rpc.User;
import org.edu_sharing.repository.client.tools.CCConstants;
import org.edu_sharing.repository.client.tools.metadata.ValueTool;
import org.edu_sharing.repository.server.AuthenticationToolAPI;
import org.edu_sharing.repository.server.MCAlfrescoAPIClient;
import org.edu_sharing.repository.server.SearchResultNodeRef;
import org.edu_sharing.repository.server.tools.*;
Expand All @@ -40,8 +39,8 @@
import org.edu_sharing.restservices.shared.NodeRef;
import org.edu_sharing.restservices.shared.*;
import org.edu_sharing.restservices.shared.NodeSearch.Facet;
import org.edu_sharing.restservices.shared.NodeSearch.Facet.Value;
import org.edu_sharing.restservices.shared.SearchResult;
import org.edu_sharing.restservices.shared.NodeSearch.Facet.Value;
import org.edu_sharing.service.InsufficientPermissionException;
import org.edu_sharing.service.authority.AuthorityService;
import org.edu_sharing.service.authority.AuthorityServiceFactory;
Expand Down Expand Up @@ -1083,7 +1082,7 @@ public NodeDao createChildByCopy(String sourceId, boolean withChildren)

try {
org.alfresco.service.cmr.repository.NodeRef newNode = nodeService.copyNode(sourceId, nodeId, withChildren);
permissionService.createNotifyObject(newNode.getId(), new AuthenticationToolAPI().getCurrentUser(), CCConstants.CCM_VALUE_NOTIFY_ACTION_PERMISSION_ADD);
permissionService.createNotifyObject(newNode.getId(),AuthenticationUtil.getFullyAuthenticatedUser(), CCConstants.CCM_VALUE_NOTIFY_ACTION_PERMISSION_ADD);
return new NodeDao(repoDao, newNode.getId(), Filter.createShowAllFilter());

} catch (Throwable t) {
Expand Down Expand Up @@ -1469,7 +1468,10 @@ public <T extends Node> void fillNodeObject(T data, boolean fillOwner, boolean f
data.setAccess(access);
// set access effective for original elements only
if (!(data instanceof CollectionReference) && Objects.equals(CallSourceHelper.CallSource.Render, CallSourceHelper.getCallSource())) {
List<String> permissions = org.edu_sharing.service.nodeservice.NodeServiceInterceptor.getIndirectPermissions(getId(), List.of(DAO_PERMISSIONS));
java.util.Collection<String> permissions = org.edu_sharing.service.nodeservice.NodeServiceInterceptor.getIndirectPermissions(getId(), List.of(DAO_PERMISSIONS));
// since it's an original: we join the permissions with the original ones
permissions = new HashSet<>(permissions);
permissions.addAll(access);
data.setAccessEffective(permissions);
}
data.setPublic(isPublic);
Expand Down Expand Up @@ -2711,7 +2713,7 @@ public NodeDao createFork(String sourceId) throws DAOException {
RunAsWork<NodeDao> work = () -> {
try {
org.alfresco.service.cmr.repository.NodeRef newNode = nodeService.copyNode(source[0], nodeId, false);
permissionService.createNotifyObject(newNode.getId(), new AuthenticationToolAPI().getCurrentUser(), CCConstants.CCM_VALUE_NOTIFY_ACTION_PERMISSION_ADD);
permissionService.createNotifyObject(newNode.getId(),AuthenticationUtil.getFullyAuthenticatedUser(), CCConstants.CCM_VALUE_NOTIFY_ACTION_PERMISSION_ADD);
nodeService.addAspect(newNode.getId(), CCConstants.CCM_ASPECT_FORKED);
nodeService.setProperty(newNode.getStoreRef().getProtocol(), newNode.getStoreRef().getIdentifier(), newNode.getId(), CCConstants.CCM_PROP_FORKED_ORIGIN,
new org.alfresco.service.cmr.repository.NodeRef(storeProtocol, storeId, source[0]), false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
import org.edu_sharing.metadataset.v2.tools.MetadataHelper;
import org.edu_sharing.repository.client.tools.CCConstants;
import org.edu_sharing.repository.server.SearchResultNodeRef;
import org.edu_sharing.restservices.CollectionDao;
import org.edu_sharing.service.authority.AuthorityServiceFactory;
import org.edu_sharing.service.authority.AuthorityServiceHelper;
import org.edu_sharing.service.search.SearchService;
import org.edu_sharing.service.search.SearchServiceElastic;
Expand Down Expand Up @@ -139,6 +141,12 @@ protected SearchResultNodeRef searchChildren(String scope, SortDefinition sortDe
token.setSortDefinition(sortDefinition);
token.setFrom(skipCount);
token.setMaxResult(maxItems);
if(CollectionDao.SearchScope.valueOf(scope).equals(CollectionDao.SearchScope.EDU_GROUPS)) {
ArrayList<String> authorities = new ArrayList<>(serviceRegistry.getAuthorityService().getAuthorities());
authorities.add(serviceRegistry.getAuthenticationService().getCurrentUserName());
authorities.remove(CCConstants.AUTHORITY_GROUP_EVERYONE);
token.setAuthorityScope(authorities);
}
SearchResultNodeRef nodeRefs = SearchServiceFactory.getLocalService().search(mds, queryId, Collections.emptyMap(), token);
for (org.edu_sharing.service.model.NodeRef nodeRef : nodeRefs.getData()) {
if (isSubCollection(nodeRef)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@ public List<Context> getAvailableContext() throws Exception {

private void buildContextCache() throws Exception {
if (contextCache.getKeys().isEmpty()) {
// put an element so that next time, the cache is never empty!
contextCache.put("", null);
Config config = getConfig();
if (config.contexts != null && config.contexts.context != null) {
for (Context context : config.contexts.context) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
package org.edu_sharing.service.permission;

import java.util.*;

import org.alfresco.service.cmr.repository.NodeRef;
import org.edu_sharing.repository.client.rpc.ACE;
import org.edu_sharing.repository.client.rpc.ACL;
import org.edu_sharing.repository.client.rpc.Authority;
import org.edu_sharing.repository.client.rpc.Group;
import org.edu_sharing.repository.client.rpc.Notify;
import org.edu_sharing.repository.client.rpc.Result;
import org.edu_sharing.repository.client.rpc.User;
import org.edu_sharing.repository.client.rpc.*;
import org.edu_sharing.repository.client.tools.CCConstants;
import org.edu_sharing.service.InsufficientPermissionException;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Map;

public interface PermissionService {
public static final String[] GUEST_PERMISSIONS = new String[]{ org.alfresco.service.cmr.security.PermissionService.READ,CCConstants.PERMISSION_READ_PREVIEW,CCConstants.PERMISSION_READ_ALL, CCConstants.PERMISSION_DOWNLOAD_CONTENT, CCConstants.PERMISSION_FEEDBACK};


void updateTimedPermissions();

/**
* adds permissions to the current ACL
* @param _nodeId
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
package org.edu_sharing.service.permission;

import java.util.*;

import org.alfresco.service.cmr.repository.NodeRef;
import org.edu_sharing.repository.client.rpc.ACE;
import org.edu_sharing.repository.client.rpc.ACL;
import org.edu_sharing.repository.client.rpc.Authority;
import org.edu_sharing.repository.client.rpc.Group;
import org.edu_sharing.repository.client.rpc.Notify;
import org.edu_sharing.repository.client.rpc.Result;
import org.edu_sharing.repository.client.rpc.User;
import org.edu_sharing.repository.client.rpc.*;
import org.edu_sharing.service.InsufficientPermissionException;

import java.util.Collection;
import java.util.*;

public class PermissionServiceAdapter implements PermissionService {

protected List<String> ALLOWED_PERMISSIONS=new ArrayList<>();


@Override
public void updateTimedPermissions() {

}

@Override
public void addPermissions(String _nodeId, Map<String, String[]> _authPerm, Boolean _inheritPermissions,
String _mailText, Boolean _sendMail, Boolean _sendCopy) throws Throwable {
Expand Down
Loading

0 comments on commit e01e766

Please sign in to comment.