fetchCommentDB
    :: CommentId
    -> ExprCommentCond
    -> DB (Either NoCommentReason Comment)
fetchCommentDB comment_id has_permission = get comment_id >>= \case
    Nothing -> do
        liftIO $
            appendFile "log" $ "comment not found: " ++ show comment_id ++ "\n"
        return (Left CommentNotFound)
    -- Hooray, the comment exists, now toss it and re-query the database
    -- with the provided permission conditions. How else would we be able
    -- to differentiate a non-existent comment and a comment the user
    -- doesn't have permission to view?
    Just _ -> fmap
        (maybe
            (Left CommentPermissionDenied)
            (Right . entityVal) . listToMaybe) $
        select $
        from $ \c -> do
        where_ $
            c ^. CommentId ==. val comment_id &&.
            has_permission c
        return c

-- | Count the visible comments in a given discussion.
--
-- Visibility depends on who the user is.
fetchCommentDB
    :: CommentId
    -> ExprCommentCond
    -> DB (Either NoCommentReason Comment)
fetchCommentDB comment_id has_permission = get comment_id >>= \case
    Nothing -> do
        liftIO $
            appendFile "log" $ "comment not found: " ++ show comment_id ++ "\n"
        return (Left CommentNotFound)
    -- Hooray, the comment exists, now toss it and re-query the database
    -- with the provided permission conditions. How else would we be able
    -- to differentiate a non-existent comment and a comment the user
    -- doesn't have permission to view?
    Just _ -> fmap
        (maybe
            (Left CommentPermissionDenied)
            (Right . entityVal) . listToMaybe) $
        select $
        from $ \c -> do
        where_ $
            c ^. CommentId ==. val comment_id &&.
            has_permission c
        return c

-- | Count the visible comments in a given discussion.
--
-- Visibility depends on who the user is.
fetchCommentDB comment_id has_permission = get comment_id >>= \case
    Nothing -> do
        liftIO $
            appendFile "log" $ "comment not found: " ++ show comment_id ++ "\n"
        return (Left CommentNotFound)
    -- Hooray, the comment exists, now toss it and re-query the database
    -- with the provided permission conditions. How else would we be able
    -- to differentiate a non-existent comment and a comment the user
    -- doesn't have permission to view?
    Just _ -> fmap
        (maybe
            (Left CommentPermissionDenied)
            (Right . entityVal) . listToMaybe) $
        select $
        from $ \c -> do
        where_ $
            c ^. CommentId ==. val comment_id &&.
            has_permission c
        return c

-- | Count the visible comments in a given discussion.
--
-- Visibility depends on who the user is.