r7353 - in dumbhippo/trunk/server: src/com/dumbhippo/persistence src/com/dumbhippo/server src/com/dumbhippo/server/impl web/tags/3



Author: marinaz
Date: 2008-03-05 16:47:09 -0600 (Wed, 05 Mar 2008)
New Revision: 7353

Modified:
   dumbhippo/trunk/server/src/com/dumbhippo/persistence/EmailResource.java
   dumbhippo/trunk/server/src/com/dumbhippo/server/OnlineDesktopSystem.java
   dumbhippo/trunk/server/src/com/dumbhippo/server/impl/IdentitySpiderBean.java
   dumbhippo/trunk/server/src/com/dumbhippo/server/impl/OnlineDesktopSystemBean.java
   dumbhippo/trunk/server/web/tags/3/accountEditTable.tag
Log:
Save Gmail accounts as supported by Google by default.

Do not allow the user to uncheck them as such.

Signal a User data model change if an account claim 
is created with the user as an owner of an e-mail supported 
by Google. (This will apply if someone verified a Gmail
email, but also if someone claims an e-mail that was 
previously marked as supported by Google.)

Modified: dumbhippo/trunk/server/src/com/dumbhippo/persistence/EmailResource.java
===================================================================
--- dumbhippo/trunk/server/src/com/dumbhippo/persistence/EmailResource.java	2008-03-05 20:00:37 UTC (rev 7352)
+++ dumbhippo/trunk/server/src/com/dumbhippo/persistence/EmailResource.java	2008-03-05 22:47:09 UTC (rev 7353)
@@ -116,4 +116,9 @@
 			return withAt; // something invalid, maybe nothing before the @
 		}
 	}
+	
+	@Transient
+	public boolean isGmail() {
+	    return email.endsWith("@gmail.com");	
+	}
 }

Modified: dumbhippo/trunk/server/src/com/dumbhippo/server/OnlineDesktopSystem.java
===================================================================
--- dumbhippo/trunk/server/src/com/dumbhippo/server/OnlineDesktopSystem.java	2008-03-05 20:00:37 UTC (rev 7352)
+++ dumbhippo/trunk/server/src/com/dumbhippo/server/OnlineDesktopSystem.java	2008-03-05 22:47:09 UTC (rev 7353)
@@ -4,6 +4,7 @@
 
 import javax.ejb.Local;
 
+import com.dumbhippo.persistence.EmailDetails;
 import com.dumbhippo.persistence.EmailResource;
 import com.dumbhippo.persistence.User;
 import com.dumbhippo.server.views.Viewpoint;
@@ -14,8 +15,12 @@
  */
 @Local
 public interface OnlineDesktopSystem {
+
+	public EmailDetails lookupEmailDetails(EmailResource email);
 	
 	public List<EmailResource> getGoogleEnabledEmails(Viewpoint viewpoint, User user);
 	
 	void setGoogleServicedEmail(Viewpoint viewpoint, User user, EmailResource email, boolean enabled) throws RetryException;
+
+    public void onGoogleServicedEmailChange(Viewpoint viewpoint, User user, EmailResource email);
 }

Modified: dumbhippo/trunk/server/src/com/dumbhippo/server/impl/IdentitySpiderBean.java
===================================================================
--- dumbhippo/trunk/server/src/com/dumbhippo/server/impl/IdentitySpiderBean.java	2008-03-05 20:00:37 UTC (rev 7352)
+++ dumbhippo/trunk/server/src/com/dumbhippo/server/impl/IdentitySpiderBean.java	2008-03-05 22:47:09 UTC (rev 7353)
@@ -39,6 +39,7 @@
 import com.dumbhippo.persistence.Contact;
 import com.dumbhippo.persistence.ContactClaim;
 import com.dumbhippo.persistence.ContactStatus;
+import com.dumbhippo.persistence.EmailDetails;
 import com.dumbhippo.persistence.EmailResource;
 import com.dumbhippo.persistence.ExternalAccount;
 import com.dumbhippo.persistence.ExternalAccountType;
