Skip to content

Commit

Permalink
Allow moving tasks across columns
Browse files Browse the repository at this point in the history
  • Loading branch information
McSinyx committed Feb 22, 2021
1 parent d6ece96 commit 7b8c8ae
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 7 deletions.
34 changes: 30 additions & 4 deletions src/acanban/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@

__all__ = ['blueprint']

BASE_ROUTE = '/p/<uuid>/tasks/<int:index>'
blueprint = Blueprint('task', __name__)
blueprint = Blueprint('task', __name__,
url_prefix='/p/<uuid>/tasks/<int:index>')


def task_query(project_id: str, index: int) -> RqlQuery:
Expand All @@ -40,7 +40,7 @@ def task_query(project_id: str, index: int) -> RqlQuery:
return project['tasks'].order_by('created_on')[index]


@blueprint.route(BASE_ROUTE)
@blueprint.route('/')
@login_required
async def display(uuid: str, index: int) -> ResponseReturnValue:
"""Display task discussion."""
Expand All @@ -51,6 +51,32 @@ async def display(uuid: str, index: int) -> ResponseReturnValue:
route=f'/p/{uuid}/tasks/{index}')


@blueprint.route('/dec')
@login_required
async def move_backward(uuid: str, index: int) -> ResponseReturnValue:
"""Move the task to the previous column."""
await pluck_project(uuid) # check authority
async with current_app.db_pool.connection() as conn:
task = await task_query(uuid, index).run(conn)
updated = {'tasks': r.row['tasks'].order_by('created_on').change_at(
index, {**task, 'status': max(0, task['status']-1)})}
await r.table('projects').get(uuid).update(updated).run(conn)
return redirect(request.referrer)


@blueprint.route('/inc')
@login_required
async def move_forward(uuid: str, index: int) -> ResponseReturnValue:
"""Move the task to the next column."""
await pluck_project(uuid) # check authority
async with current_app.db_pool.connection() as conn:
task = await task_query(uuid, index).run(conn)
updated = {'tasks': r.row['tasks'].order_by('created_on').change_at(
index, {**task, 'status': min(2, task['status']+1)})}
await r.table('projects').get(uuid).update(updated).run(conn)
return redirect(request.referrer)


def flatten_replies(comment: Dict[str, Any]) -> Iterator[Dict[str, Any]]:
"""Recursively walk through the nested replies."""
yield comment
Expand All @@ -59,7 +85,7 @@ def flatten_replies(comment: Dict[str, Any]) -> Iterator[Dict[str, Any]]:
yield from flatten_replies(reply)


@blueprint.route(f'{BASE_ROUTE}/reply/<float:parent>', methods=['POST'])
@blueprint.route('/reply/<float:parent>', methods=['POST'])
@login_required
async def save_reply(uuid: str, index: int,
parent: float) -> ResponseReturnValue:
Expand Down
4 changes: 2 additions & 2 deletions stubs/rethinkdb/ast.pyi
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Any
from typing import Any, Dict, Union

from .trio_net.net_trio import Connection

Expand All @@ -7,7 +7,7 @@ class RqlQuery:

def count(self) -> RqlQuery: ...
def filter(self, predicate: dict) -> RqlQuery: ...
def pluck(self, *selectors: str) -> RqlQuery: ...
def pluck(self, *selectors: Union[str, Dict[str, Any]]) -> RqlQuery: ...
def order_by(self, key: str) -> RqlQuery: ...
def update(self, obj: dict) -> RqlQuery: ...

Expand Down
16 changes: 15 additions & 1 deletion tests/test_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,21 @@ async def test_get(username: Optional[str], status_code: int,
user: ClientFactory) -> None:
"""Test task access permission."""
client = await user(username)
response = await client.get(BASE_ROUTE)
response = await client.get(f'{BASE_ROUTE}/')
assert response.status_code == status_code


@parametrize(('username', 'status_code'),
(param(None, Status.UNAUTHORIZED, id='guest'),
param('silasl', Status.FORBIDDEN, id='assistant'),
param('adaml', Status.FORBIDDEN, id='nonmember'),
param('ronanf', Status.FOUND, id='member')))
@parametrize('direction', ('dec', 'inc'))
async def test_move(username: Optional[str], status_code: int,
user: ClientFactory, direction: str) -> None:
"""Test moving task across columns."""
client = await user(username)
response = await client.get(f'{BASE_ROUTE}/{direction}')
assert response.status_code == status_code


Expand Down

0 comments on commit 7b8c8ae

Please sign in to comment.