[viewvc-dev] [PATCH] Hide query link (and RSS feeds) when database does not have the root

"Larry Shatzer, Jr." <[email protected]>
Newsgroups gmane.comp.version-control.cvs.viewcvs.devel
Message-ID <3fb3af800806190831r48ce023ap248fb5f5b55312f1__11385.0401984111$1213889625$gmane$org@mail.gmail.com>
We have quite a few CVS and Subversion repository roots, and not all have
their information in the query database. To avoid confusion, I have modified
my local install of ViewVC to hide the query link (and RSS feeds) for
repository roots that do not have the database backing them. If needed, I
can create an issue and post this there instead.

[[[

* templates/include/footer.ezt
* templates/include/dir_header.ezt
* templates/include/header.ezt
* lib/viewvc.py (common_template_data), (is_querydb_populated): New

Hide query link and RSS feeds for repository roots that do not have data in
the query database.

]]]

-- Larry

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
querydbpopulated.patch (text/x-patch, 3.4 KB)
Index: templates/include/footer.ezt
===================================================================
--- templates/include/footer.ezt	(revision 1958)
+++ templates/include/footer.ezt	(working copy)
@@ -9,7 +9,7 @@
 </tr>
 <tr>
   <td>Powered by <a href="http://viewvc.tigris.org/">ViewVC [vsn]</a></td>
-  <td style="text-align: right;">[if-any rss_href]<a href="[rss_href]" title="RSS 2.0 feed"><img src="[docroot]/images/feed-icon-16x16.jpg" class="vc_icon" alt="RSS 2.0 feed" /></a>[else]&nbsp;[end]</td>
+  <td style="text-align: right;">[if-any rss_href][if-any querydb_populated]<a href="[rss_href]" title="RSS 2.0 feed"><img src="[docroot]/images/feed-icon-16x16.jpg" class="vc_icon" alt="RSS 2.0 feed" /></a>[else]&nbsp;[end][end]</td>
 </tr>
 </table>
 
Index: templates/include/dir_header.ezt
===================================================================
--- templates/include/dir_header.ezt	(revision 1958)
+++ templates/include/dir_header.ezt	(working copy)
@@ -54,12 +54,12 @@
 </tr>
 [end]
 
-[if-any queryform_href]
+[if-any querydb_populated][if-any queryform_href]
 <tr>
   <td>Query:</td>
   <td><a href="[queryform_href]">Query revision history</a></td>
 </tr>
-[end]
+[end][end]
 
 </table>
 
Index: templates/include/header.ezt
===================================================================
--- templates/include/header.ezt	(revision 1958)
+++ templates/include/header.ezt	(working copy)
@@ -7,7 +7,7 @@
   <meta name="generator" content="ViewVC [vsn]" />
   <link rel="shortcut icon" href="[docroot]/images/favicon.ico" type="image/x-icon" />
   <link rel="stylesheet" href="[docroot]/styles.css" type="text/css" />
-  [if-any rss_href]<link rel="alternate" type="application/rss+xml" title="RSS [[][rootname]][where]" href="[rss_href]" />[end]
+  [if-any rss_href][if-any querydb_populated]<link rel="alternate" type="application/rss+xml" title="RSS [[][rootname]][where]" href="[rss_href]" />[end][end]
 </head>
 <body>
 <div class="vc_navheader">
Index: lib/viewvc.py
===================================================================
--- lib/viewvc.py	(revision 1958)
+++ lib/viewvc.py	(working copy)
@@ -1165,6 +1165,7 @@
     'download_text_href' : None,
     'revision_href' : None,
     'queryform_href' : None,
+    'querydb_populated' : None,
     'tarball_href' : None,
     'up_href'  : None,
     'log_href' : None,
@@ -1238,6 +1239,7 @@
     data['queryform_href'] = request.get_url(view_func=view_queryform,
                                              params=params,
                                              escape=1)
+    data['querydb_populated'] = is_querydb_populated(request)
 
   if request.cfg.cvsdb.enabled and request.roottype in ['cvs', 'svn']:
     if request.pathtype == vclib.DIR:
@@ -3539,6 +3541,20 @@
               % (fileinfo.rev, prev_rev(fileinfo.rev),
                  fileinfo.dir, fileinfo.file)
 
+def is_querydb_populated(request):
+  if not is_query_supported(request):
+    raise debug.ViewVCException('Can not query project root "%s" at "%s".'
+                                 % (request.rootname, request.where),
+                                 '403 Forbidden')
+
+  global cvsdb
+  import cvsdb
+  cfg = request.cfg  
+  db = cvsdb.ConnectDatabaseReadOnly(cfg)
+  repos_root, repos_dir = cvsdb.FindRepository(db, request.rootpath)
+  if repos_root:
+    return True 
+
 def view_query(request):
   if not is_query_supported(request):
     raise debug.ViewVCException('Can not query project root "%s" at "%s".'
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.