001/* 002 * Copyright 2025 Anyware Services 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package org.ametys.plugins.workspaces.members.observers; 017 018import org.ametys.cms.repository.ContentTypeExpression; 019import org.ametys.core.observation.Event; 020import org.ametys.plugins.repository.query.expression.AndExpression; 021import org.ametys.plugins.repository.query.expression.Expression; 022import org.ametys.plugins.repository.query.expression.Expression.Operator; 023import org.ametys.plugins.repository.query.expression.ExpressionContext; 024import org.ametys.plugins.repository.query.expression.OrExpression; 025import org.ametys.plugins.repository.query.expression.StringExpression; 026import org.ametys.plugins.workspaces.ObservationConstants; 027import org.ametys.plugins.workspaces.WorkspacesConstants; 028import org.ametys.plugins.workspaces.project.objects.Project; 029import org.ametys.plugins.workspaces.project.observers.AbstractUpdateAclSorCacheObserver; 030import org.ametys.web.repository.SiteAwareAmetysObject; 031 032/** 033 * This observer reload ACL cache of catalog's and project's contents when a member is added or removed from a project 034 */ 035public class UpdateAclSolrCacheOnMemberUpdatedObserver extends AbstractUpdateAclSorCacheObserver 036{ 037 public boolean supports(Event event) 038 { 039 String eventId = event.getId(); 040 return eventId.equals(ObservationConstants.EVENT_MEMBER_ADDED) 041 || eventId.equals(ObservationConstants.EVENT_MEMBER_JOINED) 042 || eventId.equals(ObservationConstants.EVENT_MEMBER_UPDATED) 043 || eventId.equals(ObservationConstants.EVENT_MEMBER_DELETED) 044 || eventId.equals(ObservationConstants.EVENT_PROJECT_UPDATED); 045 } 046 047 @Override 048 protected Expression getContentsExpression(Event event, Project project) 049 { 050 ExpressionContext siteExpressionContext = ExpressionContext.newInstance().withInternal(true); 051 052 // Read access have changed for project's contents and catalog news 053 Expression siteExpression = new StringExpression(SiteAwareAmetysObject.METADATA_SITE, Operator.EQ, project.getSite().getName(), siteExpressionContext); 054 Expression projectCTypesExpr = new ContentTypeExpression(Operator.EQ, WorkspacesConstants.PROJECT_ARTICLE_CONTENT_TYPE, WorkspacesConstants.WALL_CONTENT_CONTENT_TYPE_ID, WorkspacesConstants.PROJECT_ALERT_CONTENT_TYPE_ID, WorkspacesConstants.PROJECT_NEWS_CONTENT_TYPE_ID); 055 Expression projectExpr = new AndExpression(siteExpression, projectCTypesExpr); 056 057 Expression catalogCTypesExpr = new ContentTypeExpression(Operator.EQ, WorkspacesConstants.CATALOG_NEWS_CONTENT_TYPE_ID); 058 Expression catalogSiteExpr = new StringExpression(SiteAwareAmetysObject.METADATA_SITE, Operator.EQ, _projectManager.getCatalogSiteName(), siteExpressionContext); 059 Expression catalogExpr = new AndExpression(catalogSiteExpr, catalogCTypesExpr); 060 061 return new OrExpression(catalogExpr, projectExpr); 062 } 063}