001/* 002 * Copyright 2023 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.odf.rights; 017 018import java.util.Map; 019 020import org.apache.avalon.framework.configuration.Configuration; 021import org.apache.avalon.framework.configuration.ConfigurationException; 022import org.apache.avalon.framework.service.ServiceException; 023import org.apache.avalon.framework.service.ServiceManager; 024 025import org.ametys.cms.contenttype.MetadataType; 026import org.ametys.cms.search.query.Query; 027import org.ametys.cms.search.query.Query.Operator; 028import org.ametys.cms.search.ui.model.impl.AbstractCustomSearchUICriterion; 029import org.ametys.core.user.CurrentUserProvider; 030import org.ametys.core.user.UserIdentity; 031 032/** 033 * UI criteria for program item context 034 */ 035public class ODFContributorOrManagerSearchUICriteria extends AbstractCustomSearchUICriterion 036{ 037 private ODFRightHelper _odfRightHelper; 038 private CurrentUserProvider _currentUserProvider; 039 040 @Override 041 public void service(ServiceManager smanager) throws ServiceException 042 { 043 super.service(smanager); 044 _currentUserProvider = (CurrentUserProvider) smanager.lookup(CurrentUserProvider.ROLE); 045 _odfRightHelper = (ODFRightHelper) smanager.lookup(org.ametys.odf.rights.ODFRightHelper.ROLE); 046 } 047 048 @Override 049 public void configure(Configuration configuration) throws ConfigurationException 050 { 051 super.configure(configuration); 052 053 // Hidden criteria 054 setHidden(true); 055 } 056 057 public Operator getOperator() 058 { 059 // Exists allow to always include the query in QueryBuilder 060 return Operator.EXISTS; 061 } 062 063 public String getFieldId() 064 { 065 return getId(); 066 } 067 068 @Override 069 public MetadataType getType() 070 { 071 // Not suppose to be used 072 return MetadataType.STRING; 073 } 074 075 public Query getQuery(Object value, Operator customOperator, Map<String, Object> allValues, String language, Map<String, Object> contextualParameters) 076 { 077 UserIdentity currentUser = _currentUserProvider.getUser(); 078 return _odfRightHelper.getRolesQuery(currentUser); 079 } 080}