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

Enhancement : Require mentor's approval for task completion #1130

Open
wants to merge 1 commit 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
10 changes: 9 additions & 1 deletion app/api/dao/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ def create_task(user_id: int, mentorship_relation_id: int, data: Dict[str, str])
"""

description = data["description"]
if 'requires_approval' in data.keys():
requires_approval = data['requires_approval']
else:
requires_approval = False
Comment on lines +33 to +36
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if 'requires_approval' in data.keys():
requires_approval = data['requires_approval']
else:
requires_approval = False
requires_approval = data.get('requires_approval') or False


user = UserModel.find_by_id(user_id)
relation = MentorshipRelationModel.find_by_id(_id=mentorship_relation_id)
Expand All @@ -46,7 +50,8 @@ def create_task(user_id: int, mentorship_relation_id: int, data: Dict[str, str])
)

now_timestamp = datetime.utcnow().timestamp()
relation.tasks_list.add_task(description=description, created_at=now_timestamp)
relation.tasks_list.add_task(description=description, created_at=now_timestamp,
requires_approval=requires_approval)
relation.tasks_list.save_to_db()

return messages.TASK_WAS_CREATED_SUCCESSFULLY, HTTPStatus.CREATED
Expand Down Expand Up @@ -153,6 +158,9 @@ def complete_task(user_id: int, mentorship_relation_id: int, task_id: int):
if task is None:
return messages.TASK_DOES_NOT_EXIST, HTTPStatus.NOT_FOUND

if user_id == relation.mentee_id and task.get('requires_approval'):
return messages.TASK_REQUIRES_APPROVAL, HTTPStatus.UNAUTHORIZED

if task.get("is_done"):
return messages.TASK_WAS_ALREADY_ACHIEVED, HTTPStatus.CONFLICT
else:
Expand Down
4 changes: 3 additions & 1 deletion app/api/models/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ def add_models_to_namespace(api_namespace):
{
"description": fields.String(
required=True, description="Mentorship relation task description"
)
),
'requires_approval': fields.Boolean(required=False, description='If true, only mentor can mark task as completed.')
},
)

Expand All @@ -28,5 +29,6 @@ def add_models_to_namespace(api_namespace):
"completed_at": fields.Float(
required=False, description="Task completion date in UNIX timestamp format"
),
'requires_approval': fields.Boolean(required=False, description='If true, only mentor can mark task as completed.')
},
)
6 changes: 5 additions & 1 deletion app/database/models/tasks_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def __init__(self, tasks: "TasksListModel" = None):
raise ValueError(TypeError)

def add_task(
self, description: str, created_at: date, is_done=False, completed_at=None
self, description: str, created_at: date, is_done=False, completed_at=None,requires_approval=False
) -> None:
"""Adds a task to the list of tasks.

Expand All @@ -51,6 +51,7 @@ def add_task(
created_at: Date on which the task is created.
is_done: Boolean specifying completion of the task.
completed_at: Date on which task is completed.
requires_approval: Boolean specifying whether mentee can mark task as completed on his own.
"""

task = {
Expand All @@ -59,6 +60,7 @@ def add_task(
TasksFields.IS_DONE.value: is_done,
TasksFields.CREATED_AT.value: created_at,
TasksFields.COMPLETED_AT.value: completed_at,
TasksFields.REQUIRES_APPROVAL.value: requires_approval
}
self.next_task_id += 1
self.tasks = self.tasks + [task]
Expand Down Expand Up @@ -195,13 +197,15 @@ class TasksFields(Enum):
IS_DONE: Boolean specifying the completion of the task.
COMPLETED_AT: The date on which the task is completed.
CREATED_AT: The date on which the task was created.
REQUIRES_APPROVAL: Boolean specifying whether mentee can mark task as completed on his own.
"""

ID = "id"
DESCRIPTION = "description"
IS_DONE = "is_done"
COMPLETED_AT = "completed_at"
CREATED_AT = "created_at"
REQUIRES_APPROVAL = 'requires_approval'

def values(self):
"""Returns a list containing a task."""
Expand Down
1 change: 1 addition & 0 deletions app/messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
TASK_COMMENT_WITH_GIVEN_TASK_ID_DOES_NOT_EXIST = {
"message": "Task comment with given task id does not exist."
}
TASK_REQUIRES_APPROVAL = {"message": "Task requires mentor's approval."}

# Missing fields
MENTOR_ID_FIELD_IS_MISSING = {"message": "Mentor ID field is missing."}
Expand Down