From 46f8131c60d088722035aefa31f62825e87bb79c Mon Sep 17 00:00:00 2001
From: Bindu Wavell
Date: Tue, 22 Feb 2011 08:28:16 -0700
Subject: [PATCH 1/5] Allow list for all admin users
---
app.yaml | 4 ++++
config.yaml | 1 -
upload.py | 9 +++++----
3 files changed, 9 insertions(+), 5 deletions(-)
delete mode 100644 config.yaml
diff --git a/app.yaml b/app.yaml
index 785d976..84a8b78 100644
--- a/app.yaml
+++ b/app.yaml
@@ -8,5 +8,9 @@ handlers:
- url: /static
static_dir: static
+- url: /list
+ login: required
+ script: upload.py
+
- url: /.*
script: upload.py
diff --git a/config.yaml b/config.yaml
deleted file mode 100644
index 8812218..0000000
--- a/config.yaml
+++ /dev/null
@@ -1 +0,0 @@
-authorized_user: your_account@gmail.com
diff --git a/upload.py b/upload.py
index 27cbb92..18f920e 100644
--- a/upload.py
+++ b/upload.py
@@ -31,7 +31,7 @@ def get(self):
'Hello %s Sign out
' %
(user.nickname(), users.create_logout_url("/list"))
)
- if user.email() == 'your_account@gmail.com':
+ if users.is_current_user_admin():
items = Content.all().order("-date")
path = os.path.join(os.path.dirname(__file__), 'templates/list.html')
self.response.out.write(template.render(path, {'items':items}))
@@ -47,9 +47,10 @@ def get(self, key):
class ShowPage(webapp.RequestHandler):
def get(self, key):
item = Content.get(key)
- self.response.headers['Content-Type'] = 'text/plain'
- #evaluate the extension, txt and log should be text, otherwise octet-stream
- #self.response.headers['Content-Type'] = 'application/octet-stream'
+ if item.filename[-4:] in (".log", ".txt"):
+ self.response.headers['Content-Type'] = 'text/plain'
+ else:
+ self.response.headers['Content-Type'] = 'application/octet-stream'
self.response.out.write(item.contents)
class TestPage(webapp.RequestHandler):
From a3e27a5fe8677bab9ab6e520b4fd08f629c71754 Mon Sep 17 00:00:00 2001
From: Bindu Wavell
Date: Tue, 22 Feb 2011 10:57:33 -0700
Subject: [PATCH 2/5] moved premission denied message into template and added
the ability to logout if you are logged in. also added some code to set the
filename for octet-stream downloads
---
upload.py | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/upload.py b/upload.py
index f429145..ff661ce 100644
--- a/upload.py
+++ b/upload.py
@@ -33,7 +33,12 @@ def get(self):
return
if user.email().lower() not in settings.ALLOWED_USERS and not users.is_current_user_admin():
- self.response.out.write("Permission Denied")
+ template_data = {
+ 'nickname' : user.nickname(),
+ 'logout_url' : users.create_logout_url("/list"),
+ }
+ path = os.path.join(os.path.dirname(__file__), 'templates/denied.html')
+ self.response.out.write(template.render(path, template_data ))
return
template_data = {
@@ -58,6 +63,7 @@ def get(self, key):
self.response.headers['Content-Type'] = 'text/plain'
else:
self.response.headers['Content-Type'] = 'application/octet-stream'
+ self.response.headers['Content-Disposition'] = 'attachment; filename="%s"' % (item.filename)
self.response.out.write(item.contents)
application = webapp.WSGIApplication([
From 5418897de5640b575113af6ab858db219a8701b1 Mon Sep 17 00:00:00 2001
From: Bindu Wavell
Date: Tue, 22 Feb 2011 10:57:59 -0700
Subject: [PATCH 3/5] and adding the denied tempalte file to source control...
---
templates/denied.html | 7 +++++++
1 file changed, 7 insertions(+)
create mode 100644 templates/denied.html
diff --git a/templates/denied.html b/templates/denied.html
new file mode 100644
index 0000000..fa55af6
--- /dev/null
+++ b/templates/denied.html
@@ -0,0 +1,7 @@
+
+
+
+
+
\ No newline at end of file
From 489bb39020c7445403cbf70243d2456482d102b3 Mon Sep 17 00:00:00 2001
From: Bindu Wavell
Date: Sun, 20 Mar 2011 16:26:20 -0600
Subject: [PATCH 4/5] Marked most endpoints as secured in app.yaml, updated the
list template to support bulk actions and bulk check/uncheck, added handler
for bulk delete
---
app.yaml | 12 ++++++++++++
templates/dump.html | 11 +++++++++++
templates/list.html | 45 ++++++++++++++++++++++++++++++++++++++++++++-
upload.py | 23 ++++++++++++++++++++++-
4 files changed, 89 insertions(+), 2 deletions(-)
create mode 100644 templates/dump.html
diff --git a/app.yaml b/app.yaml
index 84a8b78..e8ed2fc 100644
--- a/app.yaml
+++ b/app.yaml
@@ -11,6 +11,18 @@ handlers:
- url: /list
login: required
script: upload.py
+
+- url: /show/.*
+ login: required
+ script: upload.py
+
+- url: /delete/*
+ login: required
+ script: upload.py
+
+- url: /bulk-action
+ login: required
+ script: upload.py
- url: /.*
script: upload.py
diff --git a/templates/dump.html b/templates/dump.html
new file mode 100644
index 0000000..b37aae6
--- /dev/null
+++ b/templates/dump.html
@@ -0,0 +1,11 @@
+
+
+ {{item}}
+ {% endfor %}
+
+
+
+
\ No newline at end of file
diff --git a/templates/list.html b/templates/list.html
index dfeb8e6..e863bbd 100644
--- a/templates/list.html
+++ b/templates/list.html
@@ -1,14 +1,57 @@
+
+
+
+
\ No newline at end of file
diff --git a/upload.py b/upload.py
index ff661ce..d03a692 100644
--- a/upload.py
+++ b/upload.py
@@ -65,12 +65,33 @@ def get(self, key):
self.response.headers['Content-Type'] = 'application/octet-stream'
self.response.headers['Content-Disposition'] = 'attachment; filename="%s"' % (item.filename)
self.response.out.write(item.contents)
+
+class BulkAction(webapp.RequestHandler):
+ def post(self):
+ action = self.request.get("action")
+ deleted = []
+ if action == "Bulk Delete":
+ keys = self.request.get("bulk-items", allow_multiple=True)
+ for key in keys:
+ item = Content.get(key)
+ deleted.append("User %s, uid %s uploaded on %s: %s with internal key %s" % (item.username, item.uid, item.date, item.filename, key));
+ Content.delete(item)
+
+ template_data = {
+ 'text' : 'Deleted',
+ 'items' : deleted
+ }
+ path = os.path.join(os.path.dirname(__file__), 'templates/dump.html')
+ self.response.out.write(template.render(path, template_data ))
+ else:
+ self.redirect('/list', False)
application = webapp.WSGIApplication([
('/list', ListPage),
('/show/(.*)', ShowPage),
('/delete/(.*)', DeletePage),
- ('/upload', UploadPage)
+ ('/upload', UploadPage),
+ ('/bulk-action.*', BulkAction)
], debug=True)
def main():
From 762a2a1e983ed04f2eab1ea84df8e6d98bef55d2 Mon Sep 17 00:00:00 2001
From: Bindu Wavell
Date: Sun, 20 Mar 2011 16:37:55 -0600
Subject: [PATCH 5/5] added support for application version information
---
app.yaml | 2 +-
static/test.html | 1 +
templates/list.html | 2 +-
upload.py | 2 ++
4 files changed, 5 insertions(+), 2 deletions(-)
diff --git a/app.yaml b/app.yaml
index e8ed2fc..76c1433 100644
--- a/app.yaml
+++ b/app.yaml
@@ -1,5 +1,5 @@
application: fxc-log-service
-version: 1
+version: 2
runtime: python
api_version: 1
diff --git a/static/test.html b/static/test.html
index 0961144..e50bf45 100644
--- a/static/test.html
+++ b/static/test.html
@@ -5,6 +5,7 @@
| username: | |
| uid: | |
| filename: | |
+ | version: | |
| file: | |
diff --git a/templates/list.html b/templates/list.html
index e863bbd..98db96c 100644
--- a/templates/list.html
+++ b/templates/list.html
@@ -41,7 +41,7 @@
diff --git a/upload.py b/upload.py
index d03a692..456cfd3 100644
--- a/upload.py
+++ b/upload.py
@@ -13,6 +13,7 @@ class Content(db.Model):
filename = db.StringProperty()
contents = db.BlobProperty()
date = db.DateTimeProperty(auto_now_add=True)
+ version = db.StringProperty()
class UploadPage(webapp.RequestHandler):
def post(self):
@@ -20,6 +21,7 @@ def post(self):
username=self.request.get("username"),
uid =self.request.get("uid"),
filename=self.request.get("filename"),
+ version =self.request.get("version"),
contents=db.Blob(self.request.get("file"))
)
item.put()