def setUp(self): super(CommentsTest, self).setUp() self.comment_01 = { 'content': u'A comment', 'story_id': 1 } stories.story_create({"name": "Test Story"})
def setUp(self): super(TasksTest, self).setUp() self.task_01 = { 'title': u'Invent time machine', 'status': 'todo', 'story_id': 1 } stories.story_create({"name": "Test Story"}) users.user_create({"fullname": "Test User"})
def post(self, story): """Create a new story. :param story: A story within the request body. """ # Reject private story types while ACL is not created. if (story.story_type_id and (story.story_type_id == 3 or story.story_type_id == 4)): abort(400, _("Now you can't add story with type %s.") % story.story_type_id) story_dict = story.as_dict() user_id = request.current_user_id if story.creator_id and story.creator_id != user_id: abort(400, _("You can't select author of story.")) story_dict.update({"creator_id": user_id}) if not stories_api.story_can_create_story(story.story_type_id): abort(400, _("Can't create story of this type.")) if not "tags" in story_dict or not story_dict["tags"]: story_dict["tags"] = [] # We can't set due dates when creating stories at the moment. if "due_dates" in story_dict: del story_dict['due_dates'] created_story = stories_api.story_create(story_dict) events_api.story_created_event(created_story.id, user_id, story.title) return wmodels.Story.from_db_model(created_story)
def post(self, story): """Create a new story. Example:: curl 'https://my.example.org/api/v1/stories' \\ -H 'Authorization: Bearer MY_ACCESS_TOKEN' \\ -H 'Content-Type: application/json;charset=UTF-8' \\ --data-binary '{"title":"Test Story","description":"A test story."}' :param story: A story within the request body. """ # Reject private story types while ACL is not created. if (story.story_type_id and (story.story_type_id == 3 or story.story_type_id == 4)): abort(400, _("Now you can't add story with type %s.") % story.story_type_id) story_dict = story.as_dict() user_id = request.current_user_id if story.creator_id and story.creator_id != user_id: abort(400, _("You can't select author of story.")) story_dict.update({"creator_id": user_id}) if not stories_api.story_can_create_story(story.story_type_id): abort(400, _("Can't create story of this type.")) if "tags" not in story_dict or not story_dict["tags"]: story_dict["tags"] = [] # We can't set due dates when creating stories at the moment. if "due_dates" in story_dict: del story_dict['due_dates'] users = None teams = None # We make sure that a user cannot remove all users and teams # from the permissions list for a story # This should be reworked so that users can be removed if there # are teams, and vice versa if "teams" in story_dict: teams = story_dict.pop("teams") if teams is None: teams = [] if "users" in story_dict: users = story_dict.pop("users") if users is None or (users == [] and teams == []): users = [wmodels.User.from_db_model(users_api.user_get(user_id))] created_story = stories_api.story_create(story_dict) events_api.story_created_event(created_story.id, user_id, story.title) if story.private: stories_api.create_permission(created_story, users, teams) return wmodels.Story.from_db_model(created_story)
def post(self, story): """Create a new story. :param story: A story within the request body. """ # Reject private story types while ACL is not created. if (story.story_type_id and (story.story_type_id == 3 or story.story_type_id == 4)): abort( 400, _("Now you can't add story with type %s.") % story.story_type_id) story_dict = story.as_dict() user_id = request.current_user_id if story.creator_id and story.creator_id != user_id: abort(400, _("You can't select author of story.")) story_dict.update({"creator_id": user_id}) if not stories_api.story_can_create_story(story.story_type_id): abort(400, _("Can't create story of this type.")) if not "tags" in story_dict or not story_dict["tags"]: story_dict["tags"] = [] # We can't set due dates when creating stories at the moment. if "due_dates" in story_dict: del story_dict['due_dates'] users = [] if "users" in story_dict: users = story_dict.pop("users") if users is None: users = [wmodels.User.from_db_model(users_api.user_get(user_id))] created_story = stories_api.story_create(story_dict) events_api.story_created_event(created_story.id, user_id, story.title) if story.private: stories_api.create_permission(created_story, users) return wmodels.Story.from_db_model(created_story)
def post(self, story): """Create a new story. Example:: curl 'https://my.example.org/api/v1/stories' \\ -H 'Authorization: Bearer MY_ACCESS_TOKEN' \\ -H 'Content-Type: application/json;charset=UTF-8' \\ --data-binary '{"title":"Test Story","description":"A test story."}' :param story: A story within the request body. """ # Reject private story types while ACL is not created. if (story.story_type_id and (story.story_type_id == 3 or story.story_type_id == 4)): abort( 400, _("Now you can't add story with type %s.") % story.story_type_id) story_dict = story.as_dict() user_id = request.current_user_id if story.creator_id and story.creator_id != user_id: abort(400, _("You can't select author of story.")) story_dict.update({"creator_id": user_id}) if not stories_api.story_can_create_story(story.story_type_id): abort(400, _("Can't create story of this type.")) if "tags" not in story_dict or not story_dict["tags"]: story_dict["tags"] = [] # We can't set due dates when creating stories at the moment. if "due_dates" in story_dict: del story_dict['due_dates'] users = None teams = None # We make sure that a user cannot remove all users and teams # from the permissions list for a story # This should be reworked so that users can be removed if there # are teams, and vice versa if "teams" in story_dict: teams = story_dict.pop("teams") if teams is None: teams = [] if "users" in story_dict: users = story_dict.pop("users") if users is None or (users == [] and teams == []): users = [wmodels.User.from_db_model(users_api.user_get(user_id))] created_story = stories_api.story_create(story_dict) events_api.story_created_event(created_story.id, user_id, story.title) if story.private: stories_api.create_permission(created_story, users, teams) return wmodels.Story.from_db_model(created_story)
def setUp(self): super(CommentsTest, self).setUp() self.comment_01 = {'content': u'A comment', 'story_id': 1} stories.story_create({"name": "Test Story"})