def story_can_mutate(story, new_story_type_id): if not new_story_type_id: return True if story.story_type_id == new_story_type_id: return True old_story_type = story_types.story_type_get(story.story_type_id) new_story_type = story_types.story_type_get(new_story_type_id) if not new_story_type: raise exc.NotFound(_("Story type %s not found.") % new_story_type_id) if not old_story_type.private and new_story_type.private: return False mutation = story_types.story_type_get_mutations(story.story_type_id, new_story_type_id) if not mutation: return False if not new_story_type.restricted: return True query = api_base.model_query(models.Task) query = query.filter_by(story_id=story.id) tasks = query.all() branch_ids = set() for task in tasks: if task.branch_id: branch_ids.add(task.branch_id) branch_ids = list(branch_ids) query = api_base.model_query(models.Branch) branch = query.filter(models.Branch.id.in_(branch_ids), models.Branch.restricted.__eq__(1)).first() if not branch: return True return False
def story_can_create_story(story_type_id): if not story_type_id: return True story_type = story_types.story_type_get(story_type_id) if not story_type: raise exc.NotFound("Story type %s not found." % story_type_id) if not story_type.visible: return False return True
def story_is_valid(task, branch): """Check that branch is restricted if story type is restricted. """ story = stories_api.story_get(task.story_id) if not story: raise exc.NotFound("Story %s not found." % task.story_id) story_type = story_types_api.story_type_get(story.story_type_id) if story_type.restricted: if not branch.restricted: abort(400, _("Branch %s must be restricted.") % branch.id)
def story_is_valid(task, branch): """Check that branch is restricted if story type is restricted. """ story = stories_api.story_get( task.story_id, current_user=request.current_user_id) if not story: raise exc.NotFound("Story %s not found." % task.story_id) story_type = story_types_api.story_type_get(story.story_type_id) if story_type.restricted: if not branch.restricted: abort(400, _("Branch %s must be restricted.") % branch.id)