← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] lp:~cjwatson/turnip/privacy-banner into lp:turnip

 

Colin Watson has proposed merging lp:~cjwatson/turnip/privacy-banner into lp:turnip.

Commit message:
Add a privacy banner to cgit-generated pages if the repository is private.

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~cjwatson/turnip/privacy-banner/+merge/260184

Add a privacy banner to cgit-generated pages if the repository is private.

I added ubuntu-webfonts.css from Launchpad to make the banner look as much like the standard Launchpad one as possible.  cgit's own CSS means that the Ubuntu font isn't currently used for the rest of the page, although this could of course be fixed separately.
-- 
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~cjwatson/turnip/privacy-banner into lp:turnip.
=== renamed directory 'images' => 'static'
=== added file 'static/global.css'
--- static/global.css	1970-01-01 00:00:00 +0000
+++ static/global.css	2015-05-26 16:10:32 +0000
@@ -0,0 +1,3 @@
+body {
+	font-family: Ubuntu, 'Bitstream Vera Sans', 'DejaVu Sans', Tahoma, sans-serif;
+}

=== added file 'static/notification-private.png'
Binary files static/notification-private.png	1970-01-01 00:00:00 +0000 and static/notification-private.png	2015-05-26 16:10:32 +0000 differ
=== added file 'static/private-banner.html'
--- static/private-banner.html	1970-01-01 00:00:00 +0000
+++ static/private-banner.html	2015-05-26 16:10:32 +0000
@@ -0,0 +1,4 @@
+<div class="global-notification">
+  The information on this page is private.
+  <span class="notification-private" />
+</div>

=== added file 'static/private.css'
--- static/private.css	1970-01-01 00:00:00 +0000
+++ static/private.css	2015-05-26 16:10:32 +0000
@@ -0,0 +1,36 @@
+/* Move the content down so the notification banner doesn't hide any content. */
+body {
+	padding-top: 40px;
+}
+
+.global-notification {
+	position: fixed;
+	z-index: 10;
+	top: 0;
+	left: 0;
+	right: 0;
+	padding: 8px 20px;
+	/* Define colour for browsers that don't support transparency */
+	background-color: #8d1f1f;
+	/* Set transparent background for browsers that support it */
+	background-color: rgba(125,0,0,0.9);
+	color: #fff;
+	text-shadow: 0 -1px 0 #631616;
+	font-size: 14px;
+	line-height: 21px;
+	font-weight: bold;
+	-moz-box-shadow: 0 0 5px #333;
+	-webkit-box-shadow: 0 0 5px #333;
+	box-shadow: 0 0 5px #333;
+}
+
+.notification-private {
+	background-image: url(/static/notification-private.png);
+	background-repeat: no-repeat;
+	float: left;
+	display: inline-block;
+	height: 21px;
+	width: 20px;
+	margin-right: 10px;
+	padding: 0;
+}

=== added file 'static/ubuntu-webfonts.css'
--- static/ubuntu-webfonts.css	1970-01-01 00:00:00 +0000
+++ static/ubuntu-webfonts.css	2015-05-26 16:10:32 +0000
@@ -0,0 +1,30 @@
+/* Web font definitions for the Ubuntu font.
+ *
+ * Retrieved from https://fonts.googleapis.com/css?family=Ubuntu:400,400italic,700,700italic
+ *
+ * But served from launchpad.net for performance and security reasons.
+ */
+@font-face {
+  font-family: 'Ubuntu';
+  font-style: italic;
+  font-weight: normal;
+  src: local('Ubuntu Italic'), local('Ubuntu-Italic'), url('https://themes.googleusercontent.com/static/fonts/ubuntu/v3/kbP_6ONYVgE-bLa9ZRbvvvesZW2xOQ-xsNqO47m55DA.woff') format('woff');
+}
+@font-face {
+  font-family: 'Ubuntu';
+  font-style: normal;
+  font-weight: bold;
+  src: local('Ubuntu Bold'), local('Ubuntu-Bold'), url('https://themes.googleusercontent.com/static/fonts/ubuntu/v3/0ihfXUL2emPh0ROJezvraD8E0i7KZn-EPnyo3HZu7kw.woff') format('woff');
+}
+@font-face {
+  font-family: 'Ubuntu';
+  font-style: italic;
+  font-weight: bold;
+  src: local('Ubuntu Bold Italic'), local('Ubuntu-BoldItalic'), url('https://themes.googleusercontent.com/static/fonts/ubuntu/v3/OMD20Sg9RTs7sUORCEN-7YbN6UDyHWBl620a-IRfuBk.woff') format('woff');
+}
+@font-face {
+  font-family: 'Ubuntu';
+  font-style: normal;
+  font-weight: normal;
+  src: local('Ubuntu'), url('https://themes.googleusercontent.com/static/fonts/ubuntu/v3/_xyN3apAT_yRRDeqB3sPRg.woff') format('woff');
+}

