Skip to content

Commit

Permalink
Помечание тем как решенные
Browse files Browse the repository at this point in the history
  • Loading branch information
qnikst authored and maxcom committed Dec 28, 2009
1 parent c5cda74 commit f792c00
Show file tree
Hide file tree
Showing 14 changed files with 295 additions and 194 deletions.
Binary file added html/img/solved.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 10 additions & 2 deletions src/ru/org/linux/site/Group.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ public class Group {
private String info;
private String longInfo;

private boolean resolvable;

public Group(Connection db, int id) throws SQLException, BadGroupException {
this.id = id;

Expand All @@ -51,7 +53,7 @@ public Group(Connection db, int id) throws SQLException, BadGroupException {
try {
st = db.createStatement();

rs = st.executeQuery("SELECT sections.moderate, sections.preformat, imagepost, vote, section, havelink, linktext, sections.name as sname, title, image, restrict_topics, restrict_comments,stat1,stat2,stat3,groups.id, groups.info, groups.longinfo FROM groups, sections WHERE groups.id=" + id + " AND groups.section=sections.id");
rs = st.executeQuery("SELECT sections.moderate, sections.preformat, imagepost, vote, section, havelink, linktext, sections.name as sname, title, image, restrict_topics, restrict_comments,stat1,stat2,stat3,groups.id, groups.info, groups.longinfo, groups.resolvable FROM groups, sections WHERE groups.id=" + id + " AND groups.section=sections.id");

if (!rs.next()) {
throw new BadGroupException("Группа " + id + " не существует");
Expand All @@ -75,7 +77,7 @@ private Group(ResultSet rs) throws SQLException {
public static List<Group> getGroups(Connection db, Section section) throws SQLException {
Statement st = db.createStatement();

ResultSet rs = st.executeQuery("SELECT sections.moderate, sections.preformat, imagepost, vote, section, havelink, linktext, sections.name as sname, title, image, restrict_topics, restrict_comments, stat1,stat2,stat3,groups.id,groups.info,groups.longinfo FROM groups, sections WHERE sections.id=" + section.getId() + " AND groups.section=sections.id ORDER BY id");
ResultSet rs = st.executeQuery("SELECT sections.moderate, sections.preformat, imagepost, vote, section, havelink, linktext, sections.name as sname, title, image, restrict_topics, restrict_comments, stat1,stat2,stat3,groups.id,groups.info,groups.longinfo,groups.resolvable FROM groups, sections WHERE sections.id=" + section.getId() + " AND groups.section=sections.id ORDER BY id");

List<Group> list = new ArrayList<Group>();

Expand Down Expand Up @@ -109,6 +111,7 @@ private void init(ResultSet rs) throws SQLException {

info = rs.getString("info");
longInfo = rs.getString("longinfo");
resolvable = rs.getBoolean("resolvable");
}

public boolean isImagePostAllowed() {
Expand Down Expand Up @@ -261,5 +264,10 @@ public void setInfo(String info) {
public void setLongInfo(String longInfo) {
this.longInfo = longInfo;
}

public boolean isResolvable() {
return this.resolvable;
}

}

27 changes: 25 additions & 2 deletions src/ru/org/linux/site/Message.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ public class Message implements Serializable {
private final String userAgent;
private final String postIP;
private final boolean lorcode;
private final boolean resolved;

private final Section section;

Expand All @@ -71,7 +72,8 @@ public Message(Connection db, int msgid) throws SQLException, MessageNotFoundExc
"topics.groupid as guid, topics.url, topics.linktext, user_agents.name as useragent, " +
"groups.title as gtitle, vote, havelink, section, topics.sticky, topics.postip, " +
"postdate<(CURRENT_TIMESTAMP-sections.expire) as expired, deleted, lastmod, commitby, " +
"commitdate, topics.stat1, postscore, topics.moderate, message, notop,bbcode " +
"commitdate, topics.stat1, postscore, topics.moderate, message, notop,bbcode, " +
"topics.resolved " +
"FROM topics " +
"INNER JOIN users ON (users.id=topics.userid) " +
"INNER JOIN groups ON (groups.id=topics.groupid) " +
Expand Down Expand Up @@ -110,6 +112,7 @@ public Message(Connection db, int msgid) throws SQLException, MessageNotFoundExc
userAgent = rs.getString("useragent");
postIP = rs.getString("postip");
lorcode = rs.getBoolean("bbcode");
resolved = rs.getBoolean("resolved");

rs.close();
st.close();
Expand Down Expand Up @@ -148,6 +151,7 @@ public Message(Connection db, ResultSet rs) throws SQLException {
userAgent = rs.getString("useragent");
postIP = rs.getString("postip");
lorcode = rs.getBoolean("bbcode");
resolved = rs.getBoolean("resolved");

try {
section = new Section(db, sectionid);
Expand Down Expand Up @@ -201,6 +205,7 @@ public Message(Connection db, AddMessageForm form, User user)
notop = false;
userid = user.getId();
lorcode = true;
resolved=false;

message = form.processMessage(group);

Expand Down Expand Up @@ -254,6 +259,12 @@ public Message(Connection db, Message original, ServletRequest request) throws B
title = original.title;
}

if (request.getParameter("resolve")!=null){
resolved = "yes".equals(request.getParameter("resolve"))?true:false;
}else{
resolved = original.resolved;
}

havelink = original.havelink;

sectionid = group.getSectionId();
Expand Down Expand Up @@ -634,7 +645,7 @@ public boolean isEditable(Connection db, User by) throws SQLException, UserNotFo
if (by.canCorrect() && sectionid==1) {
return true;
}

if (by.getId()==userid && !moderate && lorcode && !by.isAnonymousScore()) {
return (new Date().getTime() - postdate.getTime()) < 30*60*1000;
}
Expand Down Expand Up @@ -746,4 +757,16 @@ public List<EditInfoDTO> loadEditInfo(Connection db) throws SQLException {

return list;
}

public boolean isResolved(){
return this.resolved;
}

public void resolveMessage(Connection db, boolean b) throws SQLException {
PreparedStatement pstMsgbase = db.prepareStatement("UPDATE topics SET resolved=? WHERE id=?");
pstMsgbase.setBoolean(1, b);
pstMsgbase.setInt(2, this.msgid);
pstMsgbase.executeUpdate();
}

}
3 changes: 2 additions & 1 deletion src/ru/org/linux/site/NewsViewer.java
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,8 @@ public List<Message> getMessages(Connection db) throws SQLException, UserErrorE
"topics.groupid as guid, topics.url, topics.linktext, user_agents.name as useragent, " +
"groups.title as gtitle, vote, havelink, section, topics.sticky, topics.postip, " +
"postdate<(CURRENT_TIMESTAMP-sections.expire) as expired, deleted, lastmod, commitby, " +
"commitdate, topics.stat1, postscore, topics.moderate, message, notop,bbcode " +
"commitdate, topics.stat1, postscore, topics.moderate, message, notop,bbcode, " +
"topics.resolved " +
"FROM topics " +
"INNER JOIN groups ON (groups.id=topics.groupid) " +
"INNER JOIN sections ON (sections.id=groups.section) " +
Expand Down
8 changes: 4 additions & 4 deletions src/ru/org/linux/spring/GroupController.java
Original file line number Diff line number Diff line change
Expand Up @@ -116,15 +116,15 @@ public ModelAndView topics(int groupId, Integer offsetObject, HttpServletRequest

if (!lastmod) {
if (firstPage) {
rs = st.executeQuery("SELECT topics.title as subj, sections.name, lastmod, userid, topics.id as msgid, deleted, topics.stat1, topics.stat3, topics.stat4, topics.sticky FROM topics,groups, sections WHERE sections.id=groups.section AND (topics.moderate OR NOT sections.moderate) AND topics.groupid=groups.id AND groups.id=" + groupId + delq + ignq + " AND (postdate>(CURRENT_TIMESTAMP-'3 month'::interval) or sticky) ORDER BY sticky desc,msgid DESC LIMIT " + topics);
rs = st.executeQuery("SELECT topics.title as subj, sections.name, lastmod, userid, topics.id as msgid, deleted, topics.stat1, topics.stat3, topics.stat4, topics.sticky, topics.resolved FROM topics,groups, sections WHERE sections.id=groups.section AND (topics.moderate OR NOT sections.moderate) AND topics.groupid=groups.id AND groups.id=" + groupId + delq + ignq + " AND (postdate>(CURRENT_TIMESTAMP-'3 month'::interval) or sticky) ORDER BY sticky desc,msgid DESC LIMIT " + topics);
} else {
rs = st.executeQuery("SELECT topics.title as subj, sections.name, lastmod, userid, topics.id as msgid, deleted, topics.stat1, topics.stat3, topics.stat4, topics.sticky FROM topics,groups, sections WHERE sections.id=groups.section AND (topics.moderate OR NOT sections.moderate) AND topics.groupid=groups.id AND groups.id=" + groupId + delq + " ORDER BY sticky,msgid ASC LIMIT " + topics + " OFFSET " + offset);
rs = st.executeQuery("SELECT topics.title as subj, sections.name, lastmod, userid, topics.id as msgid, deleted, topics.stat1, topics.stat3, topics.stat4, topics.sticky,topics.resolved FROM topics,groups, sections WHERE sections.id=groups.section AND (topics.moderate OR NOT sections.moderate) AND topics.groupid=groups.id AND groups.id=" + groupId + delq + " ORDER BY sticky,msgid ASC LIMIT " + topics + " OFFSET " + offset);
}
} else {
if (firstPage) {
rs = st.executeQuery("SELECT topics.title as subj, sections.name, lastmod, userid, topics.id as msgid, deleted, topics.stat1, topics.stat3, topics.stat4, topics.sticky FROM topics,groups, sections WHERE sections.id=groups.section AND (topics.moderate OR NOT sections.moderate) AND topics.groupid=groups.id AND groups.id=" + groupId + " AND NOT deleted " + ignq + " ORDER BY sticky DESC,lastmod DESC LIMIT " + topics + " OFFSET " + offset);
rs = st.executeQuery("SELECT topics.title as subj, sections.name, lastmod, userid, topics.id as msgid, deleted, topics.stat1, topics.stat3, topics.stat4, topics.sticky, topics.resolved FROM topics,groups, sections WHERE sections.id=groups.section AND (topics.moderate OR NOT sections.moderate) AND topics.groupid=groups.id AND groups.id=" + groupId + " AND NOT deleted " + ignq + " ORDER BY sticky DESC,lastmod DESC LIMIT " + topics + " OFFSET " + offset);
} else {
rs = st.executeQuery("SELECT topics.title as subj, sections.name, lastmod, userid, topics.id as msgid, deleted, topics.stat1, topics.stat3, topics.stat4, topics.sticky FROM topics,groups, sections WHERE sections.id=groups.section AND (topics.moderate OR NOT sections.moderate) AND topics.groupid=groups.id AND groups.id=" + groupId + " AND NOT deleted ORDER BY sticky DESC,lastmod DESC LIMIT " + topics + " OFFSET " + offset);
rs = st.executeQuery("SELECT topics.title as subj, sections.name, lastmod, userid, topics.id as msgid, deleted, topics.stat1, topics.stat3, topics.stat4, topics.sticky, topics.resolved FROM topics,groups, sections WHERE sections.id=groups.section AND (topics.moderate OR NOT sections.moderate) AND topics.groupid=groups.id AND groups.id=" + groupId + " AND NOT deleted ORDER BY sticky DESC,lastmod DESC LIMIT " + topics + " OFFSET " + offset);
}
}

Expand Down
6 changes: 4 additions & 2 deletions src/ru/org/linux/spring/GroupModificationController.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ public ModelAndView modifyGroup(
@RequestParam("info") String info,
@RequestParam("longinfo") String longInfo,
@RequestParam(value = "preview", required = false) String preview,
@RequestParam(value = "resolvable", required = false) String resolvable,
ServletRequest request
) throws Exception {
Template tmpl = Template.getTemplate(request);
Expand All @@ -91,11 +92,12 @@ public ModelAndView modifyGroup(
return new ModelAndView("groupmod", params);
}

PreparedStatement pst = db.prepareStatement("UPDATE groups SET info=?, longinfo=? WHERE id=?");
PreparedStatement pst = db.prepareStatement("UPDATE groups SET info=?, longinfo=?,resolvable=? WHERE id=?");

pst.setString(1, info);
pst.setString(2, longInfo);
pst.setInt(3, id);
pst.setBoolean(3, resolvable!=null);
pst.setInt(4, id);

pst.executeUpdate();

Expand Down
59 changes: 59 additions & 0 deletions src/ru/org/linux/spring/ResolveController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* Copyright 1998-2009 Linux.org.ru
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package ru.org.linux.spring;

import java.sql.Connection;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.context.request.WebRequest;
import org.springframework.web.servlet.ModelAndView;
import ru.org.linux.site.AccessViolationException;
import ru.org.linux.site.Group;
import ru.org.linux.site.LorDataSource;
import ru.org.linux.site.Message;
import ru.org.linux.site.Template;
import ru.org.linux.site.User;

@Controller
public class ResolveController {
@RequestMapping("/resolve.jsp")
public ModelAndView resolve(
WebRequest webRequest,
HttpServletRequest request,
HttpServletResponse response,
@RequestParam("msgid") int msgid,
@RequestParam("resolve") String resolved
) throws Exception {
Template tmpl = Template.getTemplate(request);
Connection db = LorDataSource.getConnection();
Message message = new Message(db,msgid);
Group group = new Group(db, message.getGroupId());
User currentUser = User.getCurrentUser(db, request.getSession());
if (!group.isResolvable()){
throw new AccessViolationException("В данной группе нельзя помечать темы как решенные");
}
if (!tmpl.isModeratorSession()&&currentUser.getId()==message.getUid()){
throw new AccessViolationException("У Вас нет прав на решение данной темы");
}
message.resolveMessage(db, (resolved!=null)&&"yes".equals(resolved));
return new ModelAndView("action-done", "message", "Состояние темы изменено");
}


}
3 changes: 2 additions & 1 deletion src/ru/org/linux/spring/ShowRepliesController.java
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,8 @@ public ModelAndView showReplies(
" comments.id AS cid, " +
" comments.postdate AS cDate, " +
" comments.userid AS cAuthor, " +
" msgbase.message AS cMessage, bbcode " +
" msgbase.message AS cMessage, bbcode, " +
" topics.resolved as resolved " +
" FROM sections INNER JOIN groups ON (sections.id = groups.section) " +
" INNER JOIN topics ON (groups.id=topics.groupid) " +
" INNER JOIN comments ON (comments.topic=topics.id) " +
Expand Down
11 changes: 11 additions & 0 deletions src/ru/org/linux/spring/TopicsListItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public class TopicsListItem implements Serializable {
private final boolean sticky;
private final int pages;
private final int author;
private final Boolean resolved;

private static final long serialVersionUID = 5344250574674257995L;

Expand All @@ -55,6 +56,8 @@ public TopicsListItem(ResultSet rs, int messagesInPage) throws SQLException {
stat4 = rs.getInt("stat4");
sticky = rs.getBoolean("sticky");
sectionTitle = rs.getString("name");
groupTitle = rs.getString("gtitle");
resolved = rs.getBoolean("resolved");

pages = Message.getPageCount(stat1, messagesInPage);
}
Expand Down Expand Up @@ -102,4 +105,12 @@ public int getPages() {
public String getSectionTitle() {
return sectionTitle;
}

public String getGroupTitle() {
return groupTitle;
}

public Boolean isResolved(){
return resolved;
}
}
3 changes: 3 additions & 0 deletions web/WEB-INF/jsp/group.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,9 @@
<c:if test="${topic.sticky and not topic.deleted}">
<img src="/img/paper_clip.gif" width="15" height="15" alt="Прикреплено" title="Прикреплено">
</c:if>
<c:if test="${topic.resolved}">
<img src="/img/solved.png" width="15" height="15" alt="Решено" title="Решено"/>
</c:if>

<c:if test="${firstPage and topic.pages<=1}">
<a href="view-message.jsp?msgid=${topic.msgid}&amp;lastmod=${topic.lastmod.time}" rev="contents">
Expand Down
1 change: 1 addition & 0 deletions web/WEB-INF/jsp/groupmod.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
<form action="groupmod.jsp" method="POST">
<input type="hidden" name="group" value="${group.id}">
Строка описания: <input type="text" name="info" size="70" value="${fn:escapeXml(group.info)}"><br>
Можно помечать темы как прочтенные: <input type="checkbox" name="resolvable" <c:if test="${group.resolvable}">checked="checked"</c:if>/><br />
Подробное описание:<br>
<textarea rows="20" cols="70" name="longinfo"><c:out value="${group.longInfo}" escapeXml="true"/></textarea><br>
<input type="submit" value="Изменить">
Expand Down
27 changes: 27 additions & 0 deletions web/WEB-INF/jsp/resolve.jsp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<%--
~ Copyright 1998-2009 Linux.org.ru
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>

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

<title>${message}</title>
<jsp:include page="/WEB-INF/jsp/header.jsp"/>

<p>${message}</p>

<p>${bigMessage}</p>

<jsp:include page="/WEB-INF/jsp/footer.jsp"/>
13 changes: 12 additions & 1 deletion web/WEB-INF/tags/message.tag
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,18 @@
out.append("[<a href=\"delete.jsp?msgid=");
out.print(msgid);
out.append("\">Удалить</a>]");
}
}
if ((tmpl.isModeratorSession() || author.getNick().equals(user)) &&
new Group(db, message.getGroupId()).isResolvable()){
out.append("[<a href=\"resolve.jsp?msgid=");
out.print(msgid);
if (message.isResolved()){
out.append("&amp;resolve=no\">Отметить как не решенную</a>]");
}else{
out.append("&amp;resolve=yes\">Отметить как решенную</a>]");
}
}
%>
</div>
</c:if>
Expand Down

0 comments on commit f792c00

Please sign in to comment.