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.rights;
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.TraversableSource;
024
025import org.ametys.cms.ObservationConstants;
026import org.ametys.core.ui.ClientSideElement;
027import org.ametys.core.ui.right.ProfileAssignmentsToolClientSideElement;
028import org.ametys.core.user.UserIdentity;
029import org.ametys.plugins.extraction.execution.ExtractionDAO;
030
031/**
032 * {@link ClientSideElement} for the tool displaying the profile assignments for queries
033 */
034public class ExtractionProfileAssignmentsToolClientSideElement extends ProfileAssignmentsToolClientSideElement
035{
036
037    /** The query DAO */
038    private ExtractionDAO _extractionDAO;
039    
040    @Override
041    public void service(ServiceManager smanager) throws ServiceException
042    {
043        super.service(smanager);
044        _extractionDAO = (ExtractionDAO) smanager.lookup(ExtractionDAO.ROLE);
045    }
046    
047    @Override
048    protected Map<String, Object> _getEventParams(Object context, String contextIdentifier, Set<String> profileIds)
049    {
050        Map<String, Object> eventParams = super._getEventParams(context, contextIdentifier, profileIds);
051        eventParams.put(ObservationConstants.ARGS_ACL_SOLR_CACHE_UNINFLUENTIAL, true);
052        return eventParams;
053    }
054    
055    @Override
056    protected boolean hasRight(Map<String, String> rights, Object context)
057    {
058        try
059        {
060            UserIdentity user = _currentUserProvider.getUser();
061            TraversableSource source = _extractionDAO.getExtractionSource((String) context);
062            return _extractionDAO.canAssignRights(user, source);
063        }
064        catch (Exception e)
065        {
066            getLogger().error("Error while reading extraction file or container with following path: " + context);
067        }
068        return false;
069    }
070}