Mercurial Hosting > nabble
comparison src/nabble/view/web/catalog/SetPin.java @ 0:7ecd1a4ef557
add content
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Thu, 21 Mar 2019 19:15:52 -0600 |
parents | |
children | 18cf4872fd7f |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:7ecd1a4ef557 |
---|---|
1 package nabble.view.web.catalog; | |
2 | |
3 import fschmidt.util.servlet.AuthorizingServlet; | |
4 import nabble.model.ModelHome; | |
5 import nabble.model.Node; | |
6 import nabble.model.Person; | |
7 import nabble.view.lib.Jtp; | |
8 | |
9 import javax.servlet.ServletException; | |
10 import javax.servlet.http.HttpServlet; | |
11 import javax.servlet.http.HttpServletRequest; | |
12 import javax.servlet.http.HttpServletResponse; | |
13 import java.io.IOException; | |
14 | |
15 | |
16 public class SetPin extends HttpServlet implements AuthorizingServlet { | |
17 | |
18 public String getAuthorizationKey(HttpServletRequest request) throws ServletException { | |
19 return Jtp.getReadAuthorizationKey( Jtp.getSiteNotNull(request).getNode(Jtp.getLong(request,"node")) ); | |
20 } | |
21 | |
22 public boolean authorize(String key,HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException { | |
23 return Jtp.authorizeForRead(key,request,response); | |
24 } | |
25 | |
26 protected void service(HttpServletRequest request, HttpServletResponse response) | |
27 throws ServletException, IOException | |
28 { | |
29 Person visitor = Jtp.getVisitor(request, response); | |
30 | |
31 Node node = Jtp.getSiteNotNull(request).getNode(Jtp.getLong(request, "node")); | |
32 if (!Jtp.canBeRemovedBy(node,visitor)) { | |
33 Jtp.login("Only administrators can proceed in this area.", request, response); | |
34 return; | |
35 } else if (node.getParent() == null) { | |
36 // Parent was removed (e.g., user clicked on the back button and | |
37 // tried to pin/unpin a node on a dead parent) | |
38 response.sendError(HttpServletResponse.SC_GONE, "The parent of this node has been deleted. You cannot pin/unpin a node under a dead parent."); | |
39 return; | |
40 } | |
41 String value = request.getParameter("value"); | |
42 boolean pin = "pin".equals(value); | |
43 if (pin) | |
44 Jtp.addPinnedChild(node.getParent(), node); | |
45 else { | |
46 Jtp.unpinChild(node.getParent(), node); | |
47 } | |
48 | |
49 boolean isScript = "y".equals(request.getParameter("script")); | |
50 if (isScript) { | |
51 response.setHeader("Content-Type","application/x-javascript"); | |
52 } else { | |
53 String what = node.getKind() == Node.Kind.APP? "forums" : "threads"; | |
54 Jtp.sendRedirect(request,response,"/catalog/ChangePinOrder.jtp?forum=" + node.getParent().getId() + "&what=" + what); | |
55 } | |
56 } | |
57 } | |
58 |