Show More
@@ -32,7 +32,7 b' from pylons_app.lib import helpers as h' | |||||
32 | from pylons_app.lib.auth import LoginRequired, HasPermissionAllDecorator, \ |
|
32 | from pylons_app.lib.auth import LoginRequired, HasPermissionAllDecorator, \ | |
33 | HasPermissionAnyDecorator |
|
33 | HasPermissionAnyDecorator | |
34 | from pylons_app.lib.base import BaseController, render |
|
34 | from pylons_app.lib.base import BaseController, render | |
35 | from pylons_app.lib.utils import invalidate_cache |
|
35 | from pylons_app.lib.utils import invalidate_cache, action_logger | |
36 | from pylons_app.model.db import User |
|
36 | from pylons_app.model.db import User | |
37 | from pylons_app.model.forms import RepoForm |
|
37 | from pylons_app.model.forms import RepoForm | |
38 | from pylons_app.model.hg_model import HgModel |
|
38 | from pylons_app.model.hg_model import HgModel | |
@@ -77,13 +77,20 b' class ReposController(BaseController):' | |||||
77 | invalidate_cache('cached_repo_list') |
|
77 | invalidate_cache('cached_repo_list') | |
78 | h.flash(_('created repository %s') % form_result['repo_name'], |
|
78 | h.flash(_('created repository %s') % form_result['repo_name'], | |
79 | category='success') |
|
79 | category='success') | |
80 |
|
80 | |||
|
81 | if request.POST.get('user_created'): | |||
|
82 | action_logger(self.hg_app_user, 'user_created_repo', | |||
|
83 | form_result['repo_name'], '', self.sa) | |||
|
84 | else: | |||
|
85 | action_logger(self.hg_app_user, 'admin_created_repo', | |||
|
86 | form_result['repo_name'], '', self.sa) | |||
|
87 | ||||
81 | except formencode.Invalid as errors: |
|
88 | except formencode.Invalid as errors: | |
82 | c.new_repo = errors.value['repo_name'] |
|
89 | c.new_repo = errors.value['repo_name'] | |
83 |
|
90 | |||
84 | if request.POST.get('user_created'): |
|
91 | if request.POST.get('user_created'): | |
85 | r = render('admin/repos/repo_add_create_repository.html') |
|
92 | r = render('admin/repos/repo_add_create_repository.html') | |
86 | else: |
|
93 | else: | |
87 | r = render('admin/repos/repo_add.html') |
|
94 | r = render('admin/repos/repo_add.html') | |
88 |
|
95 | |||
89 | return htmlfill.render( |
|
96 | return htmlfill.render( | |
@@ -169,10 +176,14 b' class ReposController(BaseController):' | |||||
169 |
|
176 | |||
170 | return redirect(url('repos')) |
|
177 | return redirect(url('repos')) | |
171 | try: |
|
178 | try: | |
|
179 | action_logger(self.hg_app_user, 'admin_deleted_repo', | |||
|
180 | repo_name, '', self.sa) | |||
172 | repo_model.delete(repo) |
|
181 | repo_model.delete(repo) | |
173 | invalidate_cache('cached_repo_list') |
|
182 | invalidate_cache('cached_repo_list') | |
174 | h.flash(_('deleted repository %s') % repo_name, category='success') |
|
183 | h.flash(_('deleted repository %s') % repo_name, category='success') | |
175 | except Exception: |
|
184 | ||
|
185 | except Exception, e: | |||
|
186 | log.error(traceback.format_exc()) | |||
176 | h.flash(_('An error occured during deletion of %s') % repo_name, |
|
187 | h.flash(_('An error occured during deletion of %s') % repo_name, | |
177 | category='error') |
|
188 | category='error') | |
178 |
|
189 |
@@ -101,7 +101,7 b' class SettingsController(BaseController)' | |||||
101 | initial = HgModel.repo_scan(g.paths[0][0], g.paths[0][1], g.baseui) |
|
101 | initial = HgModel.repo_scan(g.paths[0][0], g.paths[0][1], g.baseui) | |
102 | repo2db_mapper(initial, rm_obsolete) |
|
102 | repo2db_mapper(initial, rm_obsolete) | |
103 | invalidate_cache('cached_repo_list') |
|
103 | invalidate_cache('cached_repo_list') | |
104 | h.flash(_('Repositories sucessfully rescanned'), category='success') |
|
104 | h.flash(_('Repositories successfully rescanned'), category='success') | |
105 |
|
105 | |||
106 | if setting_id == 'whoosh': |
|
106 | if setting_id == 'whoosh': | |
107 | repo_location = get_hg_ui_settings()['paths_root_path'] |
|
107 | repo_location = get_hg_ui_settings()['paths_root_path'] | |
@@ -134,7 +134,7 b' class SettingsController(BaseController)' | |||||
134 |
|
134 | |||
135 | except: |
|
135 | except: | |
136 | log.error(traceback.format_exc()) |
|
136 | log.error(traceback.format_exc()) | |
137 | h.flash(_('error occured during updating application settings'), |
|
137 | h.flash(_('error occurred during updating application settings'), | |
138 | category='error') |
|
138 | category='error') | |
139 |
|
139 | |||
140 | self.sa.rollback() |
|
140 | self.sa.rollback() | |
@@ -187,7 +187,7 b' class SettingsController(BaseController)' | |||||
187 |
|
187 | |||
188 | except: |
|
188 | except: | |
189 | log.error(traceback.format_exc()) |
|
189 | log.error(traceback.format_exc()) | |
190 | h.flash(_('error occured during updating application settings'), |
|
190 | h.flash(_('error occurred during updating application settings'), | |
191 | category='error') |
|
191 | category='error') | |
192 |
|
192 | |||
193 | self.sa.rollback() |
|
193 | self.sa.rollback() |
@@ -17,6 +17,7 b'' | |||||
17 | # along with this program; if not, write to the Free Software |
|
17 | # along with this program; if not, write to the Free Software | |
18 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
18 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, | |
19 | # MA 02110-1301, USA. |
|
19 | # MA 02110-1301, USA. | |
|
20 | from pylons_app.lib.utils import action_logger | |||
20 | """ |
|
21 | """ | |
21 | Created on April 4, 2010 |
|
22 | Created on April 4, 2010 | |
22 | users controller for pylons |
|
23 | users controller for pylons | |
@@ -71,6 +72,7 b' class UsersController(BaseController):' | |||||
71 | user_model.create(form_result) |
|
72 | user_model.create(form_result) | |
72 | h.flash(_('created user %s') % form_result['username'], |
|
73 | h.flash(_('created user %s') % form_result['username'], | |
73 | category='success') |
|
74 | category='success') | |
|
75 | #action_logger(self.hg_app_user, 'new_user', '', '', self.sa) | |||
74 | except formencode.Invalid as errors: |
|
76 | except formencode.Invalid as errors: | |
75 | return htmlfill.render( |
|
77 | return htmlfill.render( | |
76 | render('admin/users/user_add.html'), |
|
78 | render('admin/users/user_add.html'), |
@@ -28,7 +28,7 b' from pylons.controllers.util import redi' | |||||
28 | from pylons.i18n.translation import _ |
|
28 | from pylons.i18n.translation import _ | |
29 | from pylons_app.lib.auth import LoginRequired, HasRepoPermissionAllDecorator |
|
29 | from pylons_app.lib.auth import LoginRequired, HasRepoPermissionAllDecorator | |
30 | from pylons_app.lib.base import BaseController, render |
|
30 | from pylons_app.lib.base import BaseController, render | |
31 | from pylons_app.lib.utils import invalidate_cache |
|
31 | from pylons_app.lib.utils import invalidate_cache, action_logger | |
32 | from pylons_app.model.forms import RepoSettingsForm, RepoForkForm |
|
32 | from pylons_app.model.forms import RepoSettingsForm, RepoForkForm | |
33 | from pylons_app.model.repo_model import RepoModel |
|
33 | from pylons_app.model.repo_model import RepoModel | |
34 | import formencode |
|
34 | import formencode | |
@@ -79,7 +79,7 b' class SettingsController(BaseController)' | |||||
79 | form_result = _form.to_python(dict(request.POST)) |
|
79 | form_result = _form.to_python(dict(request.POST)) | |
80 | repo_model.update(repo_name, form_result) |
|
80 | repo_model.update(repo_name, form_result) | |
81 | invalidate_cache('cached_repo_list') |
|
81 | invalidate_cache('cached_repo_list') | |
82 | h.flash(_('Repository %s updated succesfully' % repo_name), |
|
82 | h.flash(_('Repository %s updated successfully' % repo_name), | |
83 | category='success') |
|
83 | category='success') | |
84 | changed_name = form_result['repo_name'] |
|
84 | changed_name = form_result['repo_name'] | |
85 | except formencode.Invalid as errors: |
|
85 | except formencode.Invalid as errors: | |
@@ -121,11 +121,13 b' class SettingsController(BaseController)' | |||||
121 |
|
121 | |||
122 | return redirect(url('hg_home')) |
|
122 | return redirect(url('hg_home')) | |
123 | try: |
|
123 | try: | |
|
124 | action_logger(self.hg_app_user, 'user_deleted_repo', | |||
|
125 | repo_name, '', self.sa) | |||
124 | repo_model.delete(repo) |
|
126 | repo_model.delete(repo) | |
125 | invalidate_cache('cached_repo_list') |
|
127 | invalidate_cache('cached_repo_list') | |
126 | h.flash(_('deleted repository %s') % repo_name, category='success') |
|
128 | h.flash(_('deleted repository %s') % repo_name, category='success') | |
127 | except Exception: |
|
129 | except Exception: | |
128 | h.flash(_('An error occured during deletion of %s') % repo_name, |
|
130 | h.flash(_('An error occurred during deletion of %s') % repo_name, | |
129 | category='error') |
|
131 | category='error') | |
130 |
|
132 | |||
131 | return redirect(url('hg_home')) |
|
133 | return redirect(url('hg_home')) | |
@@ -158,7 +160,8 b' class SettingsController(BaseController)' | |||||
158 | h.flash(_('fork %s repository as %s task added') \ |
|
160 | h.flash(_('fork %s repository as %s task added') \ | |
159 | % (repo_name, form_result['fork_name']), |
|
161 | % (repo_name, form_result['fork_name']), | |
160 | category='success') |
|
162 | category='success') | |
161 |
|
163 | action_logger(self.hg_app_user, 'user_forked_repo', | ||
|
164 | repo_name, '', self.sa) | |||
162 | except formencode.Invalid as errors: |
|
165 | except formencode.Invalid as errors: | |
163 | c.new_repo = errors.value['fork_name'] |
|
166 | c.new_repo = errors.value['fork_name'] | |
164 | r = render('settings/repo_fork.html') |
|
167 | r = render('settings/repo_fork.html') |
@@ -40,7 +40,7 b' class BaseController(WSGIController):' | |||||
40 | # available in environ['pylons.routes_dict'] |
|
40 | # available in environ['pylons.routes_dict'] | |
41 | try: |
|
41 | try: | |
42 | #putting this here makes sure that we update permissions every time |
|
42 | #putting this here makes sure that we update permissions every time | |
43 | c.hg_app_user = auth.get_user(session) |
|
43 | self.hg_app_user = c.hg_app_user = auth.get_user(session) | |
44 | return WSGIController.__call__(self, environ, start_response) |
|
44 | return WSGIController.__call__(self, environ, start_response) | |
45 | finally: |
|
45 | finally: | |
46 | meta.Session.remove() |
|
46 | meta.Session.remove() |
@@ -26,7 +26,7 b' from beaker.cache import cache_region' | |||||
26 | from mercurial import ui, config, hg |
|
26 | from mercurial import ui, config, hg | |
27 | from mercurial.error import RepoError |
|
27 | from mercurial.error import RepoError | |
28 | from pylons_app.model import meta |
|
28 | from pylons_app.model import meta | |
29 | from pylons_app.model.db import Repository, User, HgAppUi, HgAppSettings,UserLog |
|
29 | from pylons_app.model.db import Repository, User, HgAppUi, HgAppSettings, UserLog | |
30 | from vcs.backends.base import BaseChangeset |
|
30 | from vcs.backends.base import BaseChangeset | |
31 | from vcs.utils.lazy import LazyProperty |
|
31 | from vcs.utils.lazy import LazyProperty | |
32 | import logging |
|
32 | import logging | |
@@ -57,21 +57,21 b' def action_logger(user, action, repo, ip' | |||||
57 | if not sa: |
|
57 | if not sa: | |
58 | sa = meta.Session |
|
58 | sa = meta.Session | |
59 |
|
59 | |||
60 |
|
||||
61 | if hasattr(user, 'user_id'): |
|
|||
62 | user_id = user.user_id |
|
|||
63 | elif isinstance(user, basestring): |
|
|||
64 |
|
||||
65 | user_id = sa.Query(User).filter(User.username == user).one() |
|
|||
66 | else: |
|
|||
67 | raise Exception('You have to provide user object or username') |
|
|||
68 |
|
||||
69 | try: |
|
60 | try: | |
|
61 | if hasattr(user, 'user_id'): | |||
|
62 | user_id = user.user_id | |||
|
63 | elif isinstance(user, basestring): | |||
|
64 | user_id = sa.query(User).filter(User.username == user).one() | |||
|
65 | else: | |||
|
66 | raise Exception('You have to provide user object or username') | |||
|
67 | ||||
|
68 | repo_name = repo.lstrip('/') | |||
70 | user_log = UserLog() |
|
69 | user_log = UserLog() | |
71 | user_log.user_id = user_id |
|
70 | user_log.user_id = user_id | |
72 | user_log.action = action |
|
71 | user_log.action = action | |
|
72 | user_log.repository_name = repo_name | |||
73 | user_log.repository = sa.query(Repository)\ |
|
73 | user_log.repository = sa.query(Repository)\ | |
74 |
.filter(Repository.repo_name== |
|
74 | .filter(Repository.repo_name == repo_name).one() | |
75 | user_log.action_date = datetime.datetime.now() |
|
75 | user_log.action_date = datetime.datetime.now() | |
76 | user_log.user_ip = ipaddr |
|
76 | user_log.user_ip = ipaddr | |
77 | sa.add(user_log) |
|
77 | sa.add(user_log) |
@@ -66,7 +66,8 b' class UserLog(Base):' | |||||
66 | __table_args__ = {'useexisting':True} |
|
66 | __table_args__ = {'useexisting':True} | |
67 | user_log_id = Column("user_log_id", INTEGER(), nullable=False, unique=True, default=None, primary_key=True) |
|
67 | user_log_id = Column("user_log_id", INTEGER(), nullable=False, unique=True, default=None, primary_key=True) | |
68 | user_id = Column("user_id", INTEGER(), ForeignKey(u'users.user_id'), nullable=False, unique=None, default=None) |
|
68 | user_id = Column("user_id", INTEGER(), ForeignKey(u'users.user_id'), nullable=False, unique=None, default=None) | |
69 |
repository_id = Column("repository", |
|
69 | 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) | |
|
70 | repository_name = Column("repository_name", TEXT(length=None, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None) | |||
70 | user_ip = Column("user_ip", TEXT(length=None, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None) |
|
71 | user_ip = Column("user_ip", TEXT(length=None, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None) | |
71 | action = Column("action", TEXT(length=None, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None) |
|
72 | action = Column("action", TEXT(length=None, convert_unicode=False, assert_unicode=None), nullable=True, unique=None, default=None) | |
72 | action_date = Column("action_date", DATETIME(timezone=False), nullable=True, unique=None, default=None) |
|
73 | action_date = Column("action_date", DATETIME(timezone=False), nullable=True, unique=None, default=None) |
@@ -12,7 +12,13 b'' | |||||
12 | %for cnt,l in enumerate(c.users_log): |
|
12 | %for cnt,l in enumerate(c.users_log): | |
13 | <tr class="parity${cnt%2}"> |
|
13 | <tr class="parity${cnt%2}"> | |
14 | <td>${h.link_to(l.user.username,h.url('edit_user', id=l.user.user_id))}</td> |
|
14 | <td>${h.link_to(l.user.username,h.url('edit_user', id=l.user.user_id))}</td> | |
15 | <td>${h.link_to(l.repository.repo_name,h.url('summary_home',repo_name=l.repository.repo_name))}</td> |
|
15 | <td> | |
|
16 | %if l.repository: | |||
|
17 | ${h.link_to(l.repository.repo_name,h.url('summary_home',repo_name=l.repository.repo_name))} | |||
|
18 | %else: | |||
|
19 | ${l.repository_name} | |||
|
20 | %endif | |||
|
21 | </td> | |||
16 | <td> |
|
22 | <td> | |
17 | % if l.action == 'push' and l.revision: |
|
23 | % if l.action == 'push' and l.revision: | |
18 | ${h.link_to('%s - %s' % (l.action,l.revision), |
|
24 | ${h.link_to('%s - %s' % (l.action,l.revision), |
General Comments 0
You need to be logged in to leave comments.
Login now