def create_team(name, org_obj, team_role_name, description=""): (teamname_valid, teamname_issue) = validate_team_name(name) if not teamname_valid: raise InvalidTeamException("Invalid team name %s: %s" % (name, teamname_issue)) if not org_obj.organization: raise InvalidTeamException( "Specified organization %s was not an organization" % org_obj.username) team_role = TeamRole.get(TeamRole.name == team_role_name) return Team.create(name=name, organization=org_obj, role=team_role, description=description)
def get_organization_team(orgname, teamname): joined = Team.select().join(User) query = joined.where(Team.name == teamname, User.organization == True, User.username == orgname).limit(1) result = list(query) if not result: raise InvalidTeamException("Team does not exist: %s/%s", orgname, teamname) return result[0]
def remove_team(org_name, team_name, removed_by_username): joined = Team.select(Team, TeamRole).join(User).switch(Team).join(TeamRole) found = list( joined.where(User.organization == True, User.username == org_name, Team.name == team_name)) if not found: raise InvalidTeamException("Team '%s' is not a team in org '%s'" % (team_name, org_name)) team = found[0] if team.role.name == "admin": admin_teams = list( __get_user_admin_teams(org_name, removed_by_username)) if len(admin_teams) <= 1: # The team we are trying to remove is the only admin team containing this user. msg = "Deleting team '%s' would remove admin ability for user '%s' in organization '%s'" raise DataModelException( msg % (team_name, removed_by_username, org_name)) team.delete_instance(recursive=True, delete_nullable=True)