1 package org.tigris.scarab.screens; 2 3 48 49 import java.util.List ; 51 52 import org.apache.turbine.RunData; 54 import org.apache.turbine.TemplateContext; 55 import org.apache.turbine.TemplateSecureScreen; 56 import org.apache.turbine.Turbine; 57 58 import org.tigris.scarab.services.security.ScarabSecurity; 60 import org.tigris.scarab.tools.ScarabRequestTool; 61 import org.tigris.scarab.tools.ScarabLocalizationTool; 62 import org.tigris.scarab.tools.localization.L10NKeySet; 63 import org.tigris.scarab.util.ScarabConstants; 64 import org.tigris.scarab.util.Log; 65 import org.tigris.scarab.om.Module; 66 import org.tigris.scarab.om.ModuleManager; 67 import org.tigris.scarab.om.ScarabUser; 68 69 79 public class Default extends TemplateSecureScreen 80 { 81 87 public String doBuild(RunData data) throws Exception 88 { 89 super.doBuild(data); 90 return ""; 91 } 92 93 96 protected void doBuildTemplate(RunData data, TemplateContext context) 97 throws Exception 98 { 99 ScarabRequestTool scarabR = getScarabRequestTool(context); 100 try 104 { 105 scarabR.getCurrentModule(); 106 } 107 catch (Exception ignore) 108 { 109 } 110 111 ScarabLocalizationTool l10n = 113 (ScarabLocalizationTool) context.get("l10n"); 114 115 String altTarget = getTargetForNoIssueTypes(data); 117 boolean changeTarget = false; 118 if (altTarget != null) 119 { 120 List issueTypes = scarabR.getCurrentModule().getIssueTypes(true); 121 changeTarget = (issueTypes == null || issueTypes.isEmpty()); 122 } 123 124 if (changeTarget) 125 { 126 scarabR.setAlertMessage(L10NKeySet.IssueTypeUnavailable); 128 setTarget(data, altTarget); 129 } 130 else 131 { 132 String title = null; 134 try 135 { 136 title = getTitle(scarabR, l10n); 137 } 138 catch (Exception e) 139 { 140 Log.get().info( 141 "Error getting page title for Screen: " + data.getTarget()); 142 } 143 if (title == null) 144 { 145 title = "Scarab"; 146 } 147 context.put("title", title); 148 } 149 } 150 151 protected String getTitle(ScarabRequestTool scarabR, ScarabLocalizationTool l10n) 152 throws Exception 153 { 154 return l10n.getTitle(); 155 } 156 157 163 private String getTargetForNoIssueTypes(RunData data) 164 { 165 String property = 166 "template." 167 + data.getTarget().replace(',', '/') 168 + ".noIssueTypesForwardsTo"; 169 return Turbine.getConfiguration().getString(property, null); 170 } 171 172 176 protected boolean isAuthorized(RunData data) throws Exception 177 { 178 return checkAuthorized(data); 179 } 180 181 185 public static boolean checkAuthorized(RunData data) throws Exception 186 { 187 String template = data.getTarget(); 188 { 189 template = template.replace(',', '.'); 190 String perm = ScarabSecurity.getScreenPermission(template); 191 TemplateContext context = getTemplateContext(data); 192 ScarabRequestTool scarabR = getScarabRequestTool(context); 193 ScarabLocalizationTool l10n = getLocalizationTool(context); 194 Module currentModule = scarabR.getCurrentModule(); 195 ScarabUser user = (ScarabUser) data.getUser(); 196 if (perm != null) 197 { 198 if (!user.hasLoggedIn() 199 || !user.hasPermission(perm, currentModule)) 200 { 201 scarabR.setInfoMessage(L10NKeySet.LoginToAccountWithPermissions); 202 if ("ViewIssue.vm".equals(data.getTarget())) 207 { 208 data.getParameters().setString( 209 "viewIssueId", 210 data.getParameters().getString("id")); 211 } 212 213 setTargetLogin(data); 214 scarabR.setCurrentModule(null); 215 return false; 216 } 217 else if (currentModule == null) 218 { 219 Log.get().debug("Current module is null"); 220 scarabR.setInfoMessage(L10NKeySet.SelectModuleToWorkIn); 221 setTargetSelectModule(data); 222 return false; 223 } 224 } 225 else if ( 229 currentModule != null && !user.hasAnyRoleIn(currentModule) 230 && !user.hasAnyRoleIn( 231 ModuleManager.getInstance(Module.ROOT_ID))) 232 { 233 if (Log.get().isDebugEnabled()) 234 { 235 Log.get().debug( 236 "User (" 237 + user.getUserId() 238 + ") did not have any roles in current module" 239 + currentModule.getName()); 240 } 241 scarabR.setCurrentModule(null); 242 data.getParameters().remove(ScarabConstants.CURRENT_MODULE); 243 scarabR.setAlertMessage(L10NKeySet.NoPermissionInModule); 244 setTargetSelectModule(data); 245 return false; 246 } 247 262 } 263 return true; 264 } 265 266 public static void setTargetSelectModule(RunData data) 267 { 268 getTemplateContext(data).put( 269 ScarabConstants.NEXT_TEMPLATE, 270 data.getParameters().getString(ScarabConstants.NEXT_TEMPLATE)); 271 272 setTarget( 273 data, 274 Turbine.getConfiguration().getString( 275 "scarab.CurrentModuleTemplate", 276 "SelectModule.vm")); 277 } 278 279 public static void setTargetLogin(RunData data) 280 { 281 getTemplateContext(data).put( 282 ScarabConstants.NEXT_TEMPLATE, 283 data.getParameters().getString("template")); 284 setTarget(data, "Login.vm"); 285 } 286 287 290 public static ScarabRequestTool getScarabRequestTool(TemplateContext context) 291 { 292 return (ScarabRequestTool) context.get( 293 ScarabConstants.SCARAB_REQUEST_TOOL); 294 } 295 296 299 public static ScarabLocalizationTool getLocalizationTool(TemplateContext context) 300 { 301 return (ScarabLocalizationTool) context.get( 302 ScarabConstants.LOCALIZATION_TOOL); 303 } 304 } 305 | Popular Tags |