Index: src/hg/instinct/hgHeatmap2/hgHeatmap2.c
===================================================================
RCS file: /projects/compbio/cvsroot/kent/src/hg/instinct/hgHeatmap2/hgHeatmap2.c,v
retrieving revision 1.86
retrieving revision 1.87
diff -b -B -U 4 -r1.86 -r1.87
--- src/hg/instinct/hgHeatmap2/hgHeatmap2.c	17 Mar 2010 01:29:29 -0000	1.86
+++ src/hg/instinct/hgHeatmap2/hgHeatmap2.c	12 Apr 2010 17:16:56 -0000	1.87
@@ -30,8 +30,9 @@
 #include "json.h"
 #include "hgHeatmapLib.h"
 #include "heatmapUtility.h"
 #include "hgUsers.h"
+#include "raDb.h"
 
 static char const rcsid[] = "$Id$";
 
 /* ---- Global variables. ---- */
@@ -652,8 +652,60 @@
 
 hFreeConn(&conn);
 }
 
+void addUserDbHeatmapsRaDb(struct genoHeatmap **list, char *raName)
+{
+/* only to test user authentication currently */
+char *tokenIdStr = cartOptionalString(cart, hgh2UserTokenId);
+char *userIdStr = cartOptionalString(cart, hgh2UserId);
+if (!tokenIdStr || !userIdStr)
+    return;
+
+int tokenId = atoi(tokenIdStr);
+int userId  = atoi(userIdStr);
+
+struct slName *sl, *datasets = getUserDatasets(cart, tokenId, userId);
+if (!datasets)
+    return;
+if (!slCount(datasets))
+    return;
+
+struct sqlConnection *conn = hAllocConnProfile(localDbProfile, database);
+if (!conn)
+    return;
+
+struct raDb *ra, *raList = raDbLoad(conn);
+
+if (!raList)
+    {
+    hFreeConn(&conn);
+    errAbort("Couldn't find anything from raDb.");
+    }
+
+for (ra = raList; ra != NULL; ra = ra->next)
+    {
+    boolean userHasAccess = FALSE;
+    for (sl = datasets; sl; sl = sl->next)
+	if (sameString(sl->name, ra->name))
+	    userHasAccess = TRUE;
+
+    if (!userHasAccess)
+	continue;
+
+    struct genoHeatmap *gh = getHeatmapRaDb(conn, NULL, database, ra);
+
+    if (!gh)
+	continue;
+    if (!gh->private)
+	continue;  // do not public private datasets.
+
+    slAddHead(list, gh);
+    }
+
+hFreeConn(&conn);
+}
+
 struct genoHeatmap *getUserDbHeatmaps(char *raName)
 /* Get graphs defined. Requried to be present in the database as well as 
    in the datasets.ra file */
 {
@@ -723,16 +773,77 @@
 
 return list;
 }
 
+struct genoHeatmap *getDbHeatmapsRaDb(char *set, char *raName)
+/* Get graphs defined. Requried to be present in the database as well as 
+   in the datasets.ra file */
+{
+struct sqlConnection *localConn = hAllocConnProfile(localDbProfile, database);
+if (!localConn)
+    return NULL;
+
+/* This can be NULL */
+struct sqlConnection *publicConn = hAllocConnProfile(publicDbProfile, database);
+
+char varName[1024];
+struct genoHeatmap *list = NULL, *gh;
+
+struct raDb *ra, *raList = raDbLoad(localConn);
+
+if (raList == NULL)
+    {
+    hFreeConn(&localConn);
+    hFreeConn(&publicConn);
+    errAbort("Couldn't find anything from %s", raName);
+    }
+
+for (ra = raList; ra != NULL; ra = ra->next)
+    {
+    safef(varName, sizeof(varName), "%s%s.%s", hghDataConfigPrefix, ra->name, hghVis);
+
+    /* cgi visibility */
+    char *vis;
+    if (!hashLookup(cart->hash,varName))
+	/* default visibility */
+	vis = ra->visibility;
+    else
+	{
+	boolean cgiVis = cartBoolean(cart,varName);
+	if (cgiVis)
+	    vis = "on";
+	else
+	    vis = "off";
+	}
+
+
+    gh = getHeatmapRaDb(localConn, publicConn, database, ra);
+    if (!gh)
+	continue;
+    if (gh->private)
+	continue;  // do not include private datasets.
+
+    slAddHead(&list,gh);
+    }
+
+hFreeConn(&localConn);
+hFreeConn(&publicConn);
+
+addUserDbHeatmapsRaDb(&list, raName);
+addCustomDbHeatmaps(&list, raName);
+slReverse(&list);
+
+return list;
+}
+
 void getGenoHeatmaps(char* set)
 /* Set up ghList and ghHash with all available genome graphs */
 {
 if (isEmpty(set))
     return;
 
 char *datasetRaName = dataSetRaName();
-struct genoHeatmap *dbList = getDbHeatmaps(set, datasetRaName);
+struct genoHeatmap *dbList = getDbHeatmapsRaDb(set, datasetRaName);
 
 struct genoHeatmap *gh;
 struct slRef *ref, *refList = NULL;
 

