001/* 002 * Copyright 2021 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.extraction; 017 018import java.util.Map; 019import java.util.Set; 020 021import org.apache.avalon.framework.service.ServiceException; 022import org.apache.avalon.framework.service.ServiceManager; 023import org.apache.excalibur.source.SourceResolver; 024import org.apache.excalibur.source.TraversableSource; 025import org.apache.excalibur.source.impl.FileSource; 026 027import org.ametys.cms.ObservationConstants; 028import org.ametys.core.group.GroupIdentity; 029import org.ametys.core.ui.ClientSideElement; 030import org.ametys.core.ui.right.ProfileAssignmentsToolClientSideElement; 031import org.ametys.core.user.UserIdentity; 032import org.ametys.plugins.extraction.execution.ExtractionDAO; 033 034/** 035 * {@link ClientSideElement} for the tool displaying the profile assignments for queries 036 */ 037public class ExtractionProfileAssignmentsToolClientSideElement extends ProfileAssignmentsToolClientSideElement 038{ 039 040 /** The query DAO */ 041 private ExtractionDAO _extractionDAO; 042 private SourceResolver _sourceResolver; 043 044 @Override 045 public void service(ServiceManager smanager) throws ServiceException 046 { 047 super.service(smanager); 048 _extractionDAO = (ExtractionDAO) smanager.lookup(ExtractionDAO.ROLE); 049 _sourceResolver = (SourceResolver) smanager.lookup(SourceResolver.ROLE); 050 } 051 052 @Override 053 protected Map<String, Object> _getEventParams(Object context, String contextIdentifier, Set<String> profileIds) 054 { 055 Map<String, Object> eventParams = super._getEventParams(context, contextIdentifier, profileIds); 056 eventParams.put(ObservationConstants.ARGS_ACL_SOLR_CACHE_UNINFLUENTIAL, true); 057 return eventParams; 058 } 059 060 @Override 061 protected boolean canDelegateRights(UserIdentity user, Set<GroupIdentity> groups, String profileId, String assignment , Object context) 062 { 063 try 064 { 065 String asoluteFilePath = _extractionDAO.getExtractionAbsolutePathFromContext((String) context); 066 TraversableSource source = (TraversableSource) _sourceResolver.resolveURI(asoluteFilePath); 067 if (source.isCollection()) 068 { 069 return _extractionDAO.hasWriteRightOnExtractionContainer(user, source); 070 } 071 else 072 { 073 return _extractionDAO.hasRightAffectationRightOnExtraction(user, source, _extractionDAO.getUserIdentityByExtractionPath((FileSource) source)); 074 } 075 } 076 catch (Exception e) 077 { 078 getLogger().error("Error while reading extraction file or container with following path: " + context); 079 } 080 return super.canDelegateRights(user, groups, profileId, assignment, context); 081 } 082 083}