diff --git a/pylons_app/controllers/admin/repos.py b/pylons_app/controllers/admin/repos.py --- a/pylons_app/controllers/admin/repos.py +++ b/pylons_app/controllers/admin/repos.py @@ -32,7 +32,7 @@ from pylons_app.lib import helpers as h from pylons_app.lib.auth import LoginRequired, HasPermissionAllDecorator, \ HasPermissionAnyDecorator from pylons_app.lib.base import BaseController, render -from pylons_app.lib.utils import invalidate_cache +from pylons_app.lib.utils import invalidate_cache, action_logger from pylons_app.model.db import User from pylons_app.model.forms import RepoForm from pylons_app.model.hg_model import HgModel @@ -77,13 +77,20 @@ class ReposController(BaseController): invalidate_cache('cached_repo_list') h.flash(_('created repository %s') % form_result['repo_name'], category='success') - + + if request.POST.get('user_created'): + action_logger(self.hg_app_user, 'user_created_repo', + form_result['repo_name'], '', self.sa) + else: + action_logger(self.hg_app_user, 'admin_created_repo', + form_result['repo_name'], '', self.sa) + except formencode.Invalid as errors: c.new_repo = errors.value['repo_name'] if request.POST.get('user_created'): r = render('admin/repos/repo_add_create_repository.html') - else: + else: r = render('admin/repos/repo_add.html') return htmlfill.render( @@ -169,10 +176,14 @@ class ReposController(BaseController): return redirect(url('repos')) try: + action_logger(self.hg_app_user, 'admin_deleted_repo', + repo_name, '', self.sa) repo_model.delete(repo) invalidate_cache('cached_repo_list') h.flash(_('deleted repository %s') % repo_name, category='success') - except Exception: + + except Exception, e: + log.error(traceback.format_exc()) h.flash(_('An error occured during deletion of %s') % repo_name, category='error') diff --git a/pylons_app/controllers/admin/settings.py b/pylons_app/controllers/admin/settings.py --- a/pylons_app/controllers/admin/settings.py +++ b/pylons_app/controllers/admin/settings.py @@ -101,7 +101,7 @@ class SettingsController(BaseController) initial = HgModel.repo_scan(g.paths[0][0], g.paths[0][1], g.baseui) repo2db_mapper(initial, rm_obsolete) invalidate_cache('cached_repo_list') - h.flash(_('Repositories sucessfully rescanned'), category='success') + h.flash(_('Repositories successfully rescanned'), category='success') if setting_id == 'whoosh': repo_location = get_hg_ui_settings()['paths_root_path'] @@ -134,7 +134,7 @@ class SettingsController(BaseController) except: log.error(traceback.format_exc()) - h.flash(_('error occured during updating application settings'), + h.flash(_('error occurred during updating application settings'), category='error') self.sa.rollback() @@ -187,7 +187,7 @@ class SettingsController(BaseController) except: log.error(traceback.format_exc()) - h.flash(_('error occured during updating application settings'), + h.flash(_('error occurred during updating application settings'), category='error') self.sa.rollback() diff --git a/pylons_app/controllers/admin/users.py b/pylons_app/controllers/admin/users.py --- a/pylons_app/controllers/admin/users.py +++ b/pylons_app/controllers/admin/users.py @@ -17,6 +17,7 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, # MA 02110-1301, USA. +from pylons_app.lib.utils import action_logger """ Created on April 4, 2010 users controller for pylons @@ -71,6 +72,7 @@ class UsersController(BaseController): user_model.create(form_result) h.flash(_('created user %s') % form_result['username'], category='success') + #action_logger(self.hg_app_user, 'new_user', '', '', self.sa) except formencode.Invalid as errors: return htmlfill.render( render('admin/users/user_add.html'), diff --git a/pylons_app/controllers/settings.py b/pylons_app/controllers/settings.py --- a/pylons_app/controllers/settings.py +++ b/pylons_app/controllers/settings.py @@ -28,7 +28,7 @@ from pylons.controllers.util import redi from pylons.i18n.translation import _ from pylons_app.lib.auth import LoginRequired, HasRepoPermissionAllDecorator from pylons_app.lib.base import BaseController, render -from pylons_app.lib.utils import invalidate_cache +from pylons_app.lib.utils import invalidate_cache, action_logger from pylons_app.model.forms import RepoSettingsForm, RepoForkForm from pylons_app.model.repo_model import RepoModel import formencode @@ -79,7 +79,7 @@ class SettingsController(BaseController) form_result = _form.to_python(dict(request.POST)) repo_model.update(repo_name, form_result) invalidate_cache('cached_repo_list') - h.flash(_('Repository %s updated succesfully' % repo_name), + h.flash(_('Repository %s updated successfully' % repo_name), category='success') changed_name = form_result['repo_name'] except formencode.Invalid as errors: @@ -121,11 +121,13 @@ class SettingsController(BaseController) return redirect(url('hg_home')) try: + action_logger(self.hg_app_user, 'user_deleted_repo', + repo_name, '', self.sa) repo_model.delete(repo) invalidate_cache('cached_repo_list') h.flash(_('deleted repository %s') % repo_name, category='success') except Exception: - h.flash(_('An error occured during deletion of %s') % repo_name, + h.flash(_('An error occurred during deletion of %s') % repo_name, category='error') return redirect(url('hg_home')) @@ -158,7 +160,8 @@ class SettingsController(BaseController) h.flash(_('fork %s repository as %s task added') \ % (repo_name, form_result['fork_name']), category='success') - + action_logger(self.hg_app_user, 'user_forked_repo', + repo_name, '', self.sa) except formencode.Invalid as errors: c.new_repo = errors.value['fork_name'] r = render('settings/repo_fork.html') diff --git a/pylons_app/lib/base.py b/pylons_app/lib/base.py --- a/pylons_app/lib/base.py +++ b/pylons_app/lib/base.py @@ -40,7 +40,7 @@ class BaseController(WSGIController): # available in environ['pylons.routes_dict'] try: #putting this here makes sure that we update permissions every time - c.hg_app_user = auth.get_user(session) + self.hg_app_user = c.hg_app_user = auth.get_user(session) return WSGIController.__call__(self, environ, start_response) finally: meta.Session.remove() diff --git a/pylons_app/lib/utils.py b/pylons_app/lib/utils.py --- a/pylons_app/lib/utils.py +++ b/pylons_app/lib/utils.py @@ -26,7 +26,7 @@ from beaker.cache import cache_region from mercurial import ui, config, hg from mercurial.error import RepoError from pylons_app.model import meta -from pylons_app.model.db import Repository, User, HgAppUi, HgAppSettings,UserLog +from pylons_app.model.db import Repository, User, HgAppUi, HgAppSettings, UserLog from vcs.backends.base import BaseChangeset from vcs.utils.lazy import LazyProperty import logging @@ -57,21 +57,21 @@ def action_logger(user, action, repo, ip if not sa: sa = meta.Session - - if hasattr(user, 'user_id'): - user_id = user.user_id - elif isinstance(user, basestring): - - user_id = sa.Query(User).filter(User.username == user).one() - else: - raise Exception('You have to provide user object or username') - try: + if hasattr(user, 'user_id'): + user_id = user.user_id + elif isinstance(user, basestring): + user_id = sa.query(User).filter(User.username == user).one() + else: + raise Exception('You have to provide user object or username') + + repo_name = repo.lstrip('/') user_log = UserLog() user_log.user_id = user_id user_log.action = action + user_log.repository_name = repo_name user_log.repository = sa.query(Repository)\ - .filter(Repository.repo_name==repo.lstrip('/')).one() + .filter(Repository.repo_name == repo_name).one() user_log.action_date = datetime.datetime.now() user_log.user_ip = ipaddr sa.add(user_log) diff --git a/pylons_app/model/db.py b/pylons_app/model/db.py --- a/pylons_app/model/db.py +++ b/pylons_app/model/db.py @@ -66,7 +66,8 @@ class UserLog(Base): __table_args__ = {'useexisting':True} user_log_id = Column("user_log_id", INTEGER(), nullable=False, unique=True, default=None, primary_key=True) user_id = Column("user_id", INTEGER(), ForeignKey(u'users.user_id'), nullable=False, unique=None, default=None) - repository_id = Column("repository", TEXT(length=None, convert_unicode=False, assert_unicode=None), ForeignKey(u'repositories.repo_id'), nullable=False, unique=None, default=None) + repository_id = Column("repository_id", INTEGER(length=None, convert_unicode=False, assert_unicode=None), ForeignKey(u'repositories.repo_id'), nullable=False, unique=None, default=None) + repository_name = Column("repository_name", TEXT(length=None, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None) user_ip = Column("user_ip", TEXT(length=None, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None) action = Column("action", TEXT(length=None, 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) diff --git a/pylons_app/templates/admin/admin_log.html b/pylons_app/templates/admin/admin_log.html --- a/pylons_app/templates/admin/admin_log.html +++ b/pylons_app/templates/admin/admin_log.html @@ -12,7 +12,13 @@ %for cnt,l in enumerate(c.users_log):