Skip to content
This repository has been archived by the owner on Oct 27, 2019. It is now read-only.

Commit

Permalink
HUE-87. Incorporating review feedback, adding access to 'last access …
Browse files Browse the repository at this point in the history
…time'
  • Loading branch information
vinithra committed Aug 2, 2010
1 parent f700285 commit 1dfb687
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 16 deletions.
4 changes: 2 additions & 2 deletions README.testing
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,13 @@ E.g.
build/env/bin/hue test specific useradmin.tests:test_user_admin

Start up pdb on test failures:
build/env/bin/hue test <args> --pdb --pdb-failure
build/env/bin/hue test <args> --pdb --pdb-failure -s


Special environment variables
=============================

DESKTOP_LOG_LEVEL=<level>
DESKTOP_LOGLEVEL=<level>
level can be DEBUG, INFO, WARN, ERROR, or CRITICAL

When specified, the console logger is set to the given log level. A console
Expand Down
24 changes: 13 additions & 11 deletions desktop/core/src/desktop/auth/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@
from desktop.auth.backend import AllowFirstUserDjangoBackend
from desktop.lib.django_util import render_json, render
from desktop.lib.django_util import login_notrequired
from desktop.log.access import access_warn, recent_access_map, remote_ip_map
from userman.models import UserProfile
from desktop.log.access import access_warn, remote_ip_map, recent_access_time_map

LOG = logging.getLogger(__name__)

Expand Down Expand Up @@ -63,16 +62,19 @@ def login_form(request):


def get_current_users():
"""Return current users by inspecting sessions"""
_current_users = { }
"""Return dictionary of User objects and
a dictionary of the user's IP address and last access time"""
current_users = { }
for session in Session.objects.all():
uid = session.get_decoded().get('_auth_user_id')
if uid != None:
userobj = User.objects.get(pk=uid)
profile = UserProfile.objects.get(user=userobj)
_current_users[userobj] = remote_ip_map.get(userobj.username, { })

return _current_users
uid = session.get_decoded().get(django.contrib.auth.SESSION_KEY)
if uid is not None:
try:
userobj = User.objects.get(pk=uid)
except User.DoesNotExist:
LOG.debug("User with id=%d does not exist" % uid)
current_users[userobj] = {'ip':remote_ip_map.get(userobj.username, ''), 'time':recent_access_time_map.get(userobj.username, '')}

return current_users


@login_notrequired
Expand Down
9 changes: 6 additions & 3 deletions desktop/core/src/desktop/log/access.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,12 @@ def deco_view(func):
_recent_access_map_lk = threading.Lock()
_per_user_lk = { } # Indexed by username

# Store the IP address of users
# Store a map of usernames and their IP addresses
remote_ip_map = { }

# Store a map of usernames and last access times
recent_access_time_map = { }

# Max number of records per user per view to keep
_USER_ACCESS_HISTORY_SIZE = desktop.conf.USER_ACCESS_HISTORY_SIZE.get()

Expand Down Expand Up @@ -100,8 +103,9 @@ def add_to_access_history(self, app):
app_dict = { }
_per_user_lk[user] = threading.Lock()
recent_access_map[user] = app_dict
# Update the IP address of the user
# Update the IP address and last access time of the user
remote_ip_map[user] = self['remote_ip']
recent_access_time_map[user] = self['time']
finally:
_recent_access_map_lk.release()

Expand Down Expand Up @@ -138,7 +142,6 @@ def log_page_hit(request, view_func, level=None):
level = logging.INFO
ai = AccessInfo(request)
ai.log(level)
ai['remote_ip'] = request.META.get('REMOTE_ADDR', '-')
# Find the app
app_re_match = _MODULE_RE.match(view_func.__module__)
app = app_re_match and app_re_match.group(0) or '-'
Expand Down

0 comments on commit 1dfb687

Please sign in to comment.