def process_files_post(): app.logger.debug("POST FILES") files = flask.request.files files_extract = [] files_direct = [] for key in files: if key == _EXTRACT_KEY: files_extract += files.getlist(key) else: files_direct += files.getlist(key) uid_lst = [] if files_extract: uid_lst += process_objects(None, srv.create_files, create_stub=create_stub_files, files=files_extract) if files_direct: uid_lst += process_objects(None, srv.create_file, create_stub=create_stub_file, files=files_direct) if flask.request.method == 'POST': perms.create_perms(uid_lst, _FILES_KEY) out = {_FILES_KEY: uid_lst} return flask.jsonify(out)
def process_submission_runs(obj_uuid): # Get Submission sub = srv.get_submission(obj_uuid) # Process Runs uid_lst = process_objects(sub.list_runs, sub.execute_run) if flask.request.method == 'POST': perms.create_perms(uid_lst, _RUNS_KEY) out = {_RUNS_KEY: uid_lst} return flask.jsonify(out)
def process_assignment_submissions(obj_uuid): # Get Assignment asn = srv.get_assignment(obj_uuid) # Process Submissions uid_lst = process_objects(asn.list_submissions, asn.create_submission) if flask.request.method == 'POST': perms.create_perms(uid_lst, _SUBMISSIONS_KEY) out = {_SUBMISSIONS_KEY: uid_lst} return flask.jsonify(out)
def process_assignment_tests(obj_uuid): # Get Assignment asn = srv.get_assignment(obj_uuid) # Process Tests uid_lst = process_objects(asn.list_tests, asn.create_test) if flask.request.method == 'POST': perms.create_perms(uid_lst, _TESTS_KEY) out = {_TESTS_KEY: uid_lst} return flask.jsonify(out)
def reset_defaults(obj): """ Reset all permissions""" click.echo("Listing existing permissions") perm_lst = obj['auth'].AllowedGroupsFactory.list_family() for perm_key in perm_lst: click.echo("Permission '{}'".format(perm_key)) click.echo("Removing existing permissions") cnt = 0 for perm_key in perm_lst: perm_obj = obj['auth'].AllowedGroupsFactory.from_raw(key=perm_key) perm_obj.delete() cnt += 1 click.echo("Removed {} existing permissions".format(cnt)) click.echo("Setting base permissions") perms_base_path = os.path.join(cogs.config.PERMS_PATH, "base.json") if os.path.isfile(perms_base_path): cnt = perms.set_perms_from_file(perms_base_path) else: cnt = 0 click.echo("Set {} base permissions".format(cnt)) click.echo("Setting file permissions") fle_lst = obj['server'].list_files() cnt = perms.create_perms(fle_lst, _FILES_KEY) cnt_per = cnt/len(fle_lst) if fle_lst else 0 click.echo("Set {} file permissions ({} per file)".format(cnt, cnt_per)) click.echo("Setting reporter permissions") rpt_lst = obj['server'].list_reporters() cnt = perms.create_perms(rpt_lst, _REPORTERS_KEY) cnt_per = cnt/len(rpt_lst) if rpt_lst else 0 click.echo("Set {} reporter permissions ({} per reporter)".format(cnt, cnt_per)) click.echo("Setting assignment permissions") asn_lst = obj['server'].list_assignments() cnt = perms.create_perms(asn_lst, _ASSIGNMENTS_KEY) cnt_per = cnt/len(asn_lst) if asn_lst else 0 click.echo("Set {} assignment permissions ({} per assignment)".format(cnt, cnt_per)) click.echo("Setting test permissions") tst_lst = obj['server'].list_tests() cnt = perms.create_perms(tst_lst, _TESTS_KEY) cnt_per = cnt/len(tst_lst) if tst_lst else 0 click.echo("Set {} test permissions ({} per test)".format(cnt, cnt_per)) click.echo("Setting submission permissions") sub_lst = obj['server'].list_submissions() cnt = perms.create_perms(sub_lst, _SUBMISSIONS_KEY) cnt_per = cnt/len(sub_lst) if sub_lst else 0 click.echo("Set {} submission permissions ({} per submission)".format(cnt, cnt_per)) click.echo("Setting run permissions") run_lst = obj['server'].list_runs() cnt = perms.create_perms(run_lst, _RUNS_KEY) cnt_per = cnt/len(run_lst) if run_lst else 0 click.echo("Set {} run permissions ({} per run)".format(cnt, cnt_per)) click.echo("Listing new permissions") perm_lst = obj['auth'].AllowedGroupsFactory.list_family() for perm_key in perm_lst: click.echo("Permission '{}'".format(perm_key))
def process_assignments(): uid_lst = process_objects(srv.list_assignments, srv.create_assignment) if flask.request.method == 'POST': perms.create_perms(uid_lst, _ASSIGNMENTS_KEY) out = {_ASSIGNMENTS_KEY: uid_lst} return flask.jsonify(out)
def process_reporters(): uid_lst = process_objects(srv.list_reporters, srv.create_reporter) if flask.request.method == 'POST': perms.create_perms(uid_lst, _REPORTERS_KEY) out = {_REPORTERS_KEY: uid_lst} return flask.jsonify(out)
def reset_defaults(obj): """ Reset all permissions""" click.echo("Listing existing permissions") perm_lst = obj['auth'].AllowedGroupsFactory.list_family() for perm_key in perm_lst: click.echo("Permission '{}'".format(perm_key)) click.echo("Removing existing permissions") cnt = 0 for perm_key in perm_lst: perm_obj = obj['auth'].AllowedGroupsFactory.from_raw(key=perm_key) perm_obj.delete() cnt += 1 click.echo("Removed {} existing permissions".format(cnt)) click.echo("Setting base permissions") perms_base_path = os.path.join(cogs.config.PERMS_PATH, "base.json") if os.path.isfile(perms_base_path): cnt = perms.set_perms_from_file(perms_base_path) else: cnt = 0 click.echo("Set {} base permissions".format(cnt)) click.echo("Setting file permissions") fle_lst = obj['server'].list_files() cnt = perms.create_perms(fle_lst, _FILES_KEY) cnt_per = cnt / len(fle_lst) if fle_lst else 0 click.echo("Set {} file permissions ({} per file)".format(cnt, cnt_per)) click.echo("Setting reporter permissions") rpt_lst = obj['server'].list_reporters() cnt = perms.create_perms(rpt_lst, _REPORTERS_KEY) cnt_per = cnt / len(rpt_lst) if rpt_lst else 0 click.echo("Set {} reporter permissions ({} per reporter)".format( cnt, cnt_per)) click.echo("Setting assignment permissions") asn_lst = obj['server'].list_assignments() cnt = perms.create_perms(asn_lst, _ASSIGNMENTS_KEY) cnt_per = cnt / len(asn_lst) if asn_lst else 0 click.echo("Set {} assignment permissions ({} per assignment)".format( cnt, cnt_per)) click.echo("Setting test permissions") tst_lst = obj['server'].list_tests() cnt = perms.create_perms(tst_lst, _TESTS_KEY) cnt_per = cnt / len(tst_lst) if tst_lst else 0 click.echo("Set {} test permissions ({} per test)".format(cnt, cnt_per)) click.echo("Setting submission permissions") sub_lst = obj['server'].list_submissions() cnt = perms.create_perms(sub_lst, _SUBMISSIONS_KEY) cnt_per = cnt / len(sub_lst) if sub_lst else 0 click.echo("Set {} submission permissions ({} per submission)".format( cnt, cnt_per)) click.echo("Setting run permissions") run_lst = obj['server'].list_runs() cnt = perms.create_perms(run_lst, _RUNS_KEY) cnt_per = cnt / len(run_lst) if run_lst else 0 click.echo("Set {} run permissions ({} per run)".format(cnt, cnt_per)) click.echo("Listing new permissions") perm_lst = obj['auth'].AllowedGroupsFactory.list_family() for perm_key in perm_lst: click.echo("Permission '{}'".format(perm_key))