001/*
002 *  Copyright 2015 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.web.repository.site;
017
018import java.util.ArrayList;
019import java.util.List;
020import java.util.Map;
021
022import org.apache.cocoon.environment.Request;
023
024import org.ametys.core.user.UserIdentity;
025
026/**
027 * Action for getting the list of existing {@link Site} for administrative operations.
028 */
029public class GetAdminSitesAction extends GetSitesAction
030{
031    @Override
032    protected List<Map<String, Object>> _rootSite2json(Request request, Site site, String currentSiteName, boolean recursive, boolean readAccessOnly, boolean sharedSitesOnly, UserIdentity user)
033    {
034        List<Map<String, Object>> sites = new ArrayList<>();
035        
036//        request.setAttribute("siteName", site.getName()); // Setting temporarily this attribute to check user rights on any object on this site
037//        try
038//        {
039//            if (_rightManager.hasAtLeastOneRight(user))
040//            {
041        // FIXME handle rights for workspace admin
042        if (recursive)
043        {
044            // on recursion, returns all sub sites on the same level. The real level is determined by the "depth" property 
045            sites.addAll(_childSites2json(request, site, currentSiteName, 0, readAccessOnly, sharedSitesOnly));
046        }
047        else
048        {
049            sites.add(_site2json(request, site, currentSiteName, 0, readAccessOnly, sharedSitesOnly));
050        }
051//            }
052//        }
053//        finally
054//        {
055//            request.setAttribute("siteName", null);
056//        }
057        
058        return sites;
059    }
060}
061