Exemplo n.º 1
0
def test_to_plain():
    p = Point(x=10, y=20)
    p_plain = to_plain(p)
    assert len(p_plain) == 3
    assert p_plain["x"] == 10
    assert p_plain["y"] == 20
    assert p_plain["z"] == None
Exemplo n.º 2
0
 def get(self, request, assessment_id, topic_id):
     with db_context(db) as context:
         topic = load_topic(context, assessment_id, topic_id)
         return responses.Ok(
             to_plain(topic, relationships={
                 "aspects": {},
             }))
Exemplo n.º 3
0
 def insert_adt(self, context, table, instance):
     values = to_plain(instance)
     del values["id"]
     result = context.conn.execute(insert(table).values(values))
     inserted_id = result.inserted_primary_key[0]
     instance.attach(inserted_id)
     return instance
Exemplo n.º 4
0
    def post(self, request):
        validator = idea_validators.IdeaForCreateValidator(request.body)
        if validator.is_valid():
            if validator.cleaned_data["is_public"] and validator.cleaned_data.get("invited_usernames"):
                raise exceptions.BadRequest("Only private ideas can have invited users")

            invited_users = []
            for invited_username in validator.cleaned_data["invited_usernames"]:
                invited_user = load_user_secondary(invited_username)
                check_user_is_not_self(request.user, invited_user)
                invited_users.append(invited_user)

            data = deepcopy(validator.cleaned_data)
            del data["invited_usernames"]
            data["invited_users"] = invited_users

            idea = idea_actions.create_idea(
                request.user,
                idea_entities.IdeaForCreate(**data)
            )
            return responses.Ok(to_plain(
                idea,
                ignore_fields=["id", "is_active"],
                relationships={
                    "owner": {"ignore_fields": ["id", "password"]},
                }
            ))
        else:
            return responses.BadRequest(validator.errors)
    def get(self, request):
        with db_context(db) as context:

            assessments = assessment_actions.list_assessments(context)

            return responses.Ok(
                [to_plain(assessment) for assessment in assessments])
Exemplo n.º 6
0
    def patch(self, request, idea_uuid):
        idea = load_idea(idea_uuid)
        check_user_is_owner_of_idea(request.user, idea)

        validator = idea_validators.IdeaForUpdateValidator(request.body)
        if validator.is_valid():
            idea = idea_actions.update_idea(
                request.user,
                idea,
                idea_entities.IdeaForUpdate(**validator.cleaned_data)
            )
            return responses.Ok(to_plain(
                idea,
                ignore_fields=["id", "is_active"],
                relationships = {
                    "owner": {"ignore_fields": ["id", "password"]},
                    "forked_from": {
                        "only_fields": ["title"],
                        "relationships": {
                            "owner": {"ignore_fields": ["id", "password"]},
                        }
                    }
                }
            ))
        return responses.BadRequest(validator.errors)
Exemplo n.º 7
0
    def post(self, request, idea_uuid):
        idea = load_idea(idea_uuid)
        check_user_is_not_owner_of_idea(request.user, idea)

        forked_idea = idea_actions.fork_idea(request.user, idea)

        return responses.Ok(to_plain(forked_idea, ignore_fields=["id", "is_active"]))
Exemplo n.º 8
0
    def post(self, request, idea_uuid):
        idea = load_idea(idea_uuid)
        check_user_is_owner_of_idea(request.user, idea)

        project = idea_actions.promote_idea(request.user, idea)

        return responses.Ok(to_plain(project, ignore_fields=["id"]))
    def get(self, request, assessment_id):
        with db_context(db) as context:

            stakeholders = stakeholder_actions.list_stakeholders(
                context, assessment_id)

            return responses.Ok(
                [to_plain(stakeholder) for stakeholder in stakeholders])
Exemplo n.º 10
0
    def get(self, request, assessment_id):
        with db_context(db) as context:

            stakeholder_id = request.query_params.get('stakeholder')
            topics = topic_actions.list_topics(context, assessment_id,
                                               stakeholder_id)

            return responses.Ok([to_plain(topic) for topic in topics])
Exemplo n.º 11
0
def test_to_plain_complex():
    v = Vector(origin=Point(x=40, y=50, z=60), angle=45.0, modulus=100)
    v_plain = to_plain(v)
    assert len(v_plain) == 3
    assert v_plain["origin"]["x"] == 40
    assert v_plain["origin"]["y"] == 50
    assert v_plain["origin"]["z"] == 60
    assert v_plain["angle"] == 45.0
    assert v_plain["modulus"] == 100
Exemplo n.º 12
0
    def get(self, request, idea_uuid):
        idea = load_idea(idea_uuid)

        reactions = idea_actions.list_reactions(idea)
        return responses.Ok([
            to_plain(reaction, ignore_fields=["id"],
                relationships = {
                    "owner": {"ignore_fields": ["id", "password"]},
                }
            )
            for reaction in reactions
        ])
