Skip to content

Commit

Permalink
warnings: показ топика / комментария
Browse files Browse the repository at this point in the history
  • Loading branch information
maxcom committed Oct 31, 2024
1 parent 90b191c commit 7bd51a1
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@ class CommentPrepareService(textService: MessageTextService, msgbaseDao: Msgbase

def prepareCommentOnly(comment: Comment, currentUser: Option[CurrentUser], profile: Profile,
topic: Topic, ignoreList: Set[Int]): PreparedComment = {
assert(comment.topicId == topic.id)

val messageText = msgbaseDao.getMessageText(comment.id)
val author = userService.getUserCached(comment.userid)
val group = groupDao.getGroup(topic.groupId)
Expand Down
31 changes: 24 additions & 7 deletions src/main/scala/ru/org/linux/warning/WarningController.scala
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ import org.springframework.validation.Errors
import org.springframework.web.bind.WebDataBinder
import org.springframework.web.bind.annotation.{InitBinder, ModelAttribute, RequestMapping, RequestMethod}
import org.springframework.web.servlet.ModelAndView
import ru.org.linux.auth.{AccessViolationException, AuthUtil}
import ru.org.linux.comment.{Comment, CommentReadService}
import ru.org.linux.auth.{AccessViolationException, AuthUtil, CurrentUser}
import ru.org.linux.comment.{Comment, CommentPrepareService, CommentReadService}
import ru.org.linux.group.GroupDao
import ru.org.linux.site.MessageNotFoundException
import ru.org.linux.topic.{Topic, TopicDao, TopicLinkBuilder, TopicPermissionService}
import ru.org.linux.site.{MessageNotFoundException, Template}
import ru.org.linux.topic.{Topic, TopicDao, TopicLinkBuilder, TopicPermissionService, TopicPrepareService}
import ru.org.linux.user.UserService

import java.beans.PropertyEditorSupport
Expand All @@ -35,7 +35,8 @@ class PostWarningRequest(@BeanProperty var topic: Topic, @BeanProperty var comme

@Controller
class WarningController(warningService: WarningService, topicDao: TopicDao, commentReadService: CommentReadService,
topicPermissionService: TopicPermissionService, groupDao: GroupDao, userService: UserService) {
topicPermissionService: TopicPermissionService, groupDao: GroupDao, userService: UserService,
topicPrepareService: TopicPrepareService, commentPrepareService: CommentPrepareService) {
@RequestMapping(value = Array("/post-warning"), method = Array(RequestMethod.GET))
def showForm(@ModelAttribute(value = "request") request: PostWarningRequest): ModelAndView = AuthUtil.AuthorizedOnly { currentUser =>
val group = groupDao.getGroup(request.topic.groupId)
Expand All @@ -52,13 +53,28 @@ class WarningController(warningService: WarningService, topicDao: TopicDao, comm
}

// TODO rate limit warning
// TODO show topic / comment

val mv = new ModelAndView("post-warning")

prepareView(request, currentUser, mv)

mv
}

private def prepareView(request: PostWarningRequest, currentUser: CurrentUser, mv: ModelAndView): Unit = {
if (request.comment == null) {
val preparedTopic = topicPrepareService.prepareTopic(request.getTopic, currentUser.user)
mv.addObject("preparedTopic", preparedTopic)
} else {
val tmpl = Template.getTemplate

val preparedComment = commentPrepareService.prepareCommentOnly(request.comment, Some(currentUser), tmpl.getProf,
request.topic, Set.empty)

mv.addObject("preparedComment", preparedComment)
}
}

@RequestMapping(value = Array("/post-warning"), method = Array(RequestMethod.POST))
def post(@ModelAttribute(value = "request") request: PostWarningRequest,
errors: Errors): ModelAndView = AuthUtil.AuthorizedOnly { currentUser =>
Expand Down Expand Up @@ -88,12 +104,13 @@ class WarningController(warningService: WarningService, topicDao: TopicDao, comm
}

// TODO rate limit warning
// TODO show topic / comment
// TODO check text length

if (errors.hasErrors) {
val mv = new ModelAndView("post-warning")

prepareView(request, currentUser, mv)

mv
} else {
warningService.postWarning(request.topic, Option(request.comment), currentUser.user, request.text)
Expand Down
13 changes: 13 additions & 0 deletions src/main/webapp/WEB-INF/jsp/post-warning.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,17 @@
</div>
</div>
</form:form>

<c:if test="${preparedTopic != null}">
<div class=messages>
<lor:topic messageMenu="<%= null %>" preparedMessage="${preparedTopic}" message="${request.topic}" showMenu="false"/>
</div>
</c:if>

<c:if test="${preparedComment != null}">
<div class=messages>
<lor:comment commentsAllowed="false" showMenu="false" comment="${preparedComment}" topic="${request.topic}"/>
</div>
</c:if>

<jsp:include page="/WEB-INF/jsp/footer.jsp"/>

0 comments on commit 7bd51a1

Please sign in to comment.