diff --git a/rhodecode/controllers/admin/repos.py b/rhodecode/controllers/admin/repos.py --- a/rhodecode/controllers/admin/repos.py +++ b/rhodecode/controllers/admin/repos.py @@ -151,10 +151,12 @@ class ReposController(BaseController): if request.POST.get('user_created'): # created by regular non admin user action_logger(self.rhodecode_user, 'user_created_repo', - form_result['repo_name_full'], '', self.sa) + form_result['repo_name_full'], self.ip_addr, + self.sa) else: action_logger(self.rhodecode_user, 'admin_created_repo', - form_result['repo_name_full'], '', self.sa) + form_result['repo_name_full'], self.ip_addr, + self.sa) Session.commit() except formencode.Invalid, errors: @@ -212,7 +214,7 @@ class ReposController(BaseController): category='success') changed_name = repo.repo_name action_logger(self.rhodecode_user, 'admin_updated_repo', - changed_name, '', self.sa) + changed_name, self.ip_addr, self.sa) Session.commit() except formencode.Invalid, errors: defaults = self.__load_data(repo_name) @@ -253,7 +255,7 @@ class ReposController(BaseController): return redirect(url('repos')) try: action_logger(self.rhodecode_user, 'admin_deleted_repo', - repo_name, '', self.sa) + repo_name, self.ip_addr, self.sa) repo_model.delete(repo) invalidate_cache('get_repo_cached_%s' % repo_name) h.flash(_('deleted repository %s') % repo_name, category='success') diff --git a/rhodecode/controllers/admin/users.py b/rhodecode/controllers/admin/users.py --- a/rhodecode/controllers/admin/users.py +++ b/rhodecode/controllers/admin/users.py @@ -42,6 +42,7 @@ from rhodecode.model.db import User, Per from rhodecode.model.forms import UserForm from rhodecode.model.user import UserModel from rhodecode.model.meta import Session +from rhodecode.lib.utils import action_logger log = logging.getLogger(__name__) @@ -76,10 +77,12 @@ class UsersController(BaseController): try: form_result = user_form.to_python(dict(request.POST)) user_model.create(form_result) - h.flash(_('created user %s') % form_result['username'], + usr = form_result['username'] + action_logger(self.rhodecode_user, 'admin_created_user:%s' % usr, + None, self.ip_addr, self.sa) + h.flash(_('created user %s') % usr, category='success') Session.commit() - #action_logger(self.rhodecode_user, 'new_user', '', '', self.sa) except formencode.Invalid, errors: return htmlfill.render( render('admin/users/user_add.html'), @@ -115,6 +118,9 @@ class UsersController(BaseController): try: form_result = _form.to_python(dict(request.POST)) user_model.update(id, form_result) + usr = form_result['username'] + action_logger(self.rhodecode_user, 'admin_updated_user:%s' % usr, + None, self.ip_addr, self.sa) h.flash(_('User updated successfully'), category='success') Session.commit() except formencode.Invalid, errors: diff --git a/rhodecode/controllers/admin/users_groups.py b/rhodecode/controllers/admin/users_groups.py --- a/rhodecode/controllers/admin/users_groups.py +++ b/rhodecode/controllers/admin/users_groups.py @@ -43,6 +43,7 @@ from rhodecode.model.users_group import from rhodecode.model.db import User, UsersGroup, Permission, UsersGroupToPerm from rhodecode.model.forms import UsersGroupForm from rhodecode.model.meta import Session +from rhodecode.lib.utils import action_logger log = logging.getLogger(__name__) @@ -76,9 +77,11 @@ class UsersGroupsController(BaseControll form_result = users_group_form.to_python(dict(request.POST)) UsersGroupModel().create(name=form_result['users_group_name'], active=form_result['users_group_active']) - h.flash(_('created users group %s') \ - % form_result['users_group_name'], category='success') - #action_logger(self.rhodecode_user, 'new_user', '', '', self.sa) + gr = form_result['users_group_name'] + action_logger(self.rhodecode_user, + 'admin_created_users_group:%s' % gr, + None, self.ip_addr, self.sa) + h.flash(_('created users group %s') % gr, category='success') Session.commit() except formencode.Invalid, errors: return htmlfill.render( @@ -125,10 +128,11 @@ class UsersGroupsController(BaseControll try: form_result = users_group_form.to_python(request.POST) UsersGroupModel().update(c.users_group, form_result) - h.flash(_('updated users group %s') \ - % form_result['users_group_name'], - category='success') - #action_logger(self.rhodecode_user, 'new_user', '', '', self.sa) + gr = form_result['users_group_name'] + action_logger(self.rhodecode_user, + 'admin_updated_users_group:%s' % gr, + None, self.ip_addr, self.sa) + h.flash(_('updated users group %s') % gr, category='success') Session.commit() except formencode.Invalid, errors: e = errors.error_dict or {} diff --git a/rhodecode/controllers/changeset.py b/rhodecode/controllers/changeset.py --- a/rhodecode/controllers/changeset.py +++ b/rhodecode/controllers/changeset.py @@ -40,7 +40,7 @@ from rhodecode.lib.vcs.nodes import File import rhodecode.lib.helpers as h from rhodecode.lib.auth import LoginRequired, HasRepoPermissionAnyDecorator from rhodecode.lib.base import BaseRepoController, render -from rhodecode.lib.utils import EmptyChangeset +from rhodecode.lib.utils import EmptyChangeset, action_logger from rhodecode.lib.compat import OrderedDict from rhodecode.lib import diffs from rhodecode.model.db import ChangesetComment @@ -373,7 +373,12 @@ class ChangesetController(BaseRepoContro f_path=request.POST.get('f_path'), line_no=request.POST.get('line') ) + action_logger(self.rhodecode_user, + 'user_commented_revision:%s' % revision, + c.rhodecode_db_repo, self.ip_addr, self.sa) + Session.commit() + if not request.environ.get('HTTP_X_PARTIAL_XHR'): return redirect(h.url('changeset_home', repo_name=repo_name, revision=revision)) diff --git a/rhodecode/controllers/journal.py b/rhodecode/controllers/journal.py --- a/rhodecode/controllers/journal.py +++ b/rhodecode/controllers/journal.py @@ -192,7 +192,6 @@ class JournalController(BaseController): ttl=self.ttl) for entry in journal[:self.feed_nr]: - #tmpl = h.action_parser(entry)[0] action, action_extra = h.action_parser(entry, feed=True) title = "%s - %s %s" % (entry.user.short_contact, action, entry.repository.repo_name) @@ -226,7 +225,6 @@ class JournalController(BaseController): ttl=self.ttl) for entry in journal[:self.feed_nr]: - #tmpl = h.action_parser(entry)[0] action, action_extra = h.action_parser(entry, feed=True) title = "%s - %s %s" % (entry.user.short_contact, action, entry.repository.repo_name) diff --git a/rhodecode/controllers/settings.py b/rhodecode/controllers/settings.py --- a/rhodecode/controllers/settings.py +++ b/rhodecode/controllers/settings.py @@ -104,7 +104,7 @@ class SettingsController(BaseRepoControl category='success') changed_name = form_result['repo_name_full'] action_logger(self.rhodecode_user, 'user_updated_repo', - changed_name, '', self.sa) + changed_name, self.ip_addr, self.sa) Session.commit() except formencode.Invalid, errors: c.repo_info = repo_model.get_by_repo_name(repo_name) @@ -145,7 +145,7 @@ class SettingsController(BaseRepoControl return redirect(url('home')) try: action_logger(self.rhodecode_user, 'user_deleted_repo', - repo_name, '', self.sa) + repo_name, self.ip_addr, self.sa) repo_model.delete(repo) invalidate_cache('get_repo_cached_%s' % repo_name) h.flash(_('deleted repository %s') % repo_name, category='success') diff --git a/rhodecode/lib/helpers.py b/rhodecode/lib/helpers.py --- a/rhodecode/lib/helpers.py +++ b/rhodecode/lib/helpers.py @@ -537,22 +537,57 @@ def action_parser(user_log, feed=False): return _('fork name ') + str(link_to(action_params, url('summary_home', repo_name=repo_name,))) - action_map = {'user_deleted_repo': (_('[deleted] repository'), None), - 'user_created_repo': (_('[created] repository'), None), - 'user_created_fork': (_('[created] repository as fork'), None), - 'user_forked_repo': (_('[forked] repository'), get_fork_name), - 'user_updated_repo': (_('[updated] repository'), None), - 'admin_deleted_repo': (_('[delete] repository'), None), - 'admin_created_repo': (_('[created] repository'), None), - 'admin_forked_repo': (_('[forked] repository'), None), - 'admin_updated_repo': (_('[updated] repository'), None), - 'push': (_('[pushed] into'), get_cs_links), - 'push_local': (_('[committed via RhodeCode] into'), get_cs_links), - 'push_remote': (_('[pulled from remote] into'), get_cs_links), - 'pull': (_('[pulled] from'), None), - 'started_following_repo': (_('[started following] repository'), None), - 'stopped_following_repo': (_('[stopped following] repository'), None), - } + def get_user_name(): + user_name = action_params + return user_name + + def get_users_group(): + group_name = action_params + return group_name + + # action : translated str, callback(extractor), icon + action_map = { + 'user_deleted_repo': (_('[deleted] repository'), None, + 'database_delete.png'), + 'user_created_repo': (_('[created] repository'), None, + 'database_add.png'), + 'user_created_fork': (_('[created] repository as fork'), None, + 'arrow_divide.png'), + 'user_forked_repo': (_('[forked] repository'), get_fork_name, + 'arrow_divide.png'), + 'user_updated_repo': (_('[updated] repository'), None, + 'database_edit.png'), + 'admin_deleted_repo': (_('[delete] repository'), None, + 'database_delete.png'), + 'admin_created_repo': (_('[created] repository'), None, + 'database_add.png'), + 'admin_forked_repo': (_('[forked] repository'), None, + 'arrow_divide.png'), + 'admin_updated_repo': (_('[updated] repository'), None, + 'database_edit.png'), + 'admin_created_user': (_('[created] user'), get_user_name, + 'user_add.png'), + 'admin_updated_user': (_('[updated] user'), get_user_name, + 'user_edit.png'), + 'admin_created_users_group': (_('[created] users group'), get_users_group, + 'group_add.png'), + 'admin_updated_users_group': (_('[updated] users group'), get_users_group, + 'group_edit.png'), + 'user_commented_revision': (_('[commented] on revision'), get_cs_links, + 'comment_add.png'), + 'push': (_('[pushed] into'), get_cs_links, + 'script_add.png'), + 'push_local': (_('[committed via RhodeCode] into'), get_cs_links, + 'script_edit.png'), + 'push_remote': (_('[pulled from remote] into'), get_cs_links, + 'connect.png'), + 'pull': (_('[pulled] from'), None, + 'down_16.png'), + 'started_following_repo': (_('[started following] repository'), None, + 'heart_add.png'), + 'stopped_following_repo': (_('[stopped following] repository'), None, + 'heart_delete.png'), + } action_str = action_map.get(action, action) if feed: @@ -567,36 +602,21 @@ def action_parser(user_log, feed=False): if callable(action_str[1]): action_params_func = action_str[1] - return [literal(action), action_params_func] - + def action_parser_icon(): + action = user_log.action + action_params = None + x = action.split(':') -def action_parser_icon(user_log): - action = user_log.action - action_params = None - x = action.split(':') - - if len(x) > 1: - action, action_params = x + if len(x) > 1: + action, action_params = x - tmpl = """""" - map = {'user_deleted_repo':'database_delete.png', - 'user_created_repo':'database_add.png', - 'user_created_fork':'arrow_divide.png', - 'user_forked_repo':'arrow_divide.png', - 'user_updated_repo':'database_edit.png', - 'admin_deleted_repo':'database_delete.png', - 'admin_created_repo':'database_add.png', - 'admin_forked_repo':'arrow_divide.png', - 'admin_updated_repo':'database_edit.png', - 'push':'script_add.png', - 'push_local':'script_edit.png', - 'push_remote':'connect.png', - 'pull':'down_16.png', - 'started_following_repo':'heart_add.png', - 'stopped_following_repo':'heart_delete.png', - } - return literal(tmpl % ((url('/images/icons/')), - map.get(action, action), action)) + tmpl = """""" + ico = action_map.get(action, ['', '', ''])[2] + return literal(tmpl % ((url('/images/icons/')), ico, action)) + + # returned callbacks we need to call to get + return [lambda: literal(action), action_params_func, action_parser_icon] + #============================================================================== diff --git a/rhodecode/lib/utils.py b/rhodecode/lib/utils.py --- a/rhodecode/lib/utils.py +++ b/rhodecode/lib/utils.py @@ -146,13 +146,14 @@ def action_logger(user, action, repo, ip repo_name = repo.lstrip('/') repo_obj = Repository.get_by_repo_name(repo_name) else: - raise Exception('You have to provide repository to action logger') + repo_obj = None + repo_name = '' user_log = UserLog() user_log.user_id = user_obj.user_id user_log.action = safe_unicode(action) - user_log.repository_id = repo_obj.repo_id + user_log.repository = repo_obj user_log.repository_name = repo_name user_log.action_date = datetime.datetime.now() diff --git a/rhodecode/templates/admin/admin_log.html b/rhodecode/templates/admin/admin_log.html --- a/rhodecode/templates/admin/admin_log.html +++ b/rhodecode/templates/admin/admin_log.html @@ -12,7 +12,7 @@ %for cnt,l in enumerate(c.users_log):