1 package org.tigris.scarab.om; 2 3 48 49 import java.util.Arrays ; 50 51 import org.apache.turbine.TemplateContext; 52 import org.apache.turbine.Turbine; 53 54 import org.apache.torque.om.Persistent; 55 56 import org.tigris.scarab.om.Module; 57 import org.tigris.scarab.services.security.ScarabSecurity; 58 import org.tigris.scarab.tools.localization.L10NKeySet; 59 import org.tigris.scarab.util.Email; 60 import org.tigris.scarab.util.EmailContext; 61 import org.tigris.scarab.util.ScarabException; 62 63 69 public class IssueTemplateInfo 70 extends org.tigris.scarab.om.BaseIssueTemplateInfo 71 implements Persistent 72 { 73 74 77 public static IssueTemplateInfo getInstance() 78 { 79 return new IssueTemplateInfo(); 80 } 81 82 83 public boolean canDelete(ScarabUser user) 84 throws Exception 85 { 86 return (user.hasPermission(ScarabSecurity.ITEM__DELETE, getIssue().getModule()) 89 || (user.getUserId().equals(getIssue().getCreatedBy().getUserId()) 90 && getScopeId().equals(Scope.PERSONAL__PK))); 91 } 92 93 public boolean canEdit(ScarabUser user) 94 throws Exception 95 { 96 return canDelete(user); 97 } 98 99 public void saveAndSendEmail(ScarabUser user, Module module, 100 TemplateContext context) 101 throws Exception 102 { 103 boolean success = true; 106 Issue issue = IssueManager.getInstance(getIssueId()); 107 108 if (getScopeId().equals(Scope.PERSONAL__PK) 111 || user.hasPermission(ScarabSecurity.ITEM__APPROVE, module)) 112 { 113 setApproved(true); 114 } 115 else 116 { 117 setApproved(false); 118 issue.save(); 119 120 if (context != null) 123 { 124 String template = Turbine.getConfiguration(). 125 getString("scarab.email.requireapproval.template", 126 "RequireApproval.vm"); 127 128 ScarabUser[] toUsers = module.getUsers(ScarabSecurity.MODULE__EDIT); 129 if (toUsers.length == 0) 132 { 133 toUsers = new ScarabUser[1]; 134 toUsers[0] = user; 135 } 136 137 EmailContext ectx = new EmailContext(); 138 ectx.setUser(user); 139 ectx.setModule(module); 140 ectx.setDefaultTextKey("NewTemplateRequiresApproval"); 141 142 String fromUser = "scarab.email.default"; 143 try 144 { 145 Email.sendEmail(ectx, 146 module, 147 fromUser, 148 module.getSystemEmail(), 149 Arrays.asList(toUsers), 150 null, template); 151 } 152 catch(Exception e) 153 { 154 save(); throw e; 157 } 158 } 159 } 160 save(); 161 } 162 163 167 public void approve(ScarabUser user, boolean approved) 168 throws Exception 169 { 170 Module module = getIssue().getModule(); 171 172 if (user.hasPermission(ScarabSecurity.ITEM__APPROVE, module)) 173 { 174 setApproved(true); 175 if (!approved) 176 { 177 setScopeId(Scope.PERSONAL__PK); 178 } 179 save(); 180 } 181 else 182 { 183 throw new ScarabException(L10NKeySet.YouDoNotHavePermissionToAction); 184 } 185 } 186 187 } 188 | Popular Tags |