Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: updated task_comment information to include if comment owned by user #1152

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ repos:
rev: 21.5b1
hooks:
- id: black
additional_dependencies: ['click==8.0.4']
args: [--check]
- repo: https://gitlab.com/pycqa/flake8
rev: 3.9.2
Expand Down
10 changes: 6 additions & 4 deletions app/api/dao/mentorship_relation.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,12 +136,14 @@ def list_mentorship_relations(user_id=None, state=None):
message: A message corresponding to the completed action; success if all relationships of a given user are listed, failure if otherwise.
"""
# To check if the entered 'state' is valid.
valid_states = ["PENDING", "ACCEPTED", "REJECTED", "CANCELLED", "COMPLETED"]
# valid_states = ["PENDING", "ACCEPTED", "REJECTED", "CANCELLED", "COMPLETED"]

def isValidState(rel_state):
if rel_state in valid_states:
return True
return False
try:
MentorshipRelationState[rel_state]
except KeyError:
return False
return True

user = UserModel.find_by_id(user_id)
all_relations = user.mentor_relations + user.mentee_relations
Expand Down
6 changes: 5 additions & 1 deletion app/api/models/task_comment.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@ def add_models_to_namespace(api_namespace):
"Task comments model",
{
"id": fields.Integer(required=True, description="Task comment's id."),
"user_id": fields.Integer(required=True, description="User's id."),
"sent_by_me": fields.Boolean(required=True, description="If sent by user."),
"user": {
"id": fields.Integer(required=True, description="User's id."),
"name": fields.String(required=True, description="User's name."),
},
"task_id": fields.Integer(required=True, description="Task's id."),
"relation_id": fields.Integer(required=True, description="Relation's id."),
"creation_date": fields.Float(
Expand Down
10 changes: 10 additions & 0 deletions app/database/models/task_comment.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class TaskCommentModel(db.Model):

id = db.Column(db.Integer, primary_key=True)
user_id = db.Column(db.Integer, db.ForeignKey("users.id"))
user_name = db.Column(db.String, db.ForeignKey("users.name"))
task_id = db.Column(db.Integer, db.ForeignKey("tasks_list.id"))
relation_id = db.Column(db.Integer, db.ForeignKey("mentorship_relations.id"))
creation_date = db.Column(db.Float, nullable=False)
Expand All @@ -40,8 +41,17 @@ def __init__(self, user_id, task_id, relation_id, comment):

def json(self):
"""Returns information of task comment as a JSON object."""
if self.id == self.user_id:
sent_by_me = True
else:
sent_by_me = False
return {
"id": self.id,
"sent_by_me": sent_by_me,
"user": {
"id": self.user_id,
"name": self.user_name,
},
"user_id": self.user_id,
"task_id": self.task_id,
"relation_id": self.relation_id,
Expand Down
3 changes: 1 addition & 2 deletions tests/admin/test_api_revoking_admin_role.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@
from app import messages
from app.database.models.user import UserModel
from app.database.sqlalchemy_extension import db

from tests.base_test_case import BaseTestCase
from tests.test_data import user1, test_admin_user_2
from tests.test_data import test_admin_user_2, user1
from tests.test_utils import get_test_request_header


Expand Down
10 changes: 2 additions & 8 deletions tests/user_journey/test_rejection_path.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,14 @@
from http import HTTPStatus

from flask import json
from flask_restx import marshal

from app import messages
from app.api.models.user import public_user_api_model
from app.database.models.mentorship_relation import MentorshipRelationModel
from app.utils.enum_utils import MentorshipRelationState
from app.database.models.tasks_list import TasksListModel
from app.database.models.user import UserModel
from app.database.sqlalchemy_extension import db
from app.utils.enum_utils import MentorshipRelationState
from tests.base_test_case import BaseTestCase
from tests.test_utils import get_test_request_header
from tests.test_data import user1, user2
from app.api.models.mentorship_relation import mentorship_request_response_body
from tests.test_utils import get_test_request_header


class TestRejectionPath(BaseTestCase):
Expand Down Expand Up @@ -118,7 +112,7 @@ def test_rejection_path(self):

# Mentee discovers that the request has been rejected
mentee_current_rejected_relation = self.client.get(
f"/mentorship_relations/current", headers=mentee_auth_header
"/mentorship_relations/current", headers=mentee_auth_header
)
self.assertEqual(HTTPStatus.OK, mentee_current_rejected_relation.status_code)

Expand Down