Skip to content

Commit

Permalink
fix user_group creation
Browse files Browse the repository at this point in the history
  • Loading branch information
logica0419 committed Mar 12, 2024
1 parent 597d581 commit fd076c9
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 34 deletions.
23 changes: 17 additions & 6 deletions scripts/create_usergroups.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
from ictsc2021 import Rikka

import os
import json
import logging
import os
from http import client

from ictsc2021 import Rikka


def load_setting():
filename = "./setting.prod.json"
with open(filename, "r") as f:
setting_json = f.read()
return json.loads(setting_json)


def main():
client.HTTPConnection.debuglevel = 1
logging.basicConfig(level=logging.DEBUG)
Expand All @@ -20,7 +21,7 @@ def main():

rikka = Rikka(baseurl=str(os.environ.get("baseurl")))

print(f"\x1b[33m\n*** signin\x1b[0m")
print("\x1b[33m\n*** signin\x1b[0m") # Add a placeholder to the f-string
rikka.signin(os.environ.get("username"), os.environ.get("password"))

for team in setting["teams"]:
Expand All @@ -31,10 +32,20 @@ def main():
bastion_password = ""
bastion_host = ""
bastion_port = 0
team_id = team["user_group_id"]
team_id = team["team_name"]

print(f"\x1b[33m\n*** Create user group {name}\x1b[0m")
rikka.create_usergroup(team_id, name, organization, invitation_code, False, bastion_user, bastion_password, bastion_host, bastion_port)
rikka.create_usergroup(
name,
organization,
invitation_code,
False,
bastion_user,
bastion_password,
bastion_host,
bastion_port,
team_id,
)


main()
77 changes: 49 additions & 28 deletions scripts/ictsc2021.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,43 +24,64 @@ def _patch(self, endpoint, **kwargs):
return requests.patch(url, cookies=self._jar, **kwargs)

def signin(self, username, password):
resp = self._post("/auth/signin", json={
"name": username,
"password": password,
})
resp = self._post(
"/auth/signin",
json={
"name": username,
"password": password,
},
)
self._jar = resp.cookies
return resp

def self(self):
return self._get("/auth/self")

def create_user(self, name, password, usergroupid, invitation_code):
return self._post("/users", json={
"name": name,
"password": password,
"user_group_id": usergroupid,
"invitation_code": invitation_code,
})
return self._post(
"/users",
json={
"name": name,
"password": password,
"user_group_id": usergroupid,
"invitation_code": invitation_code,
},
)

def create_usergroup(self, id, name, organization, invitation_code, is_full_access, bastion_user, bastion_password, bastion_host, bastion_port):
return self._post("/usergroups", json={
"team_id": id,
"name": name,
"organization": organization,
"invitation_code": invitation_code,
"is_full_access": is_full_access,
"bastion_user": bastion_user,
"bastion_password": bastion_password,
"bastion_host": bastion_host,
"bastion_port": bastion_port,
})
def create_usergroup(
self,
name,
organization,
invitation_code,
is_full_access,
bastion_user,
bastion_password,
bastion_host,
bastion_port,
team_id,
):
return self._post(
"/usergroups",
json={
"name": name,
"organization": organization,
"invitation_code": invitation_code,
"is_full_access": is_full_access,
"bastion_user": bastion_user,
"bastion_password": bastion_password,
"bastion_host": bastion_host,
"bastion_port": bastion_port,
"team_id": team_id,
},
)

def send_answer(self, problem_id, content):
return self._post("/problems/%s/answers" % problem_id, json={
"body": content
})
return self._post("/problems/%s/answers" % problem_id, json={"body": content})

def point(self, problem_id, answer_id, point):
return self._patch("/problems/%s/answers/%s" % (problem_id, answer_id), json={
"point": point,
})
return self._patch(
"/problems/%s/answers/%s" % (problem_id, answer_id),
json={
"point": point,
},
)

0 comments on commit fd076c9

Please sign in to comment.