comparison rhodecode/controllers/api/api.py @ 3235:d6029dacbcc4 beta

API invalidate_cache function ref #733
author Marcin Kuzminski <marcin@python-works.com>
date Sat, 26 Jan 2013 23:12:50 +0100
parents a50901f2108d
children 5f1850e4712a
comparison
equal deleted inserted replaced
3234:21cccfea18bf 3235:d6029dacbcc4
200 log.error(traceback.format_exc()) 200 log.error(traceback.format_exc())
201 raise JSONRPCError( 201 raise JSONRPCError(
202 'Error occurred during rescan repositories action' 202 'Error occurred during rescan repositories action'
203 ) 203 )
204 204
205 def invalidate_cache(self, apiuser, repoid):
206 """
207 Dispatch cache invalidation action on given repo
208
209 :param apiuser:
210 :param repoid:
211 """
212 repo = get_repo_or_error(repoid)
213 if HasPermissionAnyApi('hg.admin')(user=apiuser) is False:
214 # check if we have admin permission for this repo !
215 if HasRepoPermissionAnyApi('repository.admin',
216 'repository.write')(user=apiuser,
217 repo_name=repo.repo_name) is False:
218 raise JSONRPCError('repository `%s` does not exist' % (repoid))
219
220 try:
221 invalidated_keys = ScmModel().mark_for_invalidation(repo.repo_name)
222 Session().commit()
223 return ('Cache for repository `%s` was invalidated: '
224 'invalidated cache keys: %s' % (repoid, invalidated_keys))
225 except Exception:
226 log.error(traceback.format_exc())
227 raise JSONRPCError(
228 'Error occurred during cache invalidation action'
229 )
230
205 def lock(self, apiuser, repoid, locked, userid=Optional(OAttr('apiuser'))): 231 def lock(self, apiuser, repoid, locked, userid=Optional(OAttr('apiuser'))):
206 """ 232 """
207 Set locking state on particular repository by given user, if 233 Set locking state on particular repository by given user, if
208 this command is runned by non-admin account userid is set to user 234 this command is runned by non-admin account userid is set to user
209 who is calling this method 235 who is calling this method