Browse Source

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

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

1
.gitignore

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

2
Pipfile

@ -12,7 +12,7 @@ beautifulsoup4 = "*"
six = "*" six = "*"
termcolor = "*" termcolor = "*"
lxml = "*" 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] [requires]
python_version = "3" python_version = "3"

12
Pipfile.lock

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

2
README.md

@ -35,7 +35,7 @@ standardní vygenerovaný webový interface ke specifikaci. Specifikace samotná
`/swagger.v1.json`. `/swagger.v1.json`.
K tomuto API je vygenerován klient aktuálně se nacházející 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 `swagger-codegen` (link v repozitáři s klientem). Obsahuje akorát dva drobné patche, protože bez nich vůbec nejde
naimportovat. naimportovat.

22
register.py

@ -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,

Loading…
Cancel
Save