|  |  | @ -116,3 +116,31 @@ func (r *mutationResolver) EditComment(ctx context.Context, input input.CommentE | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  | 	return comment, nil | 
			
		
	
		
			
				
					|  |  |  | } | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  | func (r *mutationResolver) RemoveComment(ctx context.Context, input input.CommentRemoveInput) (models.Comment, error) { | 
			
		
	
		
			
				
					|  |  |  | 	comment, err := comments.Find(input.CommentID) | 
			
		
	
		
			
				
					|  |  |  | 	if err != nil { | 
			
		
	
		
			
				
					|  |  |  | 		return models.Comment{}, errors.New("Comment not found") | 
			
		
	
		
			
				
					|  |  |  | 	} | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  | 	token := auth.TokenFromContext(ctx) | 
			
		
	
		
			
				
					|  |  |  | 	if !token.PermittedUser(comment.Author, "member", "story.edit") { | 
			
		
	
		
			
				
					|  |  |  | 		return models.Comment{}, errors.New("You cannot remove this comment") | 
			
		
	
		
			
				
					|  |  |  | 	} | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  | 	chapter, err := chapters.FindID(comment.ChapterID) | 
			
		
	
		
			
				
					|  |  |  | 	if err != nil { | 
			
		
	
		
			
				
					|  |  |  | 		return models.Comment{}, errors.New("Comment's chapter not found") | 
			
		
	
		
			
				
					|  |  |  | 	} | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  | 	if !chapter.CanComment() { | 
			
		
	
		
			
				
					|  |  |  | 		return models.Comment{}, errors.New("Comments are disabled or locked") | 
			
		
	
		
			
				
					|  |  |  | 	} | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  | 	err = comments.Remove(comment) | 
			
		
	
		
			
				
					|  |  |  | 	if err != nil { | 
			
		
	
		
			
				
					|  |  |  | 		return models.Comment{}, errors.New("Failed to remove comment: " + err.Error()) | 
			
		
	
		
			
				
					|  |  |  | 	} | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  | 	return comment, nil | 
			
		
	
		
			
				
					|  |  |  | } |