Show More
@@ -140,7 +140,7 b' class ReposController(BaseController):' | |||
|
140 | 140 | changed_name, '', self.sa) |
|
141 | 141 | |
|
142 | 142 | except formencode.Invalid, errors: |
|
143 | c.repo_info = repo_model.get(repo_name) | |
|
143 | c.repo_info = repo_model.get_by_repo_name(repo_name) | |
|
144 | 144 | c.users_array = repo_model.get_users_js() |
|
145 | 145 | errors.value.update({'user':c.repo_info.user.username}) |
|
146 | 146 | return htmlfill.render( |
@@ -168,7 +168,7 b' class ReposController(BaseController):' | |||
|
168 | 168 | # url('repo', repo_name=ID) |
|
169 | 169 | |
|
170 | 170 | repo_model = RepoModel() |
|
171 | repo = repo_model.get(repo_name) | |
|
171 | repo = repo_model.get_by_repo_name(repo_name) | |
|
172 | 172 | if not repo: |
|
173 | 173 | h.flash(_('%s repository is not mapped to db perhaps' |
|
174 | 174 | ' it was moved or renamed from the filesystem' |
@@ -245,7 +245,7 b' class ReposController(BaseController):' | |||
|
245 | 245 | """GET /repos/repo_name/edit: Form to edit an existing item""" |
|
246 | 246 | # url('edit_repo', repo_name=ID) |
|
247 | 247 | repo_model = RepoModel() |
|
248 | c.repo_info = repo = repo_model.get(repo_name) | |
|
248 | c.repo_info = repo = repo_model.get_by_repo_name(repo_name) | |
|
249 | 249 | if repo.stats: |
|
250 | 250 | last_rev = repo.stats.stat_on_revision |
|
251 | 251 | else: |
@@ -28,6 +28,7 b' from pylons.controllers.util import abor' | |||
|
28 | 28 | from rhodecode.lib.auth import LoginRequired |
|
29 | 29 | from rhodecode.lib.base import BaseController, render |
|
30 | 30 | from rhodecode.lib.helpers import get_token |
|
31 | from rhodecode.lib.utils import action_logger | |
|
31 | 32 | from rhodecode.model.db import UserLog, UserFollowing |
|
32 | 33 | from rhodecode.model.scm import ScmModel |
|
33 | 34 | import logging |
@@ -56,7 +57,6 b' class JournalController(BaseController):' | |||
|
56 | 57 | |
|
57 | 58 | |
|
58 | 59 | def toggle_following(self): |
|
59 | print c.rhodecode_user | |
|
60 | 60 | |
|
61 | 61 | if request.POST.get('auth_token') == get_token(): |
|
62 | 62 | scm_model = ScmModel() |
@@ -47,7 +47,7 b' class SettingsController(BaseController)' | |||
|
47 | 47 | |
|
48 | 48 | def index(self, repo_name): |
|
49 | 49 | repo_model = RepoModel() |
|
50 | c.repo_info = repo = repo_model.get(repo_name) | |
|
50 | c.repo_info = repo = repo_model.get_by_repo_name(repo_name) | |
|
51 | 51 | if not repo: |
|
52 | 52 | h.flash(_('%s repository is not mapped to db perhaps' |
|
53 | 53 | ' it was created or renamed from the filesystem' |
@@ -85,7 +85,7 b' class SettingsController(BaseController)' | |||
|
85 | 85 | action_logger(self.rhodecode_user, 'user_updated_repo', |
|
86 | 86 | changed_name, '', self.sa) |
|
87 | 87 | except formencode.Invalid, errors: |
|
88 | c.repo_info = repo_model.get(repo_name) | |
|
88 | c.repo_info = repo_model.get_by_repo_name(repo_name) | |
|
89 | 89 | c.users_array = repo_model.get_users_js() |
|
90 | 90 | errors.value.update({'user':c.repo_info.user.username}) |
|
91 | 91 | return htmlfill.render( |
@@ -113,7 +113,7 b' class SettingsController(BaseController)' | |||
|
113 | 113 | # url('repo_settings_delete', repo_name=ID) |
|
114 | 114 | |
|
115 | 115 | repo_model = RepoModel() |
|
116 | repo = repo_model.get(repo_name) | |
|
116 | repo = repo_model.get_by_repo_name(repo_name) | |
|
117 | 117 | if not repo: |
|
118 | 118 | h.flash(_('%s repository is not mapped to db perhaps' |
|
119 | 119 | ' it was moved or renamed from the filesystem' |
@@ -136,7 +136,7 b' class SettingsController(BaseController)' | |||
|
136 | 136 | |
|
137 | 137 | def fork(self, repo_name): |
|
138 | 138 | repo_model = RepoModel() |
|
139 | c.repo_info = repo = repo_model.get(repo_name) | |
|
139 | c.repo_info = repo = repo_model.get_by_repo_name(repo_name) | |
|
140 | 140 | if not repo: |
|
141 | 141 | h.flash(_('%s repository is not mapped to db perhaps' |
|
142 | 142 | ' it was created or renamed from the filesystem' |
@@ -152,7 +152,7 b' class SettingsController(BaseController)' | |||
|
152 | 152 | |
|
153 | 153 | def fork_create(self, repo_name): |
|
154 | 154 | repo_model = RepoModel() |
|
155 | c.repo_info = repo_model.get(repo_name) | |
|
155 | c.repo_info = repo_model.get_by_repo_name(repo_name) | |
|
156 | 156 | _form = RepoForkForm(old_data={'repo_type':c.repo_info.repo_type})() |
|
157 | 157 | form_result = {} |
|
158 | 158 | try: |
@@ -459,7 +459,10 b' def action_parser(user_log):' | |||
|
459 | 459 | 'admin_forked_repo':_('Admin forked repository'), |
|
460 | 460 | 'admin_updated_repo':_('Admin updated repository'), |
|
461 | 461 | 'push':_('Pushed') + get_cs_links(), |
|
462 |
'pull':_('Pulled'), |
|
|
462 | 'pull':_('Pulled'), | |
|
463 | 'started_following_repo':_('User started following repository'), | |
|
464 | 'stopped_following_repo':_('User stopped following repository'), | |
|
465 | } | |
|
463 | 466 | |
|
464 | 467 | return map.get(action, action) |
|
465 | 468 |
@@ -70,13 +70,14 b' def is_git(environ):' | |||
|
70 | 70 | |
|
71 | 71 | def action_logger(user, action, repo, ipaddr='', sa=None): |
|
72 | 72 | """ |
|
73 | Action logger for various action made by users | |
|
73 | Action logger for various actions made by users | |
|
74 | 74 | |
|
75 |
:param user: user that made this action, can be a |
|
|
75 | :param user: user that made this action, can be a unique username string or | |
|
76 | 76 | object containing user_id attribute |
|
77 | 77 | :param action: action to log, should be on of predefined unique actions for |
|
78 | 78 | easy translations |
|
79 | :param repo: repository that action was made on | |
|
79 | :param repo: string name of repository or object containing repo_id, | |
|
80 | that action was made on | |
|
80 | 81 | :param ipaddr: optional ip address from what the action was made |
|
81 | 82 | :param sa: optional sqlalchemy session |
|
82 | 83 | |
@@ -86,20 +87,22 b' def action_logger(user, action, repo, ip' | |||
|
86 | 87 | sa = meta.Session() |
|
87 | 88 | |
|
88 | 89 | try: |
|
90 | um = UserModel() | |
|
89 | 91 | if hasattr(user, 'user_id'): |
|
90 | 92 | user_obj = user |
|
91 | 93 | elif isinstance(user, basestring): |
|
92 |
user_obj = |
|
|
94 | user_obj = um.get_by_username(user, cache=False) | |
|
93 | 95 | else: |
|
94 | 96 | raise Exception('You have to provide user object or username') |
|
95 | 97 | |
|
96 | 98 | |
|
97 |
|
|
|
99 | rm = RepoModel() | |
|
100 | if hasattr(repo, 'repo_id'): | |
|
101 | repo_obj = rm.get(repo.repo_id, cache=False) | |
|
102 | repo_name = repo_obj.repo_name | |
|
103 | elif isinstance(repo, basestring): | |
|
98 | 104 | repo_name = repo.lstrip('/') |
|
99 | ||
|
100 | repository = RepoModel().get(repo_name, cache=False) | |
|
101 | if not repository: | |
|
102 | raise Exception('You have to provide valid repository') | |
|
105 | repo_obj = rm.get_by_repo_name(repo_name, cache=False) | |
|
103 | 106 | else: |
|
104 | 107 | raise Exception('You have to provide repository to action logger') |
|
105 | 108 | |
@@ -107,8 +110,10 b' def action_logger(user, action, repo, ip' | |||
|
107 | 110 | user_log = UserLog() |
|
108 | 111 | user_log.user_id = user_obj.user_id |
|
109 | 112 | user_log.action = action |
|
113 | ||
|
114 | user_log.repository_id = repo_obj.repo_id | |
|
110 | 115 | user_log.repository_name = repo_name |
|
111 | user_log.repository = repository | |
|
116 | ||
|
112 | 117 | user_log.action_date = datetime.datetime.now() |
|
113 | 118 | user_log.user_ip = ipaddr |
|
114 | 119 | sa.add(user_log) |
@@ -352,7 +357,7 b' def repo2db_mapper(initial_repo_list, re' | |||
|
352 | 357 | user = sa.query(User).filter(User.admin == True).first() |
|
353 | 358 | |
|
354 | 359 | for name, repo in initial_repo_list.items(): |
|
355 | if not rm.get(name, cache=False): | |
|
360 | if not rm.get_by_repo_name(name, cache=False): | |
|
356 | 361 | log.info('repository %s not found creating default', name) |
|
357 | 362 | |
|
358 | 363 | form_data = { |
@@ -170,7 +170,7 b' def ValidRepoName(edit, old_data):' | |||
|
170 | 170 | raise formencode.Invalid(_('This repository name is disallowed'), |
|
171 | 171 | value, state) |
|
172 | 172 | if old_data.get('repo_name') != value or not edit: |
|
173 | if RepoModel().get(slug, cache=False): | |
|
173 | if RepoModel().get_by_repo_name(slug, cache=False): | |
|
174 | 174 | raise formencode.Invalid(_('This repository already exists') , |
|
175 | 175 | value, state) |
|
176 | 176 | return slug |
@@ -42,13 +42,23 b' class RepoModel(object):' | |||
|
42 | 42 | |
|
43 | 43 | def get(self, repo_id, cache=False): |
|
44 | 44 | repo = self.sa.query(Repository)\ |
|
45 |
.filter(Repository.repo_ |
|
|
45 | .filter(Repository.repo_id == repo_id) | |
|
46 | 46 | |
|
47 | 47 | if cache: |
|
48 | 48 | repo = repo.options(FromCache("sql_cache_short", |
|
49 | "get_repo_%s" % repo)) | |
|
49 | "get_repo_%s" % repo_id)) | |
|
50 | 50 | return repo.scalar() |
|
51 | 51 | |
|
52 | ||
|
53 | def get_by_repo_name(self, repo_name, cache=False): | |
|
54 | repo = self.sa.query(Repository)\ | |
|
55 | .filter(Repository.repo_name == repo_name) | |
|
56 | ||
|
57 | if cache: | |
|
58 | repo = repo.options(FromCache("sql_cache_short", | |
|
59 | "get_repo_%s" % repo_name)) | |
|
60 | return repo.scalar() | |
|
61 | ||
|
52 | 62 | def get_users_js(self): |
|
53 | 63 | |
|
54 | 64 | users = self.sa.query(User).filter(User.active == True).all() |
@@ -65,19 +75,21 b' class RepoModel(object):' | |||
|
65 | 75 | #update permissions |
|
66 | 76 | for username, perm in form_data['perms_updates']: |
|
67 | 77 | r2p = self.sa.query(RepoToPerm)\ |
|
68 |
.filter(RepoToPerm.user == UserModel() |
|
|
69 | .filter(RepoToPerm.repository == self.get(repo_name))\ | |
|
78 | .filter(RepoToPerm.user == UserModel()\ | |
|
79 | .get_by_username(username, cache=False))\ | |
|
80 | .filter(RepoToPerm.repository == \ | |
|
81 | self.get_by_repo_name(repo_name))\ | |
|
70 | 82 | .one() |
|
71 | 83 | |
|
72 | 84 | r2p.permission_id = self.sa.query(Permission).filter( |
|
73 | Permission.permission_name == | |
|
85 | Permission.permission_name == | |
|
74 | 86 | perm).one().permission_id |
|
75 | 87 | self.sa.add(r2p) |
|
76 | 88 | |
|
77 | 89 | #set new permissions |
|
78 | 90 | for username, perm in form_data['perms_new']: |
|
79 | 91 | r2p = RepoToPerm() |
|
80 | r2p.repository = self.get(repo_name) | |
|
92 | r2p.repository = self.get_by_repo_name(repo_name) | |
|
81 | 93 | r2p.user = UserModel().get_by_username(username, cache=False) |
|
82 | 94 | |
|
83 | 95 | r2p.permission_id = self.sa.query(Permission).filter( |
@@ -86,7 +98,7 b' class RepoModel(object):' | |||
|
86 | 98 | self.sa.add(r2p) |
|
87 | 99 | |
|
88 | 100 | #update current repo |
|
89 | cur_repo = self.get(repo_name, cache=False) | |
|
101 | cur_repo = self.get_by_repo_name(repo_name, cache=False) | |
|
90 | 102 | |
|
91 | 103 | for k, v in form_data.items(): |
|
92 | 104 | if k == 'user': |
@@ -172,7 +184,8 b' class RepoModel(object):' | |||
|
172 | 184 | def delete_perm_user(self, form_data, repo_name): |
|
173 | 185 | try: |
|
174 | 186 | self.sa.query(RepoToPerm)\ |
|
175 |
.filter(RepoToPerm.repository |
|
|
187 | .filter(RepoToPerm.repository \ | |
|
188 | == self.get_by_repo_name(repo_name))\ | |
|
176 | 189 | .filter(RepoToPerm.user_id == form_data['user_id']).delete() |
|
177 | 190 | self.sa.commit() |
|
178 | 191 | except: |
@@ -183,7 +196,8 b' class RepoModel(object):' | |||
|
183 | 196 | def delete_stats(self, repo_name): |
|
184 | 197 | try: |
|
185 | 198 | self.sa.query(Statistics)\ |
|
186 |
.filter(Statistics.repository == |
|
|
199 | .filter(Statistics.repository == \ | |
|
200 | self.get_by_repo_name(repo_name)).delete() | |
|
187 | 201 | self.sa.commit() |
|
188 | 202 | except: |
|
189 | 203 | log.error(traceback.format_exc()) |
@@ -27,7 +27,7 b' from mercurial import ui' | |||
|
27 | 27 | from rhodecode import BACKENDS |
|
28 | 28 | from rhodecode.lib import helpers as h |
|
29 | 29 | from rhodecode.lib.auth import HasRepoPermissionAny |
|
30 | from rhodecode.lib.utils import get_repos, make_ui | |
|
30 | from rhodecode.lib.utils import get_repos, make_ui, action_logger | |
|
31 | 31 | from rhodecode.model import meta |
|
32 | 32 | from rhodecode.model.db import Repository, User, RhodeCodeUi, CacheInvalidation, \ |
|
33 | 33 | UserFollowing |
@@ -45,6 +45,15 b' import time' | |||
|
45 | 45 | |
|
46 | 46 | log = logging.getLogger(__name__) |
|
47 | 47 | |
|
48 | class UserTemp(object): | |
|
49 | def __init__(self, user_id): | |
|
50 | self.user_id = user_id | |
|
51 | ||
|
52 | class RepoTemp(object): | |
|
53 | def __init__(self, repo_id): | |
|
54 | self.repo_id = repo_id | |
|
55 | ||
|
56 | ||
|
48 | 57 | class ScmModel(object): |
|
49 | 58 | """ |
|
50 | 59 | Mercurial Model |
@@ -227,9 +236,13 b' class ScmModel(object):' | |||
|
227 | 236 | .filter(UserFollowing.user_id == user_id).scalar() |
|
228 | 237 | |
|
229 | 238 | if f is not None: |
|
239 | ||
|
230 | 240 | try: |
|
231 | 241 | self.sa.delete(f) |
|
232 | 242 | self.sa.commit() |
|
243 | action_logger(UserTemp(user_id), | |
|
244 | 'stopped_following_repo', | |
|
245 | RepoTemp(follow_repo_id)) | |
|
233 | 246 | return |
|
234 | 247 | except: |
|
235 | 248 | log.error(traceback.format_exc()) |
@@ -243,6 +256,9 b' class ScmModel(object):' | |||
|
243 | 256 | f.follows_repo_id = follow_repo_id |
|
244 | 257 | self.sa.add(f) |
|
245 | 258 | self.sa.commit() |
|
259 | action_logger(UserTemp(user_id), | |
|
260 | 'started_following_repo', | |
|
261 | RepoTemp(follow_repo_id)) | |
|
246 | 262 | except: |
|
247 | 263 | log.error(traceback.format_exc()) |
|
248 | 264 | self.sa.rollback() |
General Comments 0
You need to be logged in to leave comments.
Login now