##// END OF EJS Templates
audit-logs: moved async tasks from old deprecated action_logger.
marcink -
r1803:907f9b5c default
parent child Browse files
Show More
@@ -116,7 +116,8 b' class TestApiUpdateRepo(object):'
116 master_repo = backend.create_repo()
116 master_repo = backend.create_repo()
117 repo = backend.create_repo()
117 repo = backend.create_repo()
118 updates = {
118 updates = {
119 'fork_of': master_repo.repo_name
119 'fork_of': master_repo.repo_name,
120 'fork_of_id': master_repo.repo_id
120 }
121 }
121 expected_api_data = repo.get_api_data(include_secrets=True)
122 expected_api_data = repo.get_api_data(include_secrets=True)
122 expected_api_data.update(updates)
123 expected_api_data.update(updates)
@@ -131,6 +132,7 b' class TestApiUpdateRepo(object):'
131 assert_ok(id_, expected, given=response.body)
132 assert_ok(id_, expected, given=response.body)
132 result = response.json['result']['repository']
133 result = response.json['result']['repository']
133 assert result['fork_of'] == master_repo.repo_name
134 assert result['fork_of'] == master_repo.repo_name
135 assert result['fork_of_id'] == master_repo.repo_id
134
136
135 def test_api_update_repo_fork_of_not_found(self, backend):
137 def test_api_update_repo_fork_of_not_found(self, backend):
136 master_repo_name = 'fake-parent-repo'
138 master_repo_name = 'fake-parent-repo'
@@ -50,6 +50,7 b' ACTIONS = {'
50 'user.edit.password_reset.disabled': {},
50 'user.edit.password_reset.disabled': {},
51
51
52 'repo.create': {'data': {}},
52 'repo.create': {'data': {}},
53 'repo.fork': {'data': {}},
53 'repo.edit': {'old_data': {}},
54 'repo.edit': {'old_data': {}},
54 'repo.edit.permissions': {},
55 'repo.edit.permissions': {},
55 'repo.delete': {'old_data': {}},
56 'repo.delete': {'old_data': {}},
@@ -31,12 +31,13 b' from celery.task import task'
31 from pylons import config
31 from pylons import config
32
32
33 import rhodecode
33 import rhodecode
34 from rhodecode.lib import audit_logger
34 from rhodecode.lib.celerylib import (
35 from rhodecode.lib.celerylib import (
35 run_task, dbsession, __get_lockkey, LockHeld, DaemonLock,
36 run_task, dbsession, __get_lockkey, LockHeld, DaemonLock,
36 get_session, vcsconnection, RhodecodeCeleryTask)
37 get_session, vcsconnection, RhodecodeCeleryTask)
37 from rhodecode.lib.hooks_base import log_create_repository
38 from rhodecode.lib.hooks_base import log_create_repository
38 from rhodecode.lib.rcmail.smtp_mailer import SmtpMailer
39 from rhodecode.lib.rcmail.smtp_mailer import SmtpMailer
39 from rhodecode.lib.utils import add_cache, action_logger
40 from rhodecode.lib.utils import add_cache
40 from rhodecode.lib.utils2 import safe_int, str2bool
41 from rhodecode.lib.utils2 import safe_int, str2bool
41 from rhodecode.model.db import Repository, User
42 from rhodecode.model.db import Repository, User
42
43
@@ -141,7 +142,7 b' def create_repo(form_data, cur_user):'
141 'enable_downloads', defs.get('repo_enable_downloads'))
142 'enable_downloads', defs.get('repo_enable_downloads'))
142
143
143 try:
144 try:
144 RepoModel(DBS)._create_repo(
145 repo = RepoModel(DBS)._create_repo(
145 repo_name=repo_name_full,
146 repo_name=repo_name_full,
146 repo_type=repo_type,
147 repo_type=repo_type,
147 description=description,
148 description=description,
@@ -158,8 +159,6 b' def create_repo(form_data, cur_user):'
158 enable_downloads=enable_downloads,
159 enable_downloads=enable_downloads,
159 state=state
160 state=state
160 )
161 )
161
162 action_logger(cur_user, 'user_created_repo', repo_name_full, '', DBS)
163 DBS.commit()
162 DBS.commit()
164
163
165 # now create this repo on Filesystem
164 # now create this repo on Filesystem
@@ -177,6 +176,15 b' def create_repo(form_data, cur_user):'
177
176
178 # set new created state
177 # set new created state
179 repo.set_state(Repository.STATE_CREATED)
178 repo.set_state(Repository.STATE_CREATED)
179 repo_id = repo.repo_id
180 repo_data = repo.get_api_data()
181
182 audit_logger.store(
183 action='repo.create',
184 action_data={'data': repo_data},
185 user=cur_user,
186 repo=audit_logger.RepoWrap(repo_name=repo_name, repo_id=repo_id))
187
180 DBS.commit()
188 DBS.commit()
181 except Exception:
189 except Exception:
182 log.warning('Exception occurred when creating repository, '
190 log.warning('Exception occurred when creating repository, '
@@ -240,8 +248,7 b' def create_repo_fork(form_data, cur_user'
240 fork_of=fork_of,
248 fork_of=fork_of,
241 copy_fork_permissions=copy_fork_permissions
249 copy_fork_permissions=copy_fork_permissions
242 )
250 )
243 action_logger(cur_user, 'user_forked_repo:%s' % repo_name_full,
251
244 fork_of.repo_name, '', DBS)
245 DBS.commit()
252 DBS.commit()
246
253
247 base_path = Repository.base_path()
254 base_path = Repository.base_path()
@@ -264,6 +271,15 b' def create_repo_fork(form_data, cur_user'
264
271
265 # set new created state
272 # set new created state
266 repo.set_state(Repository.STATE_CREATED)
273 repo.set_state(Repository.STATE_CREATED)
274
275 repo_id = repo.repo_id
276 repo_data = repo.get_api_data()
277 audit_logger.store(
278 action='repo.fork',
279 action_data={'data': repo_data},
280 user=cur_user,
281 repo=audit_logger.RepoWrap(repo_name=repo_name, repo_id=repo_id))
282
267 DBS.commit()
283 DBS.commit()
268 except Exception as e:
284 except Exception as e:
269 log.warning('Exception %s occurred when forking repository, '
285 log.warning('Exception %s occurred when forking repository, '
@@ -1782,6 +1782,7 b' class Repository(Base, BaseModel):'
1782 'landing_rev': repo.landing_rev,
1782 'landing_rev': repo.landing_rev,
1783 'owner': repo.user.username,
1783 'owner': repo.user.username,
1784 'fork_of': repo.fork.repo_name if repo.fork else None,
1784 'fork_of': repo.fork.repo_name if repo.fork else None,
1785 'fork_of_id': repo.fork.repo_id if repo.fork else None,
1785 'enable_statistics': repo.enable_statistics,
1786 'enable_statistics': repo.enable_statistics,
1786 'enable_locking': repo.enable_locking,
1787 'enable_locking': repo.enable_locking,
1787 'enable_downloads': repo.enable_downloads,
1788 'enable_downloads': repo.enable_downloads,
General Comments 0
You need to be logged in to leave comments. Login now