View Javadoc
1   /**
2    * This file Copyright (c) 2013-2015 Magnolia International
3    * Ltd.  (http://www.magnolia-cms.com). All rights reserved.
4    *
5    *
6    * This file is dual-licensed under both the Magnolia
7    * Network Agreement and the GNU General Public License.
8    * You may elect to use one or the other of these licenses.
9    *
10   * This file is distributed in the hope that it will be
11   * useful, but AS-IS and WITHOUT ANY WARRANTY; without even the
12   * implied warranty of MERCHANTABILITY or FITNESS FOR A
13   * PARTICULAR PURPOSE, TITLE, or NONINFRINGEMENT.
14   * Redistribution, except as permitted by whichever of the GPL
15   * or MNA you select, is prohibited.
16   *
17   * 1. For the GPL license (GPL), you can redistribute and/or
18   * modify this file under the terms of the GNU General
19   * Public License, Version 3, as published by the Free Software
20   * Foundation.  You should have received a copy of the GNU
21   * General Public License, Version 3 along with this program;
22   * if not, write to the Free Software Foundation, Inc., 51
23   * Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
24   *
25   * 2. For the Magnolia Network Agreement (MNA), this file
26   * and the accompanying materials are made available under the
27   * terms of the MNA which accompanies this distribution, and
28   * is available at http://www.magnolia-cms.com/mna.html
29   *
30   * Any modifications to this file must keep this entire header
31   * intact.
32   *
33   */
34  package info.magnolia.security.app.action;
35  
36  import info.magnolia.cms.security.Group;
37  import info.magnolia.cms.security.Security;
38  import info.magnolia.cms.security.SecuritySupport;
39  import info.magnolia.cms.security.User;
40  import info.magnolia.commands.CommandsManager;
41  import info.magnolia.event.EventBus;
42  import info.magnolia.i18nsystem.SimpleTranslator;
43  import info.magnolia.objectfactory.Components;
44  import info.magnolia.ui.api.context.UiContext;
45  import info.magnolia.ui.api.event.AdmincentralEventBus;
46  import info.magnolia.ui.vaadin.integration.jcr.JcrItemAdapter;
47  
48  import java.util.Collection;
49  
50  import javax.inject.Inject;
51  import javax.inject.Named;
52  
53  /**
54   * Deletes a group after performing a check that the group is not assigned to any user or another group.
55   */
56  public class DeleteGroupAction extends AbstractDeleteGroupOrRoleAction<DeleteGroupActionDefinition> {
57  
58      @Inject
59      public DeleteGroupAction(DeleteGroupActionDefinition definition, JcrItemAdapter item, CommandsManager commandsManager, @Named(AdmincentralEventBus.NAME) EventBus eventBus, UiContext uiContext, SimpleTranslator i18n, SecuritySupport securitySupport) {
60          super(definition, item, commandsManager, eventBus, uiContext, i18n, securitySupport);
61      }
62  
63      /**
64       * @deprecated since 5.3.6 instead of use {@link #DeleteGroupAction(DeleteGroupActionDefinition, info.magnolia.ui.vaadin.integration.jcr.JcrItemAdapter, info.magnolia.commands.CommandsManager, info.magnolia.event.EventBus, info.magnolia.ui.api.context.UiContext, info.magnolia.i18nsystem.SimpleTranslator, info.magnolia.cms.security.SecuritySupport)}
65       */
66      @Deprecated
67      public DeleteGroupAction(DeleteGroupActionDefinition definition, JcrItemAdapter item, CommandsManager commandsManager, @Named(AdmincentralEventBus.NAME) EventBus eventBus, UiContext uiContext, SimpleTranslator i18n) {
68          super(definition, item, commandsManager, eventBus, uiContext, i18n, Security.getSecuritySupport());
69      }
70  
71      /**
72       * @deprecated since 5.2.2 instead of use {@link #DeleteGroupAction(DeleteGroupActionDefinition, info.magnolia.ui.vaadin.integration.jcr.JcrItemAdapter, info.magnolia.commands.CommandsManager, info.magnolia.event.EventBus, info.magnolia.ui.api.context.UiContext, info.magnolia.i18nsystem.SimpleTranslator)}
73       */
74      @Deprecated
75      public DeleteGroupAction(DeleteGroupActionDefinition definition, JcrItemAdapter item, @Named(AdmincentralEventBus.NAME) EventBus eventBus, UiContext uiContext, SimpleTranslator i18n) {
76          this(definition, item, Components.getComponent(CommandsManager.class), eventBus, uiContext, i18n);
77      }
78  
79      @Override
80      protected Collection<String> getGroupsOrRoles(User user) {
81          return user.getGroups();
82      }
83  
84      @Override
85      protected Collection<String> getGroupsOrRoles(Group group) {
86          return group.getGroups();
87      }
88  
89      @Override
90      protected Collection<String> getUsersWithGroupOrRoleToDelete(final String groupOrRole) {
91          return getSecuritySupport().getUserManager().getUsersWithGroup(groupOrRole);
92      }
93  
94      @Override
95      protected Collection<String> getGroupsWithGroupOrRoleToDelete(final String groupOrRole) {
96          return getSecuritySupport().getGroupManager().getGroupsWithGroup(groupOrRole);
97      }
98  
99      @Override
100     protected String getConfirmationDialogTitle() {
101         return getI18n().translate("security.groups.actions.confirmDeleteGroup.confirmationHeader");
102     }
103 
104     @Override
105     protected String getConfirmationDialogBody() {
106         return getI18n().translate("security.groups.actions.confirmDeleteGroup.confirmationMessage");
107     }
108 
109     @Override
110     protected String getConfirmationDialogProceedLabel() {
111         return getI18n().translate("security.groups.actions.confirmDeleteGroup.proceedLabel");
112     }
113 
114     @Override
115     protected String getConfirmationDialogCancelLabel() {
116         return getI18n().translate("security.groups.actions.confirmDeleteGroup.cancelLabel");
117     }
118 
119     @Override
120     protected String getBaseErrorMessage() {
121         return getI18n().translate("security.delete.group.isAssignedError");
122     }
123 
124     @Override
125     protected String getVerificationErrorMessage() {
126         return getI18n().translate("security.delete.group.cannotVerifyError");
127     }
128 }