|  | @@ -0,0 +1,29 @@
 | 
	
		
			
			|  | 1 | +import tg
 | 
	
		
			
			|  | 2 | +from tg import request
 | 
	
		
			
			|  | 3 | +from tg import RestController
 | 
	
		
			
			|  | 4 | +from tracim.lib.content import ContentApi
 | 
	
		
			
			|  | 5 | +from tracim.lib.user import UserApi
 | 
	
		
			
			|  | 6 | +from tracim.model.data import ContentType
 | 
	
		
			
			|  | 7 | +
 | 
	
		
			
			|  | 8 | +VALID_TOKEN_VALUE="djkflhqsfhyqsdb fq"
 | 
	
		
			
			|  | 9 | +
 | 
	
		
			
			|  | 10 | +class EventsRestController(RestController):
 | 
	
		
			
			|  | 11 | +
 | 
	
		
			
			|  | 12 | +
 | 
	
		
			
			|  | 13 | +    @tg.expose('json')
 | 
	
		
			
			|  | 14 | +    def post(self):
 | 
	
		
			
			|  | 15 | +        json = request.json_body
 | 
	
		
			
			|  | 16 | +        if 'token' in json and json['token'] == VALID_TOKEN_VALUE:
 | 
	
		
			
			|  | 17 | +            ## TODO check json content
 | 
	
		
			
			|  | 18 | +            uapi = UserApi(None)
 | 
	
		
			
			|  | 19 | +            ## TODO support Empty result error
 | 
	
		
			
			|  | 20 | +            user = uapi.get_one_by_email(json['user_mail'])
 | 
	
		
			
			|  | 21 | +            api = ContentApi(user)
 | 
	
		
			
			|  | 22 | +
 | 
	
		
			
			|  | 23 | +            thread = api.get_one(json['content_id'],content_type=ContentType.Any)
 | 
	
		
			
			|  | 24 | +            ## TODO Check type ? Commebt Not allowed for Folder
 | 
	
		
			
			|  | 25 | +            api.create_comment(thread.workspace, thread, json['payload']['content'], True)
 | 
	
		
			
			|  | 26 | +        else:
 | 
	
		
			
			|  | 27 | +            return {'status': 'error',
 | 
	
		
			
			|  | 28 | +                    'error': 'invalid token'}
 | 
	
		
			
			|  | 29 | +        return json
 |