def create(self, form_data, cur_user, just_db=False, fork=False): try: if fork: repo_name = form_data["fork_name"] org_name = form_data["repo_name"] org_full_name = org_name else: org_name = repo_name = form_data["repo_name"] repo_name_full = form_data["repo_name_full"] new_repo = Repository() new_repo.enable_statistics = False for k, v in form_data.items(): if k == "repo_name": if fork: v = repo_name else: v = repo_name_full if k == "repo_group": k = "group_id" setattr(new_repo, k, v) if fork: parent_repo = self.sa.query(Repository).filter(Repository.repo_name == org_full_name).one() new_repo.fork = parent_repo new_repo.user_id = cur_user.user_id self.sa.add(new_repo) # create default permission repo_to_perm = RepoToPerm() default = "repository.read" for p in UserModel(self.sa).get_by_username("default", cache=False).user_perms: if p.permission.permission_name.startswith("repository."): default = p.permission.permission_name break default_perm = "repository.none" if form_data["private"] else default repo_to_perm.permission_id = ( self.sa.query(Permission).filter(Permission.permission_name == default_perm).one().permission_id ) repo_to_perm.repository = new_repo repo_to_perm.user_id = UserModel(self.sa).get_by_username("default", cache=False).user_id self.sa.add(repo_to_perm) if not just_db: self.__create_repo(repo_name, form_data["repo_type"], form_data["repo_group"], form_data["clone_uri"]) self.sa.commit() # now automatically start following this repository as owner from rhodecode.model.scm import ScmModel ScmModel(self.sa).toggle_following_repo(new_repo.repo_id, cur_user.user_id) except: log.error(traceback.format_exc()) self.sa.rollback() raise
def create(self, form_data, cur_user, just_db=False, fork=False): try: if fork: repo_name = form_data['fork_name'] org_name = form_data['repo_name'] org_full_name = org_name else: org_name = repo_name = form_data['repo_name'] repo_name_full = form_data['repo_name_full'] new_repo = Repository() new_repo.enable_statistics = False for k, v in form_data.items(): if k == 'repo_name': if fork: v = repo_name else: v = repo_name_full if k == 'repo_group': k = 'group_id' if k == 'description': v = v or repo_name setattr(new_repo, k, v) if fork: parent_repo = self.sa.query(Repository)\ .filter(Repository.repo_name == org_full_name).one() new_repo.fork = parent_repo new_repo.user_id = cur_user.user_id self.sa.add(new_repo) #create default permission repo_to_perm = RepoToPerm() default = 'repository.read' for p in User.get_by_username('default').user_perms: if p.permission.permission_name.startswith('repository.'): default = p.permission.permission_name break default_perm = 'repository.none' if form_data['private'] else default repo_to_perm.permission_id = self.sa.query(Permission)\ .filter(Permission.permission_name == default_perm)\ .one().permission_id repo_to_perm.repository = new_repo repo_to_perm.user_id = User.get_by_username('default').user_id self.sa.add(repo_to_perm) if not just_db: self.__create_repo(repo_name, form_data['repo_type'], form_data['repo_group'], form_data['clone_uri']) self.sa.commit() #now automatically start following this repository as owner from rhodecode.model.scm import ScmModel ScmModel(self.sa).toggle_following_repo(new_repo.repo_id, cur_user.user_id) return new_repo except: log.error(traceback.format_exc()) self.sa.rollback() raise