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.OrExpression; 024import org.ametys.plugins.repository.query.expression.StringExpression; 025import org.ametys.plugins.workspaces.ObservationConstants; 026import org.ametys.plugins.workspaces.WorkspacesConstants; 027import org.ametys.plugins.workspaces.project.objects.Project; 028import org.ametys.plugins.workspaces.project.observers.AbstractUpdateAclSorCacheObserver; 029import org.ametys.web.repository.SiteAwareAmetysObject; 030 031/** 032 * This observer reload ACL cache of catalog's and project's contents when a member is added or removed from a project 033 */ 034public class UpdateAclSolrCacheOnMemberUpdatedObserver extends AbstractUpdateAclSorCacheObserver 035{ 036 public boolean supports(Event event) 037 { 038 String eventId = event.getId(); 039 return eventId.equals(ObservationConstants.EVENT_MEMBER_ADDED) || eventId.equals(ObservationConstants.EVENT_MEMBER_DELETED) || eventId.equals(ObservationConstants.EVENT_PROJECT_UPDATED); 040 } 041 042 @Override 043 protected Expression getContentsExpression(Event event, Project project) 044 { 045 // Read access have changed for project's contents and catalog news 046 Expression siteExpression = new StringExpression(SiteAwareAmetysObject.METADATA_SITE, Operator.EQ, project.getSite().getName()); 047 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); 048 Expression projectExpr = new AndExpression(siteExpression, projectCTypesExpr); 049 050 Expression catalogCTypesExpr = new ContentTypeExpression(Operator.EQ, WorkspacesConstants.CATALOG_NEWS_CONTENT_TYPE_ID); 051 Expression catalogSiteExpr = new StringExpression(SiteAwareAmetysObject.METADATA_SITE, Operator.EQ, _projectManager.getCatalogSiteName()); 052 Expression catalogExpr = new AndExpression(catalogSiteExpr, catalogCTypesExpr); 053 054 return new OrExpression(catalogExpr, projectExpr); 055 } 056}