##// 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 116 master_repo = backend.create_repo()
117 117 repo = backend.create_repo()
118 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 122 expected_api_data = repo.get_api_data(include_secrets=True)
122 123 expected_api_data.update(updates)
@@ -131,6 +132,7 b' class TestApiUpdateRepo(object):'
131 132 assert_ok(id_, expected, given=response.body)
132 133 result = response.json['result']['repository']
133 134 assert result['fork_of'] == master_repo.repo_name
135 assert result['fork_of_id'] == master_repo.repo_id
134 136
135 137 def test_api_update_repo_fork_of_not_found(self, backend):
136 138 master_repo_name = 'fake-parent-repo'
@@ -50,6 +50,7 b' ACTIONS = {'
50 50 'user.edit.password_reset.disabled': {},
51 51
52 52 'repo.create': {'data': {}},
53 'repo.fork': {'data': {}},
53 54 'repo.edit': {'old_data': {}},
54 55 'repo.edit.permissions': {},
55 56 'repo.delete': {'old_data': {}},
@@ -31,12 +31,13 b' from celery.task import task'
31 31 from pylons import config
32 32
33 33 import rhodecode
34 from rhodecode.lib import audit_logger
34 35 from rhodecode.lib.celerylib import (
35 36 run_task, dbsession, __get_lockkey, LockHeld, DaemonLock,
36 37 get_session, vcsconnection, RhodecodeCeleryTask)
37 38 from rhodecode.lib.hooks_base import log_create_repository
38 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 41 from rhodecode.lib.utils2 import safe_int, str2bool
41 42 from rhodecode.model.db import Repository, User
42 43
@@ -141,7 +142,7 b' def create_repo(form_data, cur_user):'
141 142 'enable_downloads', defs.get('repo_enable_downloads'))
142 143
143 144 try:
144 RepoModel(DBS)._create_repo(
145 repo = RepoModel(DBS)._create_repo(
145 146 repo_name=repo_name_full,
146 147 repo_type=repo_type,
147 148 description=description,
@@ -158,8 +159,6 b' def create_repo(form_data, cur_user):'
158 159 enable_downloads=enable_downloads,
159 160 state=state
160 161 )
161
162 action_logger(cur_user, 'user_created_repo', repo_name_full, '', DBS)
163 162 DBS.commit()
164 163
165 164 # now create this repo on Filesystem
@@ -177,6 +176,15 b' def create_repo(form_data, cur_user):'
177 176
178 177 # set new created state
179 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 188 DBS.commit()
181 189 except Exception:
182 190 log.warning('Exception occurred when creating repository, '
@@ -240,8 +248,7 b' def create_repo_fork(form_data, cur_user'
240 248 fork_of=fork_of,
241 249 copy_fork_permissions=copy_fork_permissions
242 250 )
243 action_logger(cur_user, 'user_forked_repo:%s' % repo_name_full,
244 fork_of.repo_name, '', DBS)
251
245 252 DBS.commit()
246 253
247 254 base_path = Repository.base_path()
@@ -264,6 +271,15 b' def create_repo_fork(form_data, cur_user'
264 271
265 272 # set new created state
266 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 283 DBS.commit()
268 284 except Exception as e:
269 285 log.warning('Exception %s occurred when forking repository, '
@@ -1782,6 +1782,7 b' class Repository(Base, BaseModel):'
1782 1782 'landing_rev': repo.landing_rev,
1783 1783 'owner': repo.user.username,
1784 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 1786 'enable_statistics': repo.enable_statistics,
1786 1787 'enable_locking': repo.enable_locking,
1787 1788 'enable_downloads': repo.enable_downloads,
General Comments 0
You need to be logged in to leave comments. Login now