|
@ -14,6 +14,8 @@ import string |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# load configuration |
|
|
# load configuration |
|
|
|
|
|
from typing import List |
|
|
|
|
|
|
|
|
try: |
|
|
try: |
|
|
import config |
|
|
import config |
|
|
except ImportError: |
|
|
except ImportError: |
|
@ -63,20 +65,22 @@ def does_organization_exist(org_api: OrganizationApi, orgname: str) -> bool: |
|
|
raise e |
|
|
raise e |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def does_organization_have_org_team(org_api: OrganizationApi, orgname: str) -> bool: |
|
|
def does_organization_have_team_with_name(org_api: OrganizationApi, orgname: str, teamname: str) -> bool: |
|
|
teams = org_api.org_list_teams(orgname) |
|
|
try: |
|
|
for t in teams: |
|
|
get_team_id_by_name(org_api, orgname, teamname) |
|
|
if 'org' == t.name: |
|
|
|
|
|
return True |
|
|
return True |
|
|
|
|
|
except AssertionError: |
|
|
return False |
|
|
return False |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_org_team_id(org_api: OrganizationApi, orgname: str) -> int: |
|
|
def get_team_id_by_name(org_api: OrganizationApi, orgname: str, teamname: str) -> int: |
|
|
|
|
|
"""Vraci bud ID teamu, nebo hazi AssertionError, pokud team neexistuje.""" |
|
|
|
|
|
|
|
|
teams = org_api.org_list_teams(orgname) |
|
|
teams = org_api.org_list_teams(orgname) |
|
|
for t in teams: |
|
|
for t in teams: |
|
|
if 'org' == t.name: |
|
|
if teamname == t.name: |
|
|
return t.id |
|
|
return t.id |
|
|
raise AssertionError('Tento kod mel byt unreachable. Zmizel tym orgu za behu skriptu?') |
|
|
raise AssertionError("Team se jmenem '{}' v organizaci '{}' neexistuje!".format(teamname, orgname)) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def validate(func_check, message: str): |
|
|
def validate(func_check, message: str): |
|
@ -169,11 +173,11 @@ def register(username: str, seminar: str, fullname: str, email: str, host, admin |
|
|
# kontrola predpokladu o stavu systemu |
|
|
# kontrola predpokladu o stavu systemu |
|
|
validate(lambda: not does_user_exist(user_api, username), "Uzivatelske jmeno je volne...") |
|
|
validate(lambda: not does_user_exist(user_api, username), "Uzivatelske jmeno je volne...") |
|
|
validate(lambda: does_organization_exist(org_api, seminar), "Organizace pro seminar existuje...") |
|
|
validate(lambda: does_organization_exist(org_api, seminar), "Organizace pro seminar existuje...") |
|
|
validate(lambda: does_organization_have_org_team(org_api, seminar), "V danem seminari existuje team 'org'...") |
|
|
validate(lambda: does_organization_have_team_with_name(org_api, seminar, 'org'), "V danem seminari existuje team 'org'...") |
|
|
print(text_green('Zakladni predpoklady pro uspesne zalozeni uctu splneny!\n')) |
|
|
print(text_green('Zakladni predpoklady pro uspesne zalozeni uctu splneny!\n')) |
|
|
|
|
|
|
|
|
# nasbirame vsechny potrebne informace |
|
|
# nasbirame vsechny potrebne informace |
|
|
org_team_id = get_org_team_id(org_api, seminar) |
|
|
org_team_id = get_team_id_by_name(org_api, seminar, 'org') |
|
|
|
|
|
|
|
|
# pripravime si uzivatele na zalozeni |
|
|
# pripravime si uzivatele na zalozeni |
|
|
create_user_req = CreateUserOption(email=email, full_name=fullname, username=username, |
|
|
create_user_req = CreateUserOption(email=email, full_name=fullname, username=username, |
|
|