changeset 3868:e262494ca099 beta

store download archive actions in journal
author Marcin Kuzminski <marcin@python-works.com>
date Sun, 19 May 2013 01:36:41 +0200
parents 73f7149f2cc0
children 5cf8947da6d4
files rhodecode/controllers/files.py rhodecode/lib/helpers.py rhodecode/model/db.py
diffstat 3 files changed, 16 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/rhodecode/controllers/files.py	Sun May 19 02:14:51 2013 +0200
+++ b/rhodecode/controllers/files.py	Sun May 19 01:36:41 2013 +0200
@@ -32,7 +32,7 @@
 from pylons import request, response, tmpl_context as c, url
 from pylons.i18n.translation import _
 from pylons.controllers.util import redirect
-from rhodecode.lib.utils import jsonify
+from rhodecode.lib.utils import jsonify, action_logger
 
 from rhodecode.lib import diffs
 from rhodecode.lib import helpers as h
@@ -492,7 +492,10 @@
                         os.remove(archive)
                     break
                 yield data
-
+        # store download action
+        action_logger(user=c.rhodecode_user,
+                      action='user_downloaded_archive:%s' % (archive_name),
+                      repo=repo_name, ipaddr=self.ip_addr, commit=True)
         response.content_disposition = str('attachment; filename=%s' % (archive_name))
         response.content_type = str(content_type)
         return get_chunked_archive(archive)
--- a/rhodecode/lib/helpers.py	Sun May 19 02:14:51 2013 +0200
+++ b/rhodecode/lib/helpers.py	Sun May 19 01:36:41 2013 +0200
@@ -684,6 +684,10 @@
                     url('pullrequest_show', repo_name=repo_name,
                     pull_request_id=pull_request_id))
 
+    def get_archive_name():
+        archive_name = action_params
+        return archive_name
+
     # action : translated str, callback(extractor), icon
     action_map = {
     'user_deleted_repo':           (_('[deleted] repository'),
@@ -696,6 +700,8 @@
                                     get_fork_name, 'arrow_divide.png'),
     'user_updated_repo':           (_('[updated] repository'),
                                     None, 'database_edit.png'),
+    'user_downloaded_archive':      (_('[downloaded] archive from repository'),
+                                    get_archive_name, 'page_white_compressed.png'),
     'admin_deleted_repo':          (_('[delete] repository'),
                                     None, 'database_delete.png'),
     'admin_created_repo':          (_('[created] repository'),
--- a/rhodecode/model/db.py	Sun May 19 02:14:51 2013 +0200
+++ b/rhodecode/model/db.py	Sun May 19 01:36:41 2013 +0200
@@ -613,6 +613,11 @@
     action = Column("action", UnicodeText(1200000, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None)
     action_date = Column("action_date", DateTime(timezone=False), nullable=True, unique=None, default=None)
 
+    def __unicode__(self):
+        return u"<%s('id:%s:%s')>" % (self.__class__.__name__,
+                                      self.repository_name,
+                                      self.action)
+
     @property
     def action_as_day(self):
         return datetime.date(*self.action_date.timetuple()[:3])