|  | @@ -24,7 +24,8 @@ from sqlalchemy.sql.elements import and_
 | 
	
		
			
			| 24 | 24 |  
 | 
	
		
			
			| 25 | 25 |  from tracim.lib.utils.utils import cmp_to_key
 | 
	
		
			
			| 26 | 26 |  from tracim.lib.core.notifications import NotifierFactory
 | 
	
		
			
			| 27 |  | -from tracim.exceptions import SameValueError, EmptyRawContentNotAllowed
 | 
	
		
			
			|  | 27 | +from tracim.exceptions import SameValueError
 | 
	
		
			
			|  | 28 | +from tracim.exceptions import EmptyCommentContentNotAllowed
 | 
	
		
			
			| 28 | 29 |  from tracim.exceptions import EmptyLabelNotAllowed
 | 
	
		
			
			| 29 | 30 |  from tracim.exceptions import ContentNotFound
 | 
	
		
			
			| 30 | 31 |  from tracim.exceptions import WorkspacesDoNotMatch
 | 
	
	
		
			
			|  | @@ -394,20 +395,28 @@ class ContentApi(object):
 | 
	
		
			
			| 394 | 395 |          return result
 | 
	
		
			
			| 395 | 396 |  
 | 
	
		
			
			| 396 | 397 |      def create(self, content_type: str, workspace: Workspace, parent: Content=None, label: str ='', filename: str = '', do_save=False, is_temporary: bool=False, do_notify=True) -> Content:
 | 
	
		
			
			|  | 398 | +        # TODO - G.M - 2018-07-16 - raise Exception instead of assert
 | 
	
		
			
			| 397 | 399 |          assert content_type in ContentType.allowed_types()
 | 
	
		
			
			|  | 400 | +        assert not (label and filename)
 | 
	
		
			
			| 398 | 401 |  
 | 
	
		
			
			| 399 | 402 |          if content_type == ContentType.Folder and not label:
 | 
	
		
			
			| 400 | 403 |              label = self.generate_folder_label(workspace, parent)
 | 
	
		
			
			| 401 | 404 |  
 | 
	
		
			
			| 402 | 405 |          content = Content()
 | 
	
		
			
			| 403 |  | -        if label:
 | 
	
		
			
			| 404 |  | -            content.label = label
 | 
	
		
			
			| 405 |  | -        elif filename:
 | 
	
		
			
			| 406 |  | -            # TODO - G.M - 2018-07-04 - File_name setting automatically
 | 
	
		
			
			|  | 406 | +
 | 
	
		
			
			|  | 407 | +        if filename:
 | 
	
		
			
			|  | 408 | +            # INFO - G.M - 2018-07-04 - File_name setting automatically
 | 
	
		
			
			| 407 | 409 |              # set label and file_extension
 | 
	
		
			
			| 408 | 410 |              content.file_name = label
 | 
	
		
			
			|  | 411 | +        elif label:
 | 
	
		
			
			|  | 412 | +            content.label = label
 | 
	
		
			
			| 409 | 413 |          else:
 | 
	
		
			
			| 410 |  | -            raise EmptyLabelNotAllowed()
 | 
	
		
			
			|  | 414 | +            if content_type == ContentType.Comment:
 | 
	
		
			
			|  | 415 | +                # INFO - G.M - 2018-07-16 - Default label for comments is
 | 
	
		
			
			|  | 416 | +                # empty string.
 | 
	
		
			
			|  | 417 | +                content.label = ''
 | 
	
		
			
			|  | 418 | +            else:
 | 
	
		
			
			|  | 419 | +                raise EmptyLabelNotAllowed('Content of this type should have a valid label')  # nopep8
 | 
	
		
			
			| 411 | 420 |  
 | 
	
		
			
			| 412 | 421 |          content.owner = self._user
 | 
	
		
			
			| 413 | 422 |          content.parent = parent
 | 
	
	
		
			
			|  | @@ -430,11 +439,11 @@ class ContentApi(object):
 | 
	
		
			
			| 430 | 439 |      def create_comment(self, workspace: Workspace=None, parent: Content=None, content:str ='', do_save=False) -> Content:
 | 
	
		
			
			| 431 | 440 |          assert parent and parent.type != ContentType.Folder
 | 
	
		
			
			| 432 | 441 |          if not content:
 | 
	
		
			
			| 433 |  | -            raise EmptyRawContentNotAllowed()
 | 
	
		
			
			|  | 442 | +            raise EmptyCommentContentNotAllowed()
 | 
	
		
			
			| 434 | 443 |          item = Content()
 | 
	
		
			
			| 435 | 444 |          item.owner = self._user
 | 
	
		
			
			| 436 | 445 |          item.parent = parent
 | 
	
		
			
			| 437 |  | -        if parent and not workspace:
 | 
	
		
			
			|  | 446 | +        if not workspace:
 | 
	
		
			
			| 438 | 447 |              workspace = item.parent.workspace
 | 
	
		
			
			| 439 | 448 |          item.workspace = workspace
 | 
	
		
			
			| 440 | 449 |          item.type = ContentType.Comment
 | 
	
	
		
			
			|  | @@ -446,7 +455,6 @@ class ContentApi(object):
 | 
	
		
			
			| 446 | 455 |              self.save(item, ActionDescription.COMMENT)
 | 
	
		
			
			| 447 | 456 |          return item
 | 
	
		
			
			| 448 | 457 |  
 | 
	
		
			
			| 449 |  | -
 | 
	
		
			
			| 450 | 458 |      def get_one_from_revision(self, content_id: int, content_type: str, workspace: Workspace=None, revision_id=None) -> Content:
 | 
	
		
			
			| 451 | 459 |          """
 | 
	
		
			
			| 452 | 460 |          This method is a hack to convert a node revision item into a node
 | 
	
	
		
			
			|  | @@ -483,6 +491,11 @@ class ContentApi(object):
 | 
	
		
			
			| 483 | 491 |          try:
 | 
	
		
			
			| 484 | 492 |              content = base_request.one()
 | 
	
		
			
			| 485 | 493 |          except NoResultFound as exc:
 | 
	
		
			
			|  | 494 | +            # TODO - G.M - 2018-07-16 - Add better support for all different
 | 
	
		
			
			|  | 495 | +            # error case who can happened here
 | 
	
		
			
			|  | 496 | +            # like content doesn't exist, wrong parent, wrong content_type, wrong workspace,
 | 
	
		
			
			|  | 497 | +            # wrong access to this workspace, wrong base filter according
 | 
	
		
			
			|  | 498 | +            # to content_status.
 | 
	
		
			
			| 486 | 499 |              raise ContentNotFound('Content "{}" not found in database'.format(content_id)) from exc  # nopep8
 | 
	
		
			
			| 487 | 500 |          return content
 | 
	
		
			
			| 488 | 501 |  
 |