=== modified file 'turnip/pack/http.py'
--- turnip/pack/http.py	2015-05-26 09:12:26 +0000
+++ turnip/pack/http.py	2015-05-26 16:10:32 +0000
@@ -357,12 +357,13 @@
 class CGitScriptResource(twcgi.CGIScript):
     """HTTP resource to run cgit."""
 
-    def __init__(self, root, repo_url, repo_path, trailing):
+    def __init__(self, root, repo_url, repo_path, trailing, private):
         twcgi.CGIScript.__init__(self, root.cgit_exec_path)
         self.root = root
         self.repo_url = repo_url
         self.repo_path = repo_path
         self.trailing = trailing
+        self.private = private
         self.cgit_config = None
 
     def _finished(self, ignored):
@@ -380,15 +381,26 @@
                 "{}://{}".format(scheme, self.root.site_name)
                 for scheme in ("git", "git+ssh", "https"))
             print("clone-prefix={}".format(prefixes), file=self.cgit_config)
+        if self.private:
+            fmt['css'] = '/static/cgit-private.css'
+        else:
+            fmt['css'] = '/static/cgit-public.css'
         print(textwrap.dedent("""\
-            css=/static/cgit.css
+            css={css}
             enable-http-clone=0
             enable-index-owner=0
             logo=/static/launchpad-logo.png
-
+            """).format(**fmt), end='', file=self.cgit_config)
+        if self.private:
+            top = os.path.dirname(os.path.dirname(os.path.dirname(__file__)))
+            print(
+                'header={top}/static/private-banner.html'.format(top=top),
+                file=self.cgit_config)
+        print(file=self.cgit_config)
+        print(textwrap.dedent("""\
             repo.url={repo_url}
             repo.path={repo_path}
-            """).format(**fmt), file=self.cgit_config)
+            """).format(**fmt), end='', file=self.cgit_config)
         self.cgit_config.flush()
         env["CGIT_CONFIG"] = self.cgit_config.name
         env["PATH_INFO"] = "/%s%s" % (self.repo_url, self.trailing)
@@ -570,7 +582,7 @@
             repo_url = repo_url[:-len(trailing)]
         repo_url = repo_url.strip('/')
         cgit_resource = CGitScriptResource(
-            self.root, repo_url, repo_path, trailing)
+            self.root, repo_url, repo_path, trailing, translated['private'])
         request.render(cgit_resource)
 
     def _translatePathErrback(self, failure, request, session):
@@ -647,10 +659,24 @@
             static_resource = DirectoryWithoutListings(
                 cgit_data_path, defaultType='text/plain')
             top = os.path.dirname(os.path.dirname(os.path.dirname(__file__)))
-            logo = os.path.join(top, 'images', 'launchpad-logo.png')
-            static_resource.putChild('launchpad-logo.png', static.File(logo))
+            stdir = os.path.join(top, 'static')
+            for name in ('launchpad-logo.png', 'notification-private.png'):
+                path = os.path.join(stdir, name)
+                static_resource.putChild(name, static.File(path))
+            with open(os.path.join(cgit_data_path, 'cgit.css'), 'rb') as f:
+                css = f.read()
+            with open(os.path.join(stdir, 'ubuntu-webfonts.css'), 'rb') as f:
+                css += b'\n' + f.read()
+            with open(os.path.join(stdir, 'global.css'), 'rb') as f:
+                css += b'\n' + f.read()
+            with open(os.path.join(stdir, 'private.css'), 'rb') as f:
+                private_css = css + b'\n' + f.read()
+            static_resource.putChild(
+                'cgit-public.css', static.Data(css, b'text/css'))
+            static_resource.putChild(
+                'cgit-private.css', static.Data(private_css, b'text/css'))
             self.putChild('static', static_resource)
-            favicon = os.path.join(top, 'images', 'launchpad.png')
+            favicon = os.path.join(stdir, 'launchpad.png')
             self.putChild('favicon.ico', static.File(favicon))
         cgit_secret_path = config.get("cgit_secret_path")
         if cgit_secret_path:


Follow ups