Browse Source

upgraded URLs pointing to our Gitea, generalized few validation functions...

master
Vašek Šraier 4 years ago
parent
commit
8b801c7d84
  1. 3
      .gitignore
  2. 2
      Pipfile
  3. 12
      Pipfile.lock
  4. 2
      README.md
  5. 26
      register.py

3
.gitignore

@ -3,4 +3,5 @@ tmp/
.idea/
.idea/
.mypy_cache/
config.py
config.py
__pycache__/

2
Pipfile

@ -12,7 +12,7 @@ beautifulsoup4 = "*"
six = "*"
termcolor = "*"
lxml = "*"
swagger_client = { git = "https://gitea-gimli.kam.mff.cuni.cz/vasek/gitea-swagger-client" }
swagger_client = { git = "https://gitea.ks.matfyz.cz/vasek/gitea-swagger-client" }
[requires]
python_version = "3"

12
Pipfile.lock

@ -1,7 +1,7 @@
{
"_meta": {
"hash": {
"sha256": "ee32788aeebfec6cf37be58728aa8f66afdc8783d61e401722317295a45b5e03"
"sha256": "a5459836de6fd359bbfc6b9783a5c4f2e451a48bfefd7b633d48b3d55ab73c48"
},
"pipfile-spec": 6,
"requires": {
@ -104,14 +104,14 @@
},
"soupsieve": {
"hashes": [
"sha256:afa56bf14907bb09403e5d15fbed6275caa4174d36b975226e3b67a3bb6e2c4b",
"sha256:eaed742b48b1f3e2d45ba6f79401b2ed5dc33b2123dfe216adb90d4bfa0ade26"
"sha256:3aef141566afd07201b525c17bfaadd07580a8066f82b57f7c9417f26adbd0a3",
"sha256:e41a65e99bd125972d84221022beb1e4b5cfc68fa12c170c39834ce32d1b294c"
],
"version": "==1.8"
"version": "==1.9"
},
"swagger-client": {
"git": "https://gitea-gimli.kam.mff.cuni.cz/vasek/gitea-swagger-client",
"ref": "2a6ff3b1aaf0a2fe27453c8f4fdde23feb3a640f"
"git": "https://gitea.ks.matfyz.cz/vasek/gitea-swagger-client",
"ref": "ed03b192ca0ba6fa7fb9bfacd567b8fbfb306355"
},
"termcolor": {
"hashes": [

2
README.md

@ -35,7 +35,7 @@ standardní vygenerovaný webový interface ke specifikaci. Specifikace samotná
`/swagger.v1.json`.
K tomuto API je vygenerován klient aktuálně se nacházející
[zde](https://gitea-gimli.kam.mff.cuni.cz/vasek/gitea-swagger-client). Kód je v podstatě čistě vygenerovaný nástrojem
[zde](https://gitea.ks.matfyz.cz/vasek/gitea-swagger-client). Kód je v podstatě čistě vygenerovaný nástrojem
`swagger-codegen` (link v repozitáři s klientem). Obsahuje akorát dva drobné patche, protože bez nich vůbec nejde
naimportovat.

26
register.py

@ -14,6 +14,8 @@ import string
# load configuration
from typing import List
try:
import config
except ImportError:
@ -63,20 +65,22 @@ def does_organization_exist(org_api: OrganizationApi, orgname: str) -> bool:
raise e
def does_organization_have_org_team(org_api: OrganizationApi, orgname: str) -> bool:
teams = org_api.org_list_teams(orgname)
for t in teams:
if 'org' == t.name:
return True
return False
def does_organization_have_team_with_name(org_api: OrganizationApi, orgname: str, teamname: str) -> bool:
try:
get_team_id_by_name(org_api, orgname, teamname)
return True
except AssertionError:
return False
def get_team_id_by_name(org_api: OrganizationApi, orgname: str, teamname: str) -> int:
"""Vraci bud ID teamu, nebo hazi AssertionError, pokud team neexistuje."""
def get_org_team_id(org_api: OrganizationApi, orgname: str) -> int:
teams = org_api.org_list_teams(orgname)
for t in teams:
if 'org' == t.name:
if teamname == t.name:
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):
@ -169,11 +173,11 @@ def register(username: str, seminar: str, fullname: str, email: str, host, admin
# kontrola predpokladu o stavu systemu
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_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'))
# 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
create_user_req = CreateUserOption(email=email, full_name=fullname, username=username,

Loading…
Cancel
Save