@@ -67,6 +68,7 @@
 import com.dumbhippo.server.IdentitySpiderRemote;
 import com.dumbhippo.server.NotFoundException;
 import com.dumbhippo.server.Notifier;
+import com.dumbhippo.server.OnlineDesktopSystem;
 import com.dumbhippo.server.PermissionDeniedException;
 import com.dumbhippo.server.RevisionControl;
 import com.dumbhippo.server.dm.ContactDMO;
@@ -114,6 +116,9 @@
 	@EJB
 	private RevisionControl revisionControl;
 	
+	@EJB
+	private OnlineDesktopSystem onlineDesktop;
+	
 	public User lookupUserByEmail(Viewpoint viewpoint, String email) throws NotFoundException {
 		EmailResource res = lookupEmail(email);
 		// lookupEmail will normally throw a NotFoundException if the resource is not found, 
@@ -204,6 +209,13 @@
 				} catch (NoResultException e) {
 					res = new EmailResource(email);
 					em.persist(res);
+					if (res.isGmail()) {
+						try {
+					        onlineDesktop.setGoogleServicedEmail(SystemViewpoint.getInstance(), null, res, true);
+						} catch (RetryException e1) {
+							logger.error("Failed to create a Google serviced e-mail for " + email, e1);							
+						}
+					}
 				}
 
 				return res;
@@ -555,6 +567,14 @@
 		groupSystem.fixupGroupMemberships(claimedOwner);
 		
 		invalidateUserResource(claimedOwner, res);
+		
+		if (res instanceof EmailResource) {
+		     EmailDetails emailDetails = onlineDesktop.lookupEmailDetails((EmailResource)res);
+		     if (emailDetails != null && emailDetails.getGoogleServicesEnabled()) {
+		    	 // we want to send out a notification for the claimedOwner about a new Google serviced e-mail
+		    	 onlineDesktop.onGoogleServicedEmailChange(SystemViewpoint.getInstance(), claimedOwner, (EmailResource)res);
+		    }						
+		}
 	}
 
 	public void removeVerifiedOwnershipClaim(UserViewpoint viewpoint,

Modified: dumbhippo/trunk/server/src/com/dumbhippo/server/impl/OnlineDesktopSystemBean.java
===================================================================
--- dumbhippo/trunk/server/src/com/dumbhippo/server/impl/OnlineDesktopSystemBean.java	2008-03-05 20:00:37 UTC (rev 7352)
+++ dumbhippo/trunk/server/src/com/dumbhippo/server/impl/OnlineDesktopSystemBean.java	2008-03-05 22:47:09 UTC (rev 7353)
@@ -19,6 +19,7 @@
 import com.dumbhippo.server.OnlineDesktopSystem;
 import com.dumbhippo.server.dm.DataService;
 import com.dumbhippo.server.dm.UserDMO;
+import com.dumbhippo.server.views.SystemViewpoint;
 import com.dumbhippo.server.views.Viewpoint;
 import com.dumbhippo.tx.RetryException;
 import com.dumbhippo.tx.TxCallable;
@@ -52,6 +53,19 @@
 			}
 		});
 	}
+
+	public EmailDetails lookupEmailDetails(EmailResource email) {
+	    Query q;
+
+		q = em.createQuery("from EmailDetails e where e.id = :email");
+		q.setParameter("email", email.getId());
+
+		try {
+		    return (EmailDetails) q.getSingleResult();
+		} catch (NoResultException e) {
+			return null;
+		}
+	}
 	
 	public List<EmailResource> getGoogleEnabledEmails(Viewpoint viewpoint,
 			User user) {
@@ -65,13 +79,34 @@
 	}
 
 	public void setGoogleServicedEmail(Viewpoint viewpoint, User user, EmailResource email, boolean enabled) throws RetryException {
-		if (!viewpoint.isOfUser(user))
+		if (!(viewpoint instanceof SystemViewpoint) && !viewpoint.isOfUser(user))
 			throw new RuntimeException("can only get your own enabled emails");
-		if (email.getAccountClaim().getOwner() != user)
+		if (!(viewpoint instanceof SystemViewpoint) && !email.getAccountClaim().getOwner().equals(user))
 			throw new RuntimeException("can only set Google state for emails you own");
 		EmailDetails ed = getEmailDetails(email);
 		ed.setGoogleServicesEnabled(enabled);
-		ReadWriteSession session = DataService.currentSessionRW();
-		session.changed(UserDMO.class, user.getGuid(), "googleEnabledEmails");		
+
+		// there is currently no scenario when we'll get a null user, when an account claim exists,
+		// but it's fine to check
+		if (user == null && email.getAccountClaim() != null) {
+			user = email.getAccountClaim().getOwner();
+			if (user != null) {
+				logger.debug("Found a user {} for e-mail {} when originally the user was null", user, email.getEmail());
+			}
+		}
+		
+		if (user != null) {
+			onGoogleServicedEmailChange(viewpoint, user, email);	
+		}
 	} 
