1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34 package info.magnolia.module.forum.admin;
35
36 import info.magnolia.cms.core.Content;
37 import info.magnolia.cms.gui.control.Hidden;
38 import info.magnolia.cms.gui.control.Tree;
39 import info.magnolia.cms.security.User;
40 import info.magnolia.context.MgnlContext;
41 import info.magnolia.freemarker.FreemarkerUtil;
42 import info.magnolia.module.forum.DefaultForumManager;
43
44 import java.util.Collection;
45
46 import javax.jcr.RepositoryException;
47
48 import org.slf4j.Logger;
49 import org.slf4j.LoggerFactory;
50
51
52
53
54
55
56
57 public class ForumTree extends Tree {
58
59 private static final Logger log = LoggerFactory.getLogger(ForumTree.class);
60
61 public ForumTree(String name, String repository) {
62 super(name, repository);
63 }
64
65 @Override
66 public String getHtmlFooter() {
67 final String str = super.getHtmlFooter();
68 return str + FreemarkerUtil.process(this, "Footer", "html");
69 }
70
71 @Override
72 protected void onGetHtmlOfSingleItem(StringBuffer html, Content parentNode, String itemType, Object item, String idPre) {
73
74 if (item instanceof Content) {
75 final Content node = (Content) item;
76 final String canModerateStr = canModerate(node);
77
78 html.append(new Hidden(idPre + "_PermissionModerate", canModerateStr).getHtml());
79 }
80 }
81
82 public String getRootModerationAllowed() throws RepositoryException {
83 final Content root = getHierarchyManager().getContent(this.getPath());
84 return canModerate(root);
85 }
86
87
88 protected String canModerate(Content node) {
89
90
91
92
93 User currentUser = MgnlContext.getUser();
94 Collection<String> allRoles = currentUser.getAllRoles();
95 if(allRoles.contains(DefaultForumManager.ROLE_FORUM_ALL_MODERATOR) || allRoles.contains(DefaultForumManager.ROLE_FORUM_ALL_ADMIN)){
96 return Boolean.toString(Boolean.TRUE);
97 }else{
98 return Boolean.toString(Boolean.FALSE);
99 }
100
101 }
102 }