Exemplo n.º 13
0
    def get(self, request, idea_uuid):
        idea = load_idea(idea_uuid)

        invited_list = idea_actions.list_invited(idea)
        return responses.Ok([
            to_plain(invited, ignore_fields=["id", "idea_id"],
                relationships = {
                    "user": {"ignore_fields": ["id", "password"]},
                }
            )
            for invited in invited_list
        ])
Exemplo n.º 14
0
    def get(self, request, idea_uuid):
        idea = load_idea(idea_uuid)

        comments = idea_actions.list_comments(idea)
        return responses.Ok([
            to_plain(comment, ignore_fields=["id"],
                relationships = {
                    "owner": {"ignore_fields": ["id", "password"]},
                }
            )
            for comment in comments
        ])
Exemplo n.º 15
0
 def get(self, request, assessment_id, form_id):
     with db_context(db) as context:
         form = load_form(context, assessment_id, form_id)
         return responses.Ok(
             to_plain(form,
                      relationships={
                          "questions": {},
                          "sub_forms": {
                              "relationships": {
                                  "sub_questions": {}
                              }
                          }
                      }))
Exemplo n.º 16
0
    def post(self, request):
        username = request.body.get("username", "")
        password = request.body.get("password", "")
        user = user_actions.get_by_username_and_password(username, password)
        if not user:
            return responses.BadRequest({"error": "Invalid username or password"})
        else:
            token_data = {"user_id": user.id}
            serializer = JSONWebSignatureSerializer(settings.SECRET_KEY)
            token = serializer.dumps(token_data).decode("ascii")

            result = to_plain(user, ignore_fields=["id", "password"])
            result["token"] = token
            return responses.Ok(result)
Exemplo n.º 17
0
 def get(self, request, idea_uuid):
     idea = load_idea(idea_uuid)
     return responses.Ok(to_plain(
         idea,
         ignore_fields=["id", "is_active"],
         relationships = {
             "owner": {"ignore_fields": ["id", "password"]},
             "forked_from": {
                 "only_fields": ["title"],
                 "relationships": {
                     "owner": {"ignore_fields": ["id", "password"]},
                 }
             }
         }
     ))
Exemplo n.º 18
0
 def get(self, request):
     ideas = idea_actions.list_ideas(request.user)
     return responses.Ok([
         to_plain(idea, ignore_fields=["id", "is_active"],
             relationships = {
                 "owner": {"ignore_fields": ["id", "password"]},
                 "forked_from": {
                     "only_fields": ["title"],
                     "relationships": {
                         "owner": {"ignore_fields": ["id", "password"]},
                     }
                 }
             }
         )
         for idea in ideas
     ])
Exemplo n.º 19
0
    def patch(self, request, username):
        user = load_user(username)
        check_user_is_self(request.user, user)

        validator = user_validators.UserForUpdateValidator(request.body)
        if validator.is_valid():
            user = user_actions.update_user(
                user,
                user_entities.UserForUpdate(**validator.cleaned_data)
            )

            token_data = {"user_id": user.id}
            serializer = JSONWebSignatureSerializer(settings.SECRET_KEY)
            token = serializer.dumps(token_data).decode("ascii")

            result = to_plain(user, ignore_fields=["id", "password"])
            result["token"] = token
            return responses.Ok(result)
        else:
            return responses.BadRequest(validator.errors)
Exemplo n.º 20
0
    def post(self, request, idea_uuid):
        idea = load_idea(idea_uuid)

        validator = idea_validators.IdeaReactionForCreateValidator(request.body)
        if validator.is_valid():
            if not idea.is_public and idea.owner_id != request.user.id:
                check_user_is_invited_to_idea(request.user, idea)

            reaction = idea_actions.create_reaction(
                request.user,
                idea,
                idea_entities.IdeaReactionForCreate(**validator.cleaned_data)
            )
            return responses.Ok(to_plain(
                reaction,
                ignore_fields=["id"],
                relationships = {
                    "owner": {"ignore_fields": ["id", "password"]},
                }
            ))
        else:
            return responses.BadRequest(validator.errors)
 def get(self, request, assessment_id):
     with db_context(db) as context:
         assessment = load_assessment(context, assessment_id)
         return responses.Ok(to_plain(assessment))
Exemplo n.º 22
0
 def get(self, request):
     users = user_actions.list_users()
     return responses.Ok([
         to_plain(user, ignore_fields=["id", "password"])
         for user in users
     ])
Exemplo n.º 23
0
 def get(self, request, username):
     user = load_user(username)
     return responses.Ok(to_plain(user, ignore_fields=["id", "password"]))
Exemplo n.º 24
0
 def update_adt(self, context, table, instance):
     values = to_plain(instance)
     result = context.conn.execute(
         update(table).values(values).where(table.c.id == instance.id))
     return result.rowcount
Exemplo n.º 25
0
    def get(self, request, assessment_id):
        with db_context(db) as context:

            forms = form_actions.list_forms(context, assessment_id)

            return responses.Ok([to_plain(form) for form in forms])