001: /*
002: * Copyright (c) JForum Team
003: * All rights reserved.
004: *
005: * Redistribution and use in source and binary forms,
006: * with or without modification, are permitted provided
007: * that the following conditions are met:
008: *
009: * 1) Redistributions of source code must retain the above
010: * copyright notice, this list of conditions and the
011: * following disclaimer.
012: * 2) Redistributions in binary form must reproduce the
013: * above copyright notice, this list of conditions and
014: * the following disclaimer in the documentation and/or
015: * other materials provided with the distribution.
016: * 3) Neither the name of "Rafael Steil" nor
017: * the names of its contributors may be used to endorse
018: * or promote products derived from this software without
019: * specific prior written permission.
020: *
021: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT
022: * HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
023: * EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
024: * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
025: * MERCHANTABILITY AND FITNESS FOR A PARTICULAR
026: * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
027: * THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
028: * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
029: * EXEMPLARY, OR CONSEQUENTIAL DAMAGES
030: * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
031: * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
032: * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
033: * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
034: * IN CONTRACT, STRICT LIABILITY, OR TORT
035: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
036: * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
037: * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
038: *
039: * This file creation date: Mar 3, 2003 / 11:07:02 AM
040: * The JForum Project
041: * http://www.jforum.net
042: */
043: package net.jforum.view.admin;
044:
045: import java.util.ArrayList;
046: import java.util.List;
047:
048: import net.jforum.dao.DataAccessDriver;
049: import net.jforum.dao.GroupDAO;
050: import net.jforum.dao.GroupSecurityDAO;
051: import net.jforum.entities.Group;
052: import net.jforum.repository.ForumRepository;
053: import net.jforum.repository.RolesRepository;
054: import net.jforum.repository.SecurityRepository;
055: import net.jforum.security.PermissionControl;
056: import net.jforum.security.XMLPermissionControl;
057: import net.jforum.util.I18n;
058: import net.jforum.util.TreeGroup;
059: import net.jforum.util.preferences.ConfigKeys;
060: import net.jforum.util.preferences.SystemGlobals;
061: import net.jforum.util.preferences.TemplateKeys;
062:
063: /**
064: * ViewHelper class for group administration.
065: *
066: * @author Rafael Steil
067: * @version $Id: GroupAction.java,v 1.24 2007/09/21 03:47:40 rafaelsteil Exp $
068: */
069: public class GroupAction extends AdminCommand {
070: // Listing
071: public void list() {
072: this .context.put("groups", new TreeGroup().getNodes());
073: this .setTemplateName(TemplateKeys.GROUP_LIST);
074: }
075:
076: // Insert
077: public void insert() {
078: this .context.put("groups", new TreeGroup().getNodes());
079: this .context.put("action", "insertSave");
080: this .context.put("selectedList", new ArrayList());
081: this .setTemplateName(TemplateKeys.GROUP_INSERT);
082: }
083:
084: // Save information for an existing group
085: public void editSave() {
086: int groupId = this .request.getIntParameter("group_id");
087:
088: Group g = new Group();
089: g
090: .setDescription(this .request
091: .getParameter("group_description"));
092: g.setId(groupId);
093:
094: int parentId = this .request.getIntParameter("parent_id");
095:
096: if (parentId == g.getId()) {
097: parentId = 0;
098: }
099:
100: g.setParentId(parentId);
101: g.setName(this .request.getParameter("group_name"));
102:
103: DataAccessDriver.getInstance().newGroupDAO().update(g);
104:
105: this .list();
106: }
107:
108: // Edit a group
109: public void edit() {
110: int groupId = this .request.getIntParameter("group_id");
111: GroupDAO gm = DataAccessDriver.getInstance().newGroupDAO();
112:
113: this .setTemplateName(TemplateKeys.GROUP_EDIT);
114:
115: this .context.put("group", gm.selectById(groupId));
116: this .context.put("groups", new TreeGroup().getNodes());
117: this .context.put("selectedList", new ArrayList());
118: this .context.put("action", "editSave");
119: }
120:
121: // Deletes a group
122: public void delete() {
123: String groupId[] = this .request.getParameterValues("group_id");
124:
125: if (groupId == null) {
126: this .list();
127:
128: return;
129: }
130:
131: List errors = new ArrayList();
132: GroupDAO gm = DataAccessDriver.getInstance().newGroupDAO();
133:
134: for (int i = 0; i < groupId.length; i++) {
135: int id = Integer.parseInt(groupId[i]);
136:
137: if (gm.canDelete(id)) {
138: gm.delete(id);
139: } else {
140: errors.add(I18n.getMessage(I18n.CANNOT_DELETE_GROUP,
141: new Object[] { new Integer(id) }));
142: }
143: }
144:
145: if (errors.size() > 0) {
146: this .context.put("errorMessage", errors);
147: }
148:
149: this .list();
150: }
151:
152: // Saves a new group
153: public void insertSave() {
154: GroupDAO gm = DataAccessDriver.getInstance().newGroupDAO();
155:
156: Group g = new Group();
157: g
158: .setDescription(this .request
159: .getParameter("group_description"));
160: g.setParentId(this .request.getIntParameter("parent_id"));
161: g.setName(this .request.getParameter("group_name"));
162:
163: gm.addNew(g);
164:
165: this .list();
166: }
167:
168: // Permissions
169: public void permissions() {
170: int id = this .request.getIntParameter("group_id");
171:
172: PermissionControl pc = new PermissionControl();
173: pc.setRoles(DataAccessDriver.getInstance()
174: .newGroupSecurityDAO().loadRoles(id));
175:
176: String xmlconfig = SystemGlobals
177: .getValue(ConfigKeys.CONFIG_DIR)
178: + "/permissions.xml";
179: List sections = new XMLPermissionControl(pc)
180: .loadConfigurations(xmlconfig);
181:
182: GroupDAO gm = DataAccessDriver.getInstance().newGroupDAO();
183:
184: this .context.put("sections", sections);
185: this .context.put("group", gm.selectById(id));
186: this .setTemplateName(TemplateKeys.GROUP_PERMISSIONS);
187: }
188:
189: public void permissionsSave() {
190: int id = this .request.getIntParameter("id");
191:
192: GroupSecurityDAO gmodel = DataAccessDriver.getInstance()
193: .newGroupSecurityDAO();
194:
195: PermissionControl pc = new PermissionControl();
196: pc.setSecurityModel(gmodel);
197:
198: new PermissionProcessHelper(pc, id).processData();
199:
200: SecurityRepository.clean();
201: RolesRepository.clear();
202: ForumRepository.clearModeratorList();
203:
204: this.list();
205: }
206: }
|