[PATCH] I added the "Admin" button to the smug menu.

2 views
Skip to first unread message

James Carroll

unread,
Feb 18, 2009, 5:37:22 PM2/18/09
to smug...@googlegroups.com
If the user is logged on. They can over-ride the url that the admin
button points to with a line in the django settings. The defailt is
used if there is no line in the admin settings, with the default being
django's /admin/ default location.

Currently, you have to be logged on for the admin button to appear, it
doesn't force you to be staff for it to appear, but unless you changed
django's default admin permissions, the button may appear, but you
will get a permission denied if you try to go there and aren't staff.
I can add a check to see if you are staff if everyone wants, but that
is just one more check that has to happen to slow things down. Does it
really hurt to have it appear for logged on users who can't use it?

James
---
smug/config.py | 3 +++
smug/menu.py | 5 +++++
2 files changed, 8 insertions(+), 0 deletions(-)

diff --git a/smug/config.py b/smug/config.py
index 38b772c..c1857bc 100644
--- a/smug/config.py
+++ b/smug/config.py
@@ -21,6 +21,7 @@ DEFAULT_CACHE_TIME = 30 * 60
DEFAULT_HEAD_TIMEOUT = 20
# An alternative DEFAULT_MIMETYPE would be application/octet-stream
DEFAULT_MIMETYPE = 'text/plain'
+DEFAULT_ADMIN_URL = '/admin/'

from django.conf import settings
import gitlib
@@ -42,5 +43,7 @@ basetemplate = _get_setting('SMUG_TEMPLATE', DEFAULT_TEMPLATE)
cache_time = _get_setting('SMUG_CACHE_TIME', DEFAULT_CACHE_TIME)
# How long to cache the head ref.
head_timeout = _get_setting('SMUG_HEAD_TIMEOUT', DEFAULT_HEAD_TIMEOUT)
+# Admin directory (note, None means admin not installed)
+admin_url = _get_setting('ADMIN_URL', DEFAULT_ADMIN_URL)

# vim: et sw=4 sts=4
diff --git a/smug/menu.py b/smug/menu.py
index 024611a..008babc 100644
--- a/smug/menu.py
+++ b/smug/menu.py
@@ -18,6 +18,7 @@

from django.contrib.auth import REDIRECT_FIELD_NAME
from itertools import chain
+import config

class SmugMenu(object):
"""Manage a menu of Smug actions."""
@@ -31,10 +32,14 @@ class SmugMenu(object):

redirect = '/%s%s' % (basepath, page)
if self.authenticated:
+ # place the logout button
# TODO: make this configurable
# note: if you leave off the redirect, it will do a logout page
url = '/%s:logout?%s=%s' % (basepath,
REDIRECT_FIELD_NAME, redirect)
self.lastitems.append(('Logout(%s)' %
(request.user.username), url))
+ # place the admin button
+ if config.admin_url is not None:
+ self.lastitems.append(('Admin',config.admin_url))
else:
url = '/%s:login?%s=%s' % (basepath, REDIRECT_FIELD_NAME, redirect)
self.lastitems.append(('Login', url))
--
1.5.4.3

~
~
~

--
"And very early in the morning
the first day of the week,
they came unto the sepulchre
at the rising of the sun..." (Mark 16:2)

Web: http://james.jlcarroll.net

Andrew McNabb

unread,
Mar 2, 2009, 10:06:53 AM3/2/09
to smug...@googlegroups.com
Thanks for the patch, James. I just committed it and pushed it. Since
no one commented on the question of whether to include the button for
non-staff users, I'm sticking with what you submitted.

By the way, I did have a problem applying the patch because a few lines
were split by your email program into two shorter lines. This confused
the patch program, so I had to join the lines manually.

Thanks for your contribution.

On Wed, Feb 18, 2009 at 03:37:22PM -0700, James Carroll wrote:
>
> If the user is logged on. They can over-ride the url that the admin
> button points to with a line in the django settings. The defailt is
> used if there is no line in the admin settings, with the default being
> django's /admin/ default location.
>
> Currently, you have to be logged on for the admin button to appear, it
> doesn't force you to be staff for it to appear, but unless you changed
> django's default admin permissions, the button may appear, but you
> will get a permission denied if you try to go there and aren't staff.
> I can add a check to see if you are staff if everyone wants, but that
> is just one more check that has to happen to slow things down. Does it
> really hurt to have it appear for logged on users who can't use it?


--
Andrew McNabb
http://www.mcnabbs.org/andrew/
PGP Fingerprint: 8A17 B57C 6879 1863 DE55 8012 AB4D 6098 8826 6868

Reply all
Reply to author
Forward
0 new messages