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.Arrays; 019import java.util.HashSet; 020import java.util.Set; 021import java.util.stream.Collectors; 022 023import org.ametys.cms.repository.Content; 024import org.ametys.core.right.AccessController; 025import org.ametys.core.user.UserIdentity; 026import org.ametys.odf.rights.ODFRightHelper.ContextualizedContent; 027 028/** 029 * {@link AccessController} for a ODF {@link ContextualizedContent} based on ODF managers role 030 * 031 */ 032public class ODFManagerForContextualizedContentAccessController extends AbstractODFRoleForContextualizedContentAccessController 033{ 034 @Override 035 protected String getTargetProfileId() 036 { 037 return _odfRightHelper.getManagerProfileId(); 038 } 039 040 @Override 041 protected Set<UserIdentity> getLocalAllowedUsers(Content content) 042 { 043 UserIdentity[] allowedUsers = _odfRightHelper.getManagers(content); 044 return allowedUsers != null ? Arrays.stream(allowedUsers).collect(Collectors.toSet()) : new HashSet<>(); 045 } 046 047 @Override 048 protected String getRoleAttributePath() 049 { 050 return ODFRightHelper.MANAGERS_FIELD_PATH; 051 } 052}