+	
+    public void onGoogleServicedEmailChange(Viewpoint viewpoint, User user, EmailResource email) {
+		if (!(viewpoint instanceof SystemViewpoint) && !viewpoint.isOfUser(user))
+			throw new RuntimeException("can only get your own enabled emails");
+		if (!(viewpoint instanceof SystemViewpoint) && !email.getAccountClaim().getOwner().equals(user))
+			throw new RuntimeException("can only set Google state for emails you own");
+		
+	    ReadWriteSession session = DataService.currentSessionRW();
+	    session.changed(UserDMO.class, user.getGuid(), "googleEnabledEmails");		    	
+    }
 }

Modified: dumbhippo/trunk/server/web/tags/3/accountEditTable.tag
===================================================================
--- dumbhippo/trunk/server/web/tags/3/accountEditTable.tag	2008-03-05 20:00:37 UTC (rev 7352)
+++ dumbhippo/trunk/server/web/tags/3/accountEditTable.tag	2008-03-05 22:47:09 UTC (rev 7353)
@@ -164,6 +164,10 @@
 		</div>
 	    </dht2:formTableRow>
 	    <dht2:formTableRow label="Google services">
+	    <div class="dh-explanation">
+	    Selecting emails that are supported by <a href="http://www.google.com/a"; target="_blank">Google Apps for Your Domain</a> will allow various Online Desktop widgets get updates for 
+	    the corresponding accounts. Your Gmail emails are selected automatically.   
+		</div>
 		<div id="dhGoogleServices"
 			class="dh-account-preferences-row">
 			<table>
@@ -173,12 +177,22 @@
 					<td>
 					    <c:set var="checkboxId" value="dhGoogleEnabledEmail${loopStatus.count}"/>
 						<c:choose>
+						    <%-- we really shouldn't have any Gmail e-mails that are not among google enabled e-mails, --%>
+						    <%-- but if that's the case, we'll let the user fix the error, rather than mask it --%> 
+							<c:when test="${dh:containerHas(account.person.dmo.googleEnabledEmails, email.email) && email.gmail}">
+								<jsp:element name="input">
+									<jsp:attribute name="type">checkbox</jsp:attribute>
+									<jsp:attribute name="id"><c:out value="${checkboxId}"/></jsp:attribute>
+									<jsp:attribute name="checked">true</jsp:attribute>
+									<jsp:attribute name="disabled"/>
+								</jsp:element>
+							</c:when>						
 							<c:when test="${dh:containerHas(account.person.dmo.googleEnabledEmails, email.email)}">
 								<jsp:element name="input">
 									<jsp:attribute name="type">checkbox</jsp:attribute>
 									<jsp:attribute name="id"><c:out value="${checkboxId}"/></jsp:attribute>
 									<jsp:attribute name="onclick">dh.actions.setGoogleServicedEmail(<dh:jsString value="${email.email}" />, <dh:jsString value="${checkboxId}" />)</jsp:attribute>
-									<jsp:attribute name="checked">true</jsp:attribute>
+									<jsp:attribute name="checked">true</jsp:attribute>  
 								</jsp:element>
 							</c:when>
 							<c:otherwise>



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]