Show More
@@ -848,8 +848,10 b' OUTPUT::' | |||
|
848 | 848 | delete_repo |
|
849 | 849 | ----------- |
|
850 | 850 | |
|
851 |
Deletes a repository. This command can be executed only using api_key belonging |
|
|
852 | rights or regular user that have admin access to repository. | |
|
851 | Deletes a repository. This command can be executed only using api_key belonging | |
|
852 | to user with admin rights or regular user that have admin access to repository. | |
|
853 | When `forks` param is set it's possible to detach or delete forks of deleting | |
|
854 | repository | |
|
853 | 855 | |
|
854 | 856 | |
|
855 | 857 | INPUT:: |
@@ -858,7 +860,8 b' INPUT::' | |||
|
858 | 860 | api_key : "<api_key>" |
|
859 | 861 | method : "delete_repo" |
|
860 | 862 | args: { |
|
861 | "repoid" : "<reponame or repo_id>" | |
|
863 | "repoid" : "<reponame or repo_id>", | |
|
864 | "forks" : "`delete` or `detach` = Optional(None)" | |
|
862 | 865 | } |
|
863 | 866 | |
|
864 | 867 | OUTPUT:: |
@@ -50,6 +50,7 b' from rhodecode.model.scm import ScmModel' | |||
|
50 | 50 | from rhodecode.model.repo import RepoModel |
|
51 | 51 | from rhodecode.lib.compat import json |
|
52 | 52 | from sqlalchemy.sql.expression import func |
|
53 | from rhodecode.lib.exceptions import AttachedForksError | |
|
53 | 54 | |
|
54 | 55 | log = logging.getLogger(__name__) |
|
55 | 56 | |
@@ -302,38 +303,26 b' class ReposController(BaseRepoController' | |||
|
302 | 303 | return redirect(url('repos')) |
|
303 | 304 | try: |
|
304 | 305 | _forks = repo.forks.count() |
|
306 | handle_forks = None | |
|
305 | 307 | if _forks and request.POST.get('forks'): |
|
306 | 308 | do = request.POST['forks'] |
|
307 | 309 | if do == 'detach_forks': |
|
308 |
for |
|
|
309 | log.debug('Detaching fork %s from repo %s' % (r, repo)) | |
|
310 | r.fork = None | |
|
311 | Session().add(r) | |
|
310 | handle_forks = 'detach' | |
|
312 | 311 | h.flash(_('Detached %s forks') % _forks, category='success') |
|
313 | 312 | elif do == 'delete_forks': |
|
314 |
for |
|
|
315 | log.debug('Deleting fork %s of repo %s' % (r, repo)) | |
|
316 | repo_model.delete(r) | |
|
313 | handle_forks = 'delete' | |
|
317 | 314 | h.flash(_('Deleted %s forks') % _forks, category='success') |
|
315 | repo_model.delete(repo, forks=handle_forks) | |
|
318 | 316 | action_logger(self.rhodecode_user, 'admin_deleted_repo', |
|
319 |
|
|
|
320 | repo_model.delete(repo) | |
|
317 | repo_name, self.ip_addr, self.sa) | |
|
321 | 318 | invalidate_cache('get_repo_cached_%s' % repo_name) |
|
322 | 319 | h.flash(_('Deleted repository %s') % repo_name, category='success') |
|
323 | 320 | Session().commit() |
|
324 |
except |
|
|
325 | if e.message.find('repositories_fork_id_fkey') != -1: | |
|
326 | log.error(traceback.format_exc()) | |
|
327 | h.flash(_('Cannot delete %s it still contains attached ' | |
|
328 | 'forks') % repo_name, | |
|
329 | category='warning') | |
|
330 | else: | |
|
331 | log.error(traceback.format_exc()) | |
|
332 | h.flash(_('An error occurred during ' | |
|
333 | 'deletion of %s') % repo_name, | |
|
334 | category='error') | |
|
321 | except AttachedForksError: | |
|
322 | h.flash(_('Cannot delete %s it still contains attached forks') | |
|
323 | % repo_name, category='warning') | |
|
335 | 324 | |
|
336 |
except Exception |
|
|
325 | except Exception: | |
|
337 | 326 | log.error(traceback.format_exc()) |
|
338 | 327 | h.flash(_('An error occurred during deletion of %s') % repo_name, |
|
339 | 328 | category='error') |
@@ -853,12 +853,13 b' class ApiController(JSONRPCController):' | |||
|
853 | 853 | fork_name) |
|
854 | 854 | ) |
|
855 | 855 | |
|
856 | def delete_repo(self, apiuser, repoid): | |
|
856 | def delete_repo(self, apiuser, repoid, forks=Optional(None)): | |
|
857 | 857 | """ |
|
858 | 858 | Deletes a given repository |
|
859 | 859 | |
|
860 | 860 | :param apiuser: |
|
861 | 861 | :param repoid: |
|
862 | :param forks: detach or delete, what do do with attached forks for repo | |
|
862 | 863 | """ |
|
863 | 864 | repo = get_repo_or_error(repoid) |
|
864 | 865 | |
@@ -866,13 +867,26 b' class ApiController(JSONRPCController):' | |||
|
866 | 867 | # check if we have admin permission for this repo ! |
|
867 | 868 | if HasRepoPermissionAnyApi('repository.admin')(user=apiuser, |
|
868 | 869 | repo_name=repo.repo_name) is False: |
|
869 |
|
|
|
870 | raise JSONRPCError('repository `%s` does not exist' % (repoid)) | |
|
870 | 871 | |
|
871 | 872 | try: |
|
872 | RepoModel().delete(repo) | |
|
873 | handle_forks = Optional.extract(forks) | |
|
874 | _forks_msg = '' | |
|
875 | _forks = [f for f in repo.forks] | |
|
876 | if handle_forks == 'detach': | |
|
877 | _forks_msg = ' ' + _('Detached %s forks') % len(_forks) | |
|
878 | elif handle_forks == 'delete': | |
|
879 | _forks_msg = ' ' + _('Deleted %s forks') % len(_forks) | |
|
880 | elif _forks: | |
|
881 | raise JSONRPCError( | |
|
882 | 'Cannot delete `%s` it still contains attached forks' | |
|
883 | % repo.repo_name | |
|
884 | ) | |
|
885 | ||
|
886 | RepoModel().delete(repo, forks=forks) | |
|
873 | 887 | Session().commit() |
|
874 | 888 | return dict( |
|
875 | msg='Deleted repository `%s`' % repo.repo_name, | |
|
889 | msg='Deleted repository `%s`%s' % (repo.repo_name, _forks_msg), | |
|
876 | 890 | success=True |
|
877 | 891 | ) |
|
878 | 892 | except Exception: |
@@ -58,6 +58,10 b' class StatusChangeOnClosedPullRequestErr' | |||
|
58 | 58 | pass |
|
59 | 59 | |
|
60 | 60 | |
|
61 | class AttachedForksError(Exception): | |
|
62 | pass | |
|
63 | ||
|
64 | ||
|
61 | 65 | class HTTPLockedRC(HTTPClientError): |
|
62 | 66 | """ |
|
63 | 67 | Special Exception For locked Repos in RhodeCode, the return code can |
@@ -42,6 +42,7 b' from rhodecode.model.db import Repositor' | |||
|
42 | 42 | RhodeCodeSetting, RepositoryField |
|
43 | 43 | from rhodecode.lib import helpers as h |
|
44 | 44 | from rhodecode.lib.auth import HasRepoPermissionAny |
|
45 | from rhodecode.lib.exceptions import AttachedForksError | |
|
45 | 46 | |
|
46 | 47 | log = logging.getLogger(__name__) |
|
47 | 48 | |
@@ -465,9 +466,27 b' class RepoModel(BaseModel):' | |||
|
465 | 466 | from rhodecode.lib.celerylib import tasks, run_task |
|
466 | 467 | run_task(tasks.create_repo_fork, form_data, cur_user) |
|
467 | 468 | |
|
468 | def delete(self, repo): | |
|
469 | def delete(self, repo, forks=None): | |
|
470 | """ | |
|
471 | Delete given repository, forks parameter defines what do do with | |
|
472 | attached forks. Throws AttachedForksError if deleted repo has attached | |
|
473 | forks | |
|
474 | ||
|
475 | :param repo: | |
|
476 | :param forks: str 'delete' or 'detach' | |
|
477 | """ | |
|
469 | 478 | repo = self._get_repo(repo) |
|
470 | 479 | if repo: |
|
480 | if forks == 'detach': | |
|
481 | for r in repo.forks: | |
|
482 | r.fork = None | |
|
483 | self.sa.add(r) | |
|
484 | elif forks == 'delete': | |
|
485 | for r in repo.forks: | |
|
486 | self.delete(r, forks='delete') | |
|
487 | elif [f for f in repo.forks]: | |
|
488 | raise AttachedForksError() | |
|
489 | ||
|
471 | 490 | old_repo_dict = repo.get_dict() |
|
472 | 491 | owner = repo.user |
|
473 | 492 | try: |
General Comments 0
You need to be logged in to leave comments.
Login now