def connect_stories_to_meeting(id_str: str) -> HttpResponse: meeting_id_res = validate_meeting_id_from_str(id_str) if meeting_id_res.is_error: return get_with_error(400, meeting_id_res.message) meeting_id = meeting_id_res.data update_story_group_meetings(meeting_id) return get_with_data(get_meeting_story_groups(get_meeting_ids()))
def get_admin_page_data() -> HttpResponse: meeting_ids = get_meeting_ids() meetings_res = get_meetings(meeting_ids) if meetings_res.is_error: return get_with_error(500, meetings_res.message) meetings = meetings_res.data config_list = get_config_list() groups = get_groups() tasks = get_tasks() years_res = get_years() if years_res.is_error: return get_with_error(500, years_res.message) years = years_res.data group_years = get_group_years() meeting_story_groups = get_meeting_story_groups(meeting_ids) return get_with_data({ "meetings": meetings, "general": config_list, "groups": groups, "tasks": tasks, "years": years, "groupYears": group_years, "meetingStoryGroups": meeting_story_groups })
def handle_start_timer(id: str) -> HttpResponse: meeting_id_res = validate_meeting_id_from_str(id) if meeting_id_res.is_error: return get_with_error(meeting_id_res.message) print("Starting deadline check for meeting {0}".format(id)) update_meeting_check_for_deadline(meeting_id_res.data, True) return get_with_data({})
def handle_email(data: Dict) -> HttpResponse: meeting_id_res = validate_meeting_id(data, "id") if meeting_id_res.is_error: return get_with_error(400, meeting_id_res.message) meeting_id = meeting_id_res.data threading.Thread(target=send_emails, args=(meeting_id, )).start() return get_with_data({})
def validate_password(response_json: Dict) -> HttpResponse: if response_json is None or "pass" not in response_json: return get_with_error(400, "Bad Request") password = response_json["pass"] correct_password = os.environ.get("frontend_admin_pass", "asd123") if password != correct_password: return get_with_error(401, "Invalid password") return get_with_data({})
def handle_story_email(data: Dict) -> HttpResponse: meeting_id_res = validate_meeting_id(data, "id") if meeting_id_res.is_error: return get_with_error(meeting_id_res.message) meeting_id = meeting_id_res.data story_datas = update_story_group_meetings(meeting_id) threading.Thread(target=send_story_emails, args=(meeting_id, story_datas)).start() return get_with_data(get_meeting_story_groups(get_meeting_ids()))
def handle_incoming_config(config: Dict) -> HttpResponse: validated_configs = validate_configs(config) if validated_configs.is_error: return get_with_error(400, validated_configs.message) configs = validated_configs.data for config in configs: update_config_value(config.key, config.value) return get_with_data({})
def handle_gamma_auth(data: dict) -> HttpResponse: code_res = validate_str(data, "code") if code_res.is_error: return get_with_error(400, code_res.message) code = code_res.data data = { 'grant_type': 'authorization_code', 'client_id': GAMMA_CLIENT_ID, 'redirect_uri': GAMMA_REDIRECT_URI, 'code': code } c = f"{GAMMA_CLIENT_ID}:{GAMMA_SECRET}" encoded_bytes = base64.b64encode(c.encode("utf-8")) encoded_str = str(encoded_bytes, "utf-8") headers = { 'Content-Type': 'application/x-www-form-urlencoded', 'Authorization': f'Basic {encoded_str}' } res = requests.post(f"{GAMMA_TOKEN_URI}?{urllib.parse.urlencode(data)}", headers=headers) if res.status_code != 200: print( f"Error communicating with gamma status code {res.status_code} > {res.raw}" ) return get_with_error(500, "Gamma error") res_json = res.json() if "access_token" not in res_json: return get_with_error(400, "Invalid token") token = res.json()["access_token"] gamma_me_headers = {"Authorization": f"Bearer {token}"} gamma_me_res = requests.get(GAMMA_ME_URI, headers=gamma_me_headers) if gamma_me_res.ok: gamma_me_json = gamma_me_res.json() for group in gamma_me_json["groups"]: super_group = group["superGroup"] if group["active"] and super_group["name"] == "styrit": if res.ok: session["token"] = token return get_with_data({}) return get_with_error(403, "Must be a member of styrIT") else: return get_with_error( 500, f"Unable to communicate with Gamma, code '{res.status_code}', content '{res.content}'" )
def handle_meeting_config(data: Dict) -> HttpResponse: valid = validate_meeting(data) if valid.is_error: return get_with_error(400, valid.message) update_res = update_meeting_data(valid.data) if update_res.is_error: return get_with_error(400, update_res.message) meeting_data_res = get_meeting_json_data(valid.data.id) if meeting_data_res.is_error: return get_with_error(400, meeting_data_res.message) return get_with_data(meeting_data_res.data.to_json())
def handle_stories(config: Dict[str, object]) -> HttpResponse: stories_res = validate_stories(config) if stories_res.is_error: return get_with_error(400, stories_res.message) valid = stories_res.data update_res = update_stories(valid) if update_res.is_error: return get_with_error(400, update_res.message) return get_with_data({ "groupYears": get_group_years(), "years": get_years() })
def get_archive_url(id_str: str) -> HttpResponse: id_res = validate_meeting_id_from_str(id_str) if id_res.is_error: return get_with_error(400, id_res.message) id = id_res.data archive_code_res = create_archive(id) if archive_code_res.is_error: return get_with_error(500, archive_code_res.message) archive_code = archive_code_res.data base_url = get_config_value("archive_base_url") redirect_url = f"{base_url}/{archive_code}" print("Should be redirected to {0}".format(redirect_url)) return get_with_data({"redirect_url": redirect_url})
def handle_code_request(code_str: str) -> HttpResponse: code_res = validate_code(code_str) if code_res.is_error: return get_with_error(400, code_res.message) code_last_upload = get_last_upload_for_code(code_res.data) current_date = datetime.utcnow() if code_last_upload < current_date: secretary_email = get_config_value("secretary_email") return get_with_error(401, "Code expired, please contact the secretary at {0}".format(secretary_email)) data_res = get_data_for_code(code_res.data) if data_res.is_error: return get_with_error(401, data_res.message) return get_with_data({ "code": code_str, "data": data_res.data })
def handle_file_request(code_str: str, files: Dict) -> HttpResponse: code_res = validate_code(code_str) if code_res.is_error: return get_with_error(401, code_res.message) code = code_res.data group_meeting = get_group_meeting_by_code(code) if group_meeting is None: secretary_email = get_config_value("secretary_email") return get_with_error( 400, "Code not found! Please contact the secretary at {0}".format( secretary_email)) overwrite = False for task in files: file_res = handle_file(code, task, files[task]) if file_res.is_error: return get_with_error(400, file_res.message) overwrite = file_res.data return get_with_data({"overwrite": overwrite})