1 package org.tigris.scarab.actions; 2 3 48 49 import java.util.List ; 51 52 import org.apache.fulcrum.intake.model.Group; 53 import org.apache.fulcrum.parser.ParameterParser; 54 import org.apache.fulcrum.security.TurbineSecurity; 55 import org.apache.torque.oid.IDBroker; 56 import org.apache.torque.util.BasePeer; 57 import org.apache.turbine.RunData; 58 import org.apache.turbine.TemplateContext; 59 import org.apache.turbine.tool.IntakeTool; 60 import org.tigris.scarab.actions.base.RequireLoginFirstAction; 61 import org.tigris.scarab.om.GlobalParameter; 62 import org.tigris.scarab.om.GlobalParameterManager; 63 import org.tigris.scarab.om.Issue; 64 import org.tigris.scarab.om.Module; 65 import org.tigris.scarab.om.ModuleManager; 66 import org.tigris.scarab.om.ScarabModule; 67 import org.tigris.scarab.om.ScarabUser; 68 import org.tigris.scarab.services.security.ScarabSecurity; 69 import org.tigris.scarab.tools.ScarabLocalizationTool; 70 import org.tigris.scarab.tools.ScarabRequestTool; 71 import org.tigris.scarab.tools.localization.L10NKeySet; 72 import org.tigris.scarab.util.Log; 73 74 80 public class ModifyModule extends RequireLoginFirstAction 81 { 82 private static final String [] EMAIL_PARAMS = 83 {GlobalParameter.EMAIL_ENABLED, 84 GlobalParameter.EMAIL_INCLUDE_ISSUE_DETAILS}; 85 86 89 public void doUpdate(RunData data, TemplateContext context) 90 throws Exception 91 { 92 String template = getCurrentTemplate(data, null); 93 String nextTemplate = getNextTemplate(data, template); 94 95 ScarabLocalizationTool l10n = getLocalizationTool(context); 96 IntakeTool intake = getIntakeTool(context); 97 ScarabRequestTool scarabR = getScarabRequestTool(context); 98 99 if (intake.isAllValid()) 100 { 101 Module me = null; 102 try 103 { 104 me = scarabR.getModule(); 105 } 106 catch (Exception e) 107 { 108 throw new Exception ("Could not locate module"); } 110 111 Group moduleGroup = intake.get 112 ("Module",me.getQueryKey(), false); 113 if (moduleGroup == null) 114 { 115 setTarget(data, template); 116 scarabR.setAlertMessage( 117 L10NKeySet.CouldNotLocateModuleGroup); 118 return; 119 } 120 else 121 { 122 ScarabUser user = (ScarabUser) data.getUser(); 123 124 if (!user.hasPermission(ScarabSecurity.MODULE__EDIT, me)) 127 { 128 scarabR.setAlertMessage(NO_PERMISSION_MESSAGE); 129 intake.remove(moduleGroup); 130 setTarget(data, nextTemplate); 131 return; 132 } 133 134 Module origParent = me.getParent(); 135 String origCode = me.getCode(); 136 moduleGroup.setProperties(me); 137 Module newParent = me.getParent(); 138 String newCode = me.getCode(); 139 140 if (newParent.getParent() == me && origParent!=me) 141 { 142 scarabR.setAlertMessage(L10NKeySet.CircularParentChildRelationship); 143 intake.remove(moduleGroup); 144 setTarget(data, template); 145 return; 146 } 147 else if (!user.hasPermission(ScarabSecurity.MODULE__EDIT, origParent) && 148 origParent.getModuleId() != newParent.getModuleId()) 149 { 150 scarabR.setAlertMessage(L10NKeySet.NoPermissionInParentModule); 151 setTarget(data, template); 152 return; 153 } 154 155 if (! newCode.equals(origCode)) 157 { 158 if (me instanceof ScarabModule) 159 { 160 ScarabModule sm = (ScarabModule)me; 161 List issues = sm.getIssues(); 162 for (int i = 0; i < issues.size(); i++) 163 { 164 Issue issue = (Issue)issues.get(i); 165 if (! issue.getIdPrefix().equals(me.getCode())) 166 { 167 issue.setIdPrefix(me.getCode()); 168 issue.save(); 169 } 170 } 171 String idTable = IDBroker.TABLE_NAME.substring(0, 174 IDBroker.TABLE_NAME.indexOf('.')); 175 String sql = "update " + idTable 176 + " SET TABLE_NAME='" + newCode + "' WHERE TABLE_NAME='" + 177 origCode + "'"; 178 BasePeer.executeStatement(sql); 179 } 180 else 181 { 182 throw new Exception ("Did not get a ScarabModule"); } 184 } 185 186 me.save(); 187 188 if (GlobalParameterManager.getBoolean( 190 GlobalParameter.EMAIL_ALLOW_MODULE_OVERRIDE,me)) 191 { 192 ParameterParser pp = data.getParameters(); 193 String name; 194 for (int i=0; i<EMAIL_PARAMS.length; i++) 195 { 196 name = EMAIL_PARAMS[i]; 197 GlobalParameterManager 198 .setBoolean(name, me, pp.getBoolean(name)); 199 } 200 } 201 202 ParameterParser pp = data.getParameters(); 203 String name = GlobalParameter.ISSUE_REASON_REQUIRED; 204 boolean allowEmptyReason = pp.getBoolean(name,false); 205 GlobalParameterManager.setBoolean(name, me,allowEmptyReason); 206 207 intake.remove(moduleGroup); 208 setTarget(data, nextTemplate); 209 scarabR.setConfirmMessage(L10NKeySet.ModuleUpdated); 210 } 211 } 212 } 213 214 217 public void doCreate(RunData data, TemplateContext context) 218 throws Exception 219 { 220 String template = getCurrentTemplate(data, null); 221 String nextTemplate = getNextTemplate(data, template); 222 223 ScarabLocalizationTool l10n = getLocalizationTool(context); 224 IntakeTool intake = getIntakeTool(context); 225 ScarabRequestTool scarabR = getScarabRequestTool(context); 226 227 if (intake.isAllValid()) 228 { 229 Group moduleGroup = intake.get 230 ("Module",IntakeTool.DEFAULT_KEY, false); 231 Module me = ModuleManager.getInstance(); 232 if (moduleGroup == null) 233 { 234 throw new Exception ("Could not locate module"); } 236 try 237 { 238 moduleGroup.setProperties(me); 239 ScarabUser user = (ScarabUser)data.getUser(); 240 241 if (!user.hasPermission(ScarabSecurity.MODULE__EDIT, 245 me.getParent())) 246 { 247 throw new Exception ("You do not have permission to" + 248 " assign this module to the requested parent module."); } 250 me.setOwnerId(user.getUserId()); 251 me.save(); 252 253 data.setACL(TurbineSecurity.getACL(data.getUser())); 254 data.save(); 255 256 scarabR.setConfirmMessage(L10NKeySet.NewModuleCreated); 257 } 258 catch (Exception e) 259 { 260 setTarget(data, template); 261 Log.get().error(e); 262 String msg = l10n.getMessage(e); 263 scarabR.setAlertMessage(msg); 264 return; 265 } 266 intake.remove(moduleGroup); 267 } 268 else 269 { 270 setTarget(data, template); 271 return; 272 } 273 setTarget(data, nextTemplate); 274 } 275 } 276 | Popular Tags |