def task_is_valid_put(task, original_task): """Check that task can be update. """ # Check that creator_id of task can't be changed. if task.creator_id and task.creator_id != original_task.creator_id: abort(400, _("You can't change author of task.")) # Set project_id if it isn't in request. if not task.project_id: task.project_id = original_task.project_id # Set branch_id if it isn't in request. if not task.branch_id: task.branch_id = original_task.branch_id # Check that branch is valid for this task. If project_id was changed, # task will be associated with master branch of this project, because # client doesn't support branches. if task.project_id == original_task.project_id: branch_is_valid(task) else: task.branch_id = branches_api.branch_get_master_branch( task.project_id ).id # Check that task ready to associate with milestone if milestone_id in # request. if task.milestone_id: if original_task.status != 'merged' and task.status != 'merged': abort(400, _("Milestones can only be associated with merged tasks")) if (original_task.status == 'merged' and task.status and task.status != 'merged'): abort(400, _("Milestones can only be associated with merged tasks")) elif 'milestone_id' in task.as_dict(omit_unset=True): return task # Set milestone id if task status isn't 'merged' or if original task # has milestone_id. if task.status and task.status != 'merged': task.milestone_id = None elif not task.milestone_id and original_task.milestone_id: task.milestone_id = original_task.milestone_id # Check that milestone is valid for this task. if task.milestone_id: milestone_is_valid(task) return task
def task_is_valid_post(task): """Check that task can be created. """ # Check that task author didn't change creator_id. if task.creator_id and task.creator_id != request.current_user_id: abort(400, _("You can't select author of task.")) # Check that project_id is in request if not task.project_id: abort(400, _("You must select a project for task.")) # Check that story_id is in request if not task.story_id: abort(400, _("You must select a story for task.")) # Set branch_id to 'master' branch defaults and check that # branch is valid for this task. branch = None if not task.branch_id: branch = branches_api.branch_get_master_branch( task.project_id ) task.branch_id = branch.id else: branch = branch_is_valid(task) # Check that branch is restricted if story type is restricted story_is_valid(task, branch) # Check that task status is merged and milestone is valid for this task # if milestone_id is in request. if task.milestone_id: if task.status != 'merged': abort(400, _("Milestones can only be associated with merged tasks")) milestone_is_valid(task) return task