예제 #1
0
def patch_questionnaire_properties(questionnaire_key):
    if not resource_database.is_valid_resource_name(questionnaire_key):
        end_with_status(400)

    authorized_roles = get_authorized_roles()
    if len(authorized_roles) == 0:
        end_with_status(403)

    if "all" in authorized_roles or questionnaire_key in authorized_roles:
        questionnaire = resource_database.read_questionnaire(questionnaire_key)

        form = cgi.FieldStorage()

        possibleProperties = ["name", "pictureUrl", "public"]

        booleanProperties = ["public"]

        for property in possibleProperties:
            if property in form:
                if property in booleanProperties:
                    string_value = form.getfirst(property)
                    if string_value == "true":
                        questionnaire[property] = True
                    else:
                        questionnaire[property] = False
                else:
                    questionnaire[property] = form.getfirst(property)

        resource_database.write_questionnaire(questionnaire_key, questionnaire)
        end_with_success(None)
    else:
        end_with_status(403)
예제 #2
0
def patch_questionnaire_labels(questionnaire_key):
    if not resource_database.is_valid_resource_name(questionnaire_key):
        end_with_status(400)

    authorized_roles = get_authorized_roles()
    if len(authorized_roles) == 0:
        end_with_status(403)

    if "all" in authorized_roles or questionnaire_key in authorized_roles:
        questionnaire = resource_database.read_questionnaire(questionnaire_key)

        form = cgi.FieldStorage()

        possibleLabels = [
            "headline", "submit", "abort", "back", "submitQuestion",
            "errorInvalidForm", "errorDuringSubmission",
            "registrationSuccessful"
        ]

        for label in possibleLabels:
            if label in form:
                questionnaire["labels"][label] = form.getfirst(label)

        resource_database.write_questionnaire(questionnaire_key, questionnaire)
        end_with_success(None)
    else:
        end_with_status(403)
예제 #3
0
def get_questionnaire(questionnaire_key):
    if not resource_database.is_valid_resource_name(questionnaire_key):
        end_with_status(400)

    authorized_roles = get_authorized_roles(False)

    questionnaire = resource_database.read_questionnaire(questionnaire_key)

    if "all" in authorized_roles or questionnaire_key in authorized_roles or questionnaire[
            "public"]:
        end_with_success(questionnaire)
    else:
        end_with_status(403)
예제 #4
0
def get_questionnaire_labels(questionnaire_key):
    if not resource_database.is_valid_resource_name(questionnaire_key):
        end_with_status(400)

    authorized_roles = get_authorized_roles()
    if len(authorized_roles) == 0:
        end_with_status(403)

    if "all" in authorized_roles or questionnaire_key in authorized_roles:
        questionnaire = resource_database.read_questionnaire(questionnaire_key)
        labels = questionnaire["labels"]
        end_with_success(labels)
    else:
        end_with_status(403)
예제 #5
0
def get_questionnaire_properties(questionnaire_key):
    if not resource_database.is_valid_resource_name(questionnaire_key):
        end_with_status(400)

    authorized_roles = get_authorized_roles()
    if len(authorized_roles) == 0:
        end_with_status(403)

    if "all" in authorized_roles or questionnaire_key in authorized_roles:
        questionnaire = resource_database.read_questionnaire(questionnaire_key)
        properties = {
            "name": questionnaire["name"],
            "pictureUrl": questionnaire["pictureUrl"],
            "public": questionnaire["public"]
        }
        end_with_success(properties)
    else:
        end_with_status(403)
예제 #6
0
def get_all_questionnaires():
    authorized_roles = get_authorized_roles(False)

    all_questionnaires = resource_database.list_questionnaires()

    response = []

    for current_questionnaire_key in all_questionnaires:
        current_questionnaire_data = resource_database.read_questionnaire(
            current_questionnaire_key)

        public = current_questionnaire_data["public"]
        admin = (current_questionnaire_key
                 in authorized_roles) or ("all" in authorized_roles)

        if public or admin:
            response.append({
                "key": current_questionnaire_key,
                "public": public,
                "admin": admin
            })

    end_with_success(response)