def post(self, due_date): """Create a new due date. :param due_date: A due date within the request body. """ due_date_dict = due_date.as_dict() user_id = request.current_user_id if due_date.creator_id and due_date.creator_id != user_id: abort(400, _("You can't select the creator of a due date.")) due_date_dict.update({'creator_id': user_id}) board_id = due_date_dict.pop('board_id') worklist_id = due_date_dict.pop('worklist_id') if 'stories' in due_date_dict: del due_date_dict['stories'] if 'tasks' in due_date_dict: del due_date_dict['tasks'] owners = due_date_dict.pop('owners') users = due_date_dict.pop('users') if not owners: owners = [user_id] if not users: users = [] created_due_date = due_dates_api.create(due_date_dict) if board_id is not None: date = due_dates_api.get(created_due_date.id) date.boards.append(boards_api.get(board_id)) if worklist_id is not None: date = due_dates_api.get(created_due_date.id) date.worklists.append(worklists_api.get(worklist_id)) edit_permission = { 'name': 'edit_due_date_%d' % created_due_date.id, 'codename': 'edit_date', 'users': owners } assign_permission = { 'name': 'assign_due_date_%d' % created_due_date.id, 'codename': 'assign_date', 'users': users } due_dates_api.create_permission(created_due_date.id, edit_permission) due_dates_api.create_permission(created_due_date.id, assign_permission) created_due_date = due_dates_api.get(created_due_date.id) due_date_model = wmodels.DueDate.from_db_model(created_due_date) due_date_model.resolve_items(created_due_date) due_date_model.resolve_permissions(created_due_date, request.current_user_id) return due_date_model
def post(self, due_date): """Create a new due date. :param due_date: A due date within the request body. """ due_date_dict = due_date.as_dict() user_id = request.current_user_id if due_date.creator_id and due_date.creator_id != user_id: abort(400, _("You can't select the creator of a due date.")) due_date_dict.update({"creator_id": user_id}) board_id = due_date_dict.pop("board_id") worklist_id = due_date_dict.pop("worklist_id") if "stories" in due_date_dict: del due_date_dict["stories"] if "tasks" in due_date_dict: del due_date_dict["tasks"] owners = due_date_dict.pop("owners") users = due_date_dict.pop("users") if not owners: owners = [user_id] if not users: users = [] created_due_date = due_dates_api.create(due_date_dict) if board_id is not None: date = due_dates_api.get(created_due_date.id) date.boards.append(boards_api.get(board_id)) if worklist_id is not None: date = due_dates_api.get(created_due_date.id) date.worklists.append(worklists_api.get(worklist_id)) edit_permission = {"name": "edit_due_date_%d" % created_due_date.id, "codename": "edit_date", "users": owners} assign_permission = { "name": "assign_due_date_%d" % created_due_date.id, "codename": "assign_date", "users": users, } due_dates_api.create_permission(created_due_date.id, edit_permission) due_dates_api.create_permission(created_due_date.id, assign_permission) created_due_date = due_dates_api.get(created_due_date.id) due_date_model = wmodels.DueDate.from_db_model(created_due_date) due_date_model.resolve_items(created_due_date) due_date_model.resolve_permissions(created_due_date, request.current_user_id) return due_date_model
def post(self, due_date_id, permission): """Add a new permission to the due date. :param due_date_id: The ID of the due date. :param permission: The dict used to create the permission. """ if due_dates_api.editable(due_dates_api.get(due_date_id), request.current_user_id): return due_dates_api.create_permission(due_date_id, permission) else: raise exc.NotFound(_("Due date %s not found") % due_date_id)