Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add management view.

  • Loading branch information...
commit 056308689928421552923e6fefab08cc9d1d83ae 1 parent d360f0b
Chris McDonough authored
View
5 cluegun.ini
@@ -5,9 +5,14 @@ debug = true
use = egg:repoze.cluegun#make_app
db_path = %(here)s/cluegun.db
+[filter:who]
+use = egg:repoze.who#config
+config_file = %(here)s/who.ini
+
[pipeline:main]
pipeline = egg:repoze.tm2#tm
# egg:repoze.profile#profile
+ who
cluegun
[server:main]
View
1  cluegun.passwd
@@ -0,0 +1 @@
+admin:admin
View
24 repoze/cluegun/configure.zcml
@@ -6,18 +6,40 @@
<bfg:view
for=".models.IPasteBin"
+ view=".views.index_view"
+ permission="view"
+ />
+
+ <bfg:view
+ for=".models.IPasteBin"
+ view=".views.manage_view"
+ name="manage"
+ permission="manage"
+ />
+
+ <bfg:view
+ for=".models.IPasteBin"
view=".views.static_view"
name="static"
+ permission="view"
/>
<bfg:view
for=".models.IPasteBin"
- view=".views.index_view"
+ view=".views.logout_view"
+ name="logout"
+ permission="view"
/>
<bfg:view
for=".models.IPasteEntry"
view=".views.entry_view"
+ permission="view"
/>
+ <utility
+ provides="repoze.bfg.interfaces.ISecurityPolicy"
+ factory="repoze.bfg.security.RemoteUserACLSecurityPolicy"
+ />
+
</configure>
View
4 repoze/cluegun/models.py
@@ -8,11 +8,15 @@
from zope.interface import implements
from zope.location.interfaces import ILocation
+from repoze.bfg.security import Allow
+from repoze.bfg.security import Everyone
+
class IPasteBin(Interface):
pass
class PasteBin(PersistentMapping):
implements(IPasteBin, ILocation)
+ __acl__ = [ (Allow, Everyone, 'view'), (Allow, 'manager', 'manage') ]
current_id = -1
View
40 repoze/cluegun/templates/add.pt
@@ -1,40 +0,0 @@
-<div xmlns="http://www.w3.org/1999/xhtml"
- xmlns:tal="http://xml.zope.org/namespaces/tal">
-<form action="." method="POST">
- <input type="hidden" name="form.submitted"/>
- <fieldset>
- <legend>Paste Info</legend>
- <div class="field">
- <label for="author_name">Name</label>
- <input type="text" name="author_name" value="${author_name}" />
- </div>
- <div class="field">
- <label for="language">Language</label>
- <select name="language">
- <option value="" selected="selected">-- Auto detect --</option>
- <option tal:repeat="lexer lexers"
- value="${lexer.alias}"
- >${lexer.name}</option>
- </select>
- </div>
- <div class="field">
- <label for="paste">Paste Text</label>
- <textarea name="paste">${paste}</textarea>
- </div>
- <input type="submit" />
- </fieldset>
-</form>
-
-<div class="right" tal:condition="pastes">
- <fieldset>
- <legend>Previous Pastes</legend>
- <ul>
- <li tal:repeat="paste pastes">
- <a href="${paste.url}"
- >By: ${paste.author} on ${paste.date}</a>
- </li>
- </ul>
- </fieldset>
-</div>
-
-</div>
View
5 repoze/cluegun/templates/index.pt
@@ -15,6 +15,11 @@
<div class="message" tal:condition="message|nothing"
tal:content="message">Error message</div>
+ <div class="userinfo" tal:condition="user">
+ You are currently logged in as <b>${user}</b>
+ <a href="${application_url}/logout">Log Out</a>
+ </div>
+
<div class="left">
<form action="." method="POST">
View
42 repoze/cluegun/templates/manage.pt
@@ -0,0 +1,42 @@
+<html xmlns="http://www.w3.org/1999/xhtml"
+ xmlns:tal="http://xml.zope.org/namespaces/tal">
+ <head>
+ <title>ClueGun pastebin management</title>
+ <link rel="stylesheet" type="text/css"
+ href="${application_url}/static/styles.css" />
+ </head>
+ <body>
+ <div id="main">
+
+ <div class="header">ClueGun ${version} by <a
+ href="http://repoze.org" >Agendaless Consulting</a> (based on ClueBin by <a
+ href="http://www.serverzen.com">ServerZen Software</a>).
+ </div>
+
+ <a href="..">Main page</a>
+
+
+ <div class="left" tal:condition="pastes">
+
+ <fieldset>
+ <legend>Delete Pastes</legend>
+ <form action="${application_url}/manage" method="POST">
+ <ul>
+ <li tal:repeat="paste pastes">
+ <input type="checkbox" name="delete:list"
+ value="${paste.name}"/>
+ <a href="${paste.url}"
+ >By: ${paste.author} on ${paste.date}</a>
+ </li>
+ </ul>
+ <input type="submit" name="form.submitted" value="Delete"/>
+ </form>
+ </fieldset>
+ </div>
+
+ <div class="clear">
+
+ </div>
+ </div>
+ </body>
+</html>
View
41 repoze/cluegun/views.py
@@ -11,11 +11,13 @@
from pygments import formatters
from pygments import util
-
from repoze.bfg.wsgi import wsgiapp
from repoze.bfg.template import render_template_to_response
from repoze.bfg.template import render_template
from repoze.bfg.traversal import find_interface
+from repoze.bfg.security import authenticated_userid
+from repoze.bfg.security import has_permission
+from repoze.monty import marshal
from repoze.cluegun.models import PasteEntry
from repoze.cluegun.models import IPasteBin
@@ -43,7 +45,8 @@ def get_pastes(context, request):
else:
pdate = 'UNKNOWN'
paste_url = urlparse.urljoin(app_url, name)
- new = {'author':entry.author_name, 'date':pdate, 'url':paste_url}
+ new = {'author':entry.author_name, 'date':pdate, 'url':paste_url,
+ 'name':name}
pastes.append(new)
return pastes
@@ -103,6 +106,8 @@ def index_view(context, request):
message = u''
response = webob.Response()
app_url = request.application_url
+ user = authenticated_userid(request)
+ can_manage = has_permission('manage', context, request)
if params.has_key('form.submitted'):
paste = request.params.get('paste', '')
@@ -141,9 +146,41 @@ def index_view(context, request):
message = message,
pastes = pastes,
application_url = app_url,
+ user = user,
+ can_manage = can_manage,
)
response.unicode_body = unicode(body)
return response
+def manage_view(context, request):
+ params = request.params
+ message = u''
+ response = webob.Response()
+ app_url = request.application_url
+
+ if params.has_key('form.submitted'):
+ form = marshal(request.environ, request.body_file)
+ checkboxes = form.get('delete', [])
+ for checkbox in checkboxes:
+ del context[checkbox]
+ message = '%s pastes deleted' % len(checkboxes)
+ response.status = '301 Moved Permanently'
+ response.headers['Location'] = app_url
+
+ pastes = get_pastes(context, request)
+
+ body = render_template(
+ 'templates/manage.pt',
+ version = app_version,
+ pastes = pastes,
+ application_url = app_url,
+ )
+ response.unicode_body = unicode(body)
+ return response
+def logout_view(context, request):
+ response = webob.Response()
+ response.status = '401 Unauthorized'
+ return response
+
View
4 setup.py
@@ -57,12 +57,16 @@ def get_version():
tests_require = [
'repoze.bfg',
'repoze.tm2',
+ 'repoze.monty',
+ 'repoze.who',
'ZODB3',
'Pygments',
],
install_requires=[
'repoze.bfg',
'repoze.tm2',
+ 'repoze.monty',
+ 'repoze.who',
'ZODB3',
'Pygments',
],
View
40 who.ini
@@ -0,0 +1,40 @@
+[plugin:form]
+# identification and challenge
+use = repoze.who.plugins.form:make_plugin
+login_form_qs = __do_login
+rememberer_name = auth_tkt
+
+[plugin:auth_tkt]
+# identification
+use = repoze.who.plugins.auth_tkt:make_plugin
+secret = s33kr1t
+cookie_name = oatmeal
+secure = False
+include_ip = False
+
+[plugin:htpasswd]
+# authentication
+use = repoze.who.plugins.htpasswd:make_plugin
+filename = %(here)s/cluegun.passwd
+check_fn = repoze.who.plugins.htpasswd:plain_check
+
+[general]
+request_classifier = repoze.who.classifiers:default_request_classifier
+challenge_decider = repoze.who.classifiers:default_challenge_decider
+
+[identifiers]
+# plugin_name;classifier_name:.. or just plugin_name (good for any)
+plugins =
+ form;browser
+ auth_tkt
+
+[authenticators]
+# plugin_name;classifier_name.. or just plugin_name (good for any)
+plugins =
+ htpasswd
+
+[challengers]
+# plugin_name;classifier_name:.. or just plugin_name (good for any)
+plugins =
+ form
+
Please sign in to comment.
Something went wrong with that request. Please try again.