001/*
002 *  Copyright 2024 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.runtime.plugins.admin.user;
017
018import java.util.List;
019import java.util.Map;
020
021import org.apache.avalon.framework.service.ServiceException;
022import org.apache.avalon.framework.service.ServiceManager;
023
024import org.ametys.core.ui.Callable;
025import org.ametys.core.ui.StaticClientSideElement;
026import org.ametys.core.user.UserIdentity;
027import org.ametys.core.user.status.UserStatusManager;
028
029/**
030 * Client side element to activate or deactivate the personal data removal process
031 */
032public class PersonalDataRemovalClientSideElement extends StaticClientSideElement
033{
034    /** The user status manager */
035    protected UserStatusManager _userStatusManager;
036    
037    @Override
038    public void service(ServiceManager smanager) throws ServiceException
039    {
040        super.service(smanager);
041        _userStatusManager = (UserStatusManager) smanager.lookup(UserStatusManager.ROLE);
042    }
043    
044    /**
045     * Activate the data removal process of a list of identities
046     * @param identitiesAsJSON the list of identities
047     * @return true if the operation succeed
048     */
049    @Callable(rights = "Runtime_Rights_Unknown_Users")
050    public List<UserIdentity> activatePersonalDataRemoval(List<Map<String, String>> identitiesAsJSON)
051    {
052        List<UserIdentity> identities = identitiesAsJSON.stream()
053            .map(json -> new UserIdentity(json.get("login"), json.get("populationId")))
054            .toList();
055        
056        _userStatusManager.activatePersonalDataRemoval(identities);
057        return identities;
058    }
059    
060    /**
061     * Deactivate the data removal process of a list of identities
062     * @param identitiesAsJSON the list of identities
063     * @return true if the operation succeed
064     */
065    @Callable(rights = "Runtime_Rights_Unknown_Users")
066    public List<UserIdentity> deactivatePersonalDataRemoval(List<Map<String, String>> identitiesAsJSON)
067    {
068        List<UserIdentity> identities = identitiesAsJSON.stream()
069                .map(json -> new UserIdentity(json.get("login"), json.get("populationId")))
070                .toList();
071        
072        _userStatusManager.deactivatePersonalDataRemoval(identities);
073        return identities;
074    }
075
076}