def edit_note(request): """Edit content/metadata of individual note.""" req_data = json.loads(request.body.decode("utf8")) try: note_id = req_data["id"] except KeyError: return json_error("Note id is required") title = req_data.get("title") body = req_data.get("body") try: note = storage.get_note(note_id) note = actions.edit_note( note_id, title=title, body=body, permissions=get_perms(request.user.id, note.board_id), ) except DjangoStorage.DoesNotExist: return json_error("Note {} does not exist".format(note_id)) except PermissionError as e: return json_error(str(e), status=403) return json_success({"note": note.asdict()})
def create_board(request): """Create a new board.""" req_data = json.loads(request.body.decode("utf8")) try: name = req_data["name"] except KeyError: return json_error("Board name is required") board = actions.create_board(name=name, user_id=request.user.id) return json_success({"board": board.asdict()})
def create_board(request): """Create a new board.""" req_data = json.loads(request.body.decode('utf8')) try: name = req_data['name'] except KeyError: return json_error('Board name is required') board = actions.create_board(name=name, user_id=request.user.id) return json_success({'board': board.asdict()})
def get_note(request, note_id): """Display an individual note.""" try: note = storage.get_note(note_id) note = actions.get_note( note_id, permissions=get_perms(request.user.id, note.board_id) ) except DjangoStorage.DoesNotExist: return json_error("Note {} does not exist".format(note_id)) except PermissionError as e: return json_error(str(e), status=403) return json_success({"note": note.asdict()})
def delete_board(request): req_data = json.loads(request.body.decode("utf8")) try: board_id = req_data["id"] except KeyError: return json_error("Board id is required") try: board = actions.delete_board( id=board_id, permissions=get_perms(request.user.id, board_id) ) except PermissionError as e: return json_error(str(e), status=403) return json_success({"board": board.asdict()})
def remove_user_from_board(request): """Remove user from a board.""" req_data = json.loads(request.body.decode("utf8")) user_id = req_data.get("user_id") board_id = req_data.get("board_id") try: board_user = actions.remove_user_from_board( user_id=user_id, board_id=board_id, permissions=get_perms(request.user.id, board_id), ) except PermissionError as e: return json_error(str(e), status=403) return json_success({"board_user": board_user})
def add_user_to_board(request): """Add user to a board.""" req_data = json.loads(request.body.decode('utf8')) user_id = req_data.get('user_id') board_id = req_data.get('board_id') role = req_data.get('role') try: board = actions.add_user_to_board(user_id=user_id, board_id=board_id, role=role, permissions=get_perms( request.user.id, board_id)) except PermissionError as e: return json_error(str(e), status=403) return json_success({'board': board.asdict()})