1 43 package net.jforum.view.admin; 44 45 import java.util.ArrayList ; 46 import java.util.List ; 47 48 import net.jforum.dao.DataAccessDriver; 49 import net.jforum.dao.GroupDAO; 50 import net.jforum.dao.security.GroupSecurityDAO; 51 import net.jforum.entities.Group; 52 import net.jforum.repository.ForumRepository; 53 import net.jforum.repository.RolesRepository; 54 import net.jforum.repository.SecurityRepository; 55 import net.jforum.security.PermissionControl; 56 import net.jforum.security.XMLPermissionControl; 57 import net.jforum.util.I18n; 58 import net.jforum.util.TreeGroup; 59 import net.jforum.util.preferences.ConfigKeys; 60 import net.jforum.util.preferences.SystemGlobals; 61 import net.jforum.util.preferences.TemplateKeys; 62 63 69 public class GroupAction extends AdminCommand 70 { 71 public void list() throws Exception 73 { 74 this.context.put("groups", new TreeGroup().getNodes()); 75 this.setTemplateName(TemplateKeys.GROUP_LIST); 76 } 77 78 public void insert() throws Exception 80 { 81 this.context.put("groups", new TreeGroup().getNodes()); 82 this.context.put("action", "insertSave"); 83 this.context.put("selectedList", new ArrayList ()); 84 this.setTemplateName(TemplateKeys.GROUP_INSERT); 85 } 86 87 public void editSave() throws Exception 89 { 90 int groupId = this.request.getIntParameter("group_id"); 91 92 Group g = new Group(); 93 g.setDescription(this.request.getParameter("group_description")); 94 g.setId(groupId); 95 96 int parentId = this.request.getIntParameter("parent_id"); 97 98 if (parentId == g.getId()) { 99 parentId = 0; 100 } 101 102 g.setParentId(parentId); 103 g.setName(this.request.getParameter("group_name")); 104 105 DataAccessDriver.getInstance().newGroupDAO().update(g); 106 107 this.list(); 108 } 109 110 public void edit() throws Exception 112 { 113 int groupId = this.request.getIntParameter("group_id"); 114 GroupDAO gm = DataAccessDriver.getInstance().newGroupDAO(); 115 116 this.setTemplateName(TemplateKeys.GROUP_EDIT); 117 118 this.context.put("group", gm.selectById(groupId)); 119 this.context.put("groups", new TreeGroup().getNodes()); 120 this.context.put("selectedList", new ArrayList ()); 121 this.context.put("action", "editSave"); 122 } 123 124 public void delete() throws Exception 126 { 127 String groupId[] = this.request.getParameterValues("group_id"); 128 129 if (groupId == null) { 130 this.list(); 131 132 return; 133 } 134 135 List errors = new ArrayList (); 136 GroupDAO gm = DataAccessDriver.getInstance().newGroupDAO(); 137 138 for (int i = 0; i < groupId.length; i++) { 139 int id = Integer.parseInt(groupId[i]); 140 141 if (gm.canDelete(id)) { 142 gm.delete(id); 143 } 144 else { 145 errors.add(I18n.getMessage(I18n.CANNOT_DELETE_GROUP, new Object [] { new Integer (id) })); 146 } 147 } 148 149 if (errors.size() > 0) { 150 this.context.put("errorMessage", errors); 151 } 152 153 this.list(); 154 } 155 156 public void insertSave() throws Exception 158 { 159 GroupDAO gm = DataAccessDriver.getInstance().newGroupDAO(); 160 161 Group g = new Group(); 162 g.setDescription(this.request.getParameter("group_description")); 163 g.setParentId(this.request.getIntParameter("parent_id")); 164 g.setName(this.request.getParameter("group_name")); 165 166 gm.addNew(g); 167 168 this.list(); 169 } 170 171 public void permissions() throws Exception 173 { 174 int id = this.request.getIntParameter("group_id"); 175 176 PermissionControl pc = new PermissionControl(); 177 pc.setRoles(DataAccessDriver.getInstance().newGroupSecurityDAO().loadRoles(id)); 178 179 List sections = new XMLPermissionControl(pc).loadConfigurations( 180 SystemGlobals.getValue(ConfigKeys.CONFIG_DIR) + "/permissions.xml"); 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() throws Exception 190 { 191 int id = this.request.getIntParameter("id"); 192 193 GroupSecurityDAO gmodel = DataAccessDriver.getInstance().newGroupSecurityDAO(); 194 195 PermissionControl pc = new PermissionControl(); 196 pc.setSecurityModel(gmodel); 197 198 new PermissionProcessHelper(pc, id, true).processData(); 199 200 SecurityRepository.clean(); 201 RolesRepository.clear(); 202 ForumRepository.clearModeratorList(); 203 204 this.list(); 205 } 206 } 207 | Popular Tags |