def orgdashboards_get_group_entity_name(self): entity_name = helpers.orgdashboards_get_group_entity_name() assert entity_name == 'group' config.set('ckanext.orgdashboards.group_entity_name', 'some_entity') entity_name = helpers.orgdashboards_get_group_entity_name() assert entity_name == 'some_entity'
def orgdashboards_get_organization_entity_name(self): entity_name = helpers.orgdashboards_get_organization_entity_name() assert entity_name == 'organization' config.set('ckanext.orgdashboards.organization_entity_name', 'some_entity') entity_name = helpers.orgdashboards_get_organization_entity_name() assert entity_name == 'some_entity'
def create_repo_fork(form_data, cur_user): """ Creates a fork of repository using internal VCS methods :param form_data: :param cur_user: """ from rhodecode.model.repo import RepoModel from rhodecode.model.user import UserModel log = get_logger(create_repo_fork) DBS = get_session() cur_user = UserModel(DBS)._get_user(cur_user) owner = cur_user repo_name = form_data['repo_name'] # fork in this case repo_name_full = form_data['repo_name_full'] repo_type = form_data['repo_type'] description = form_data['description'] private = form_data['private'] clone_uri = form_data.get('clone_uri') repo_group = safe_int(form_data['repo_group']) landing_rev = form_data['landing_rev'] copy_fork_permissions = form_data.get('copy_permissions') fork_id = safe_int(form_data.get('fork_parent_id')) try: fork_of = RepoModel(DBS)._get_repo(fork_id) RepoModel(DBS)._create_repo( repo_name=repo_name_full, repo_type=repo_type, description=description, owner=owner, private=private, clone_uri=clone_uri, repo_group=repo_group, landing_rev=landing_rev, fork_of=fork_of, copy_fork_permissions=copy_fork_permissions) action_logger(cur_user, 'user_forked_repo:%s' % repo_name_full, fork_of.repo_name, '', DBS) DBS.commit() base_path = Repository.base_path() source_repo_path = os.path.join(base_path, fork_of.repo_name) # now create this repo on Filesystem RepoModel(DBS)._create_filesystem_repo( repo_name=repo_name, repo_type=repo_type, repo_group=RepoModel(DBS)._get_repo_group(repo_group), clone_uri=source_repo_path, ) repo = Repository.get_by_repo_name(repo_name_full) log_create_repository(created_by=owner.username, **repo.get_dict()) # update repo commit caches initially config = repo._config config.set('extensions', 'largefiles', '') repo.update_commit_cache(config=config) # set new created state repo.set_state(Repository.STATE_CREATED) DBS.commit() except Exception as e: log.warning( 'Exception %s occurred when forking repository, ' 'doing cleanup...', e) # rollback things manually ! repo = Repository.get_by_repo_name(repo_name_full) if repo: Repository.delete(repo.repo_id) DBS.commit() RepoModel(DBS)._delete_filesystem_repo(repo) raise # it's an odd fix to make celery fail task when exception occurs def on_failure(self, *args, **kwargs): pass return True