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.core.ui.right.profile; 017 018import java.util.ArrayList; 019import java.util.List; 020import java.util.Map; 021 022import org.ametys.core.right.RightManager.RightResult; 023import org.ametys.core.ui.ClientSideElementHelper; 024import org.ametys.core.ui.StaticClientSideElement; 025 026/** 027 * Client side element for the profile tools 028 */ 029public class ProfileToolsClientSideElement extends StaticClientSideElement 030{ 031 @Override 032 public List<Script> getScripts(boolean ignoreRights, Map<String, Object> contextParameters) 033 { 034 List<Script> scripts = super.getScripts(ignoreRights, contextParameters); 035 if (scripts == null) 036 { 037 return null; 038 } 039 040 if (_rightManager.currentUserHasRight("Runtime_Rights_Rights_Profile_Handle", "/admin") != RightResult.RIGHT_ALLOW) 041 { 042 return scripts; 043 } 044 045 // The user has the right to handle profiles on /admin (and not only on its workspace... so it will be allowed to edit shared profiles 046 047 List<Script> modifiedScripts = new ArrayList<>(); 048 049 for (Script originalScript : scripts) 050 { 051 Script clonedScript = ClientSideElementHelper.cloneScript(originalScript); 052 053 clonedScript.getParameters().put("canEditAnyContext", "true"); 054 055 modifiedScripts.add(clonedScript); 056 } 057 058 return modifiedScripts; 059 } 060}