/src/main/java/net/jforum/actions/helpers/PermissionOptions.java

https://github.com/toby78/jforum3-maven · Java · 397 lines · 236 code · 69 blank · 92 comment · 5 complexity · 538319cb5b13b1b534b36fcb4df0c8a9 MD5 · raw file

  1. /*
  2. * Copyright (c) JForum Team. All rights reserved.
  3. *
  4. * The software in this package is published under the terms of the LGPL
  5. * license a copy of which has been included with this distribution in the
  6. * license.txt file.
  7. *
  8. * The JForum Project
  9. * http://www.jforum.net
  10. */
  11. package net.jforum.actions.helpers;
  12. import java.util.ArrayList;
  13. import java.util.List;
  14. /**
  15. * Use in the group permissions page
  16. * @author Rafael Steil
  17. */
  18. public class PermissionOptions {
  19. private List<Integer> categories = new ArrayList<Integer>();
  20. private List<Integer> forums = new ArrayList<Integer>();
  21. private List<Integer> replyOnly = new ArrayList<Integer>();
  22. private List<Integer> readOnly = new ArrayList<Integer>();
  23. private List<Integer> moderatedReplies = new ArrayList<Integer>();
  24. private List<Integer> html = new ArrayList<Integer>();
  25. private List<Integer> attachments = new ArrayList<Integer>();
  26. private List<Integer> moderateForums = new ArrayList<Integer>();
  27. private List<Integer> attachmentsDownload = new ArrayList<Integer>();
  28. private List<Integer> groups = new ArrayList<Integer>();
  29. private boolean canRemovePosts;
  30. private boolean canEditPosts;
  31. private boolean canMoveTopics;
  32. private boolean canLockUnlock;
  33. private boolean moderator;
  34. private boolean canApproveMessages;
  35. private boolean administrator;
  36. private boolean stickyAnnouncement;
  37. private boolean poll;
  38. private boolean pollVote;
  39. private boolean canInteractOtherGroups;
  40. private boolean canManageForums;
  41. private boolean isCoAdministrator;
  42. private boolean privateMessageAllowed;
  43. private boolean userListingAllowed;
  44. private boolean canViewProfile;
  45. private boolean canHaveProfilePicture;
  46. private boolean postOnlyWithModeratorOnline;
  47. private boolean pmOnlyToModerators;
  48. private boolean canViewActivityLog;
  49. private boolean canViewFullActivityLog;
  50. public boolean getPostOnlyWithModeratorOnline() {
  51. return this.postOnlyWithModeratorOnline;
  52. }
  53. public void setPostOnlyWithModeratorOnline(boolean postOnlyWithModeratorOnline) {
  54. this.postOnlyWithModeratorOnline = postOnlyWithModeratorOnline;
  55. }
  56. public boolean isPrivateMessageAllowed() {
  57. return this.privateMessageAllowed;
  58. }
  59. public void setPrivateMessageAllowed(boolean privateMessage) {
  60. this.privateMessageAllowed = privateMessage;
  61. }
  62. public boolean isUserListingAllowed() {
  63. return this.userListingAllowed;
  64. }
  65. public void setUserListingAllowed(boolean userListing) {
  66. this.userListingAllowed = userListing;
  67. }
  68. public boolean getCanViewProfile() {
  69. return this.canViewProfile;
  70. }
  71. public void setCanViewProfile(boolean viewProfile) {
  72. this.canViewProfile = viewProfile;
  73. }
  74. public boolean getCanHaveProfilePicture() {
  75. return this.canHaveProfilePicture;
  76. }
  77. public void setCanHaveProfilePicture(boolean profilePicture) {
  78. this.canHaveProfilePicture = profilePicture;
  79. }
  80. /**
  81. * Return true if can interact with users from other groups
  82. * @return
  83. */
  84. public boolean getCanInteractOtherGroups() {
  85. return this.canInteractOtherGroups;
  86. }
  87. public void setCanInteractOtherGroups(boolean canInteractOtherGroups) {
  88. this.canInteractOtherGroups = canInteractOtherGroups;
  89. }
  90. /**
  91. * Forums where only replies are allowed
  92. * @return
  93. */
  94. public List<Integer> getReplyOnly() {
  95. return this.replyOnly;
  96. }
  97. /**
  98. * Read-only forums
  99. * @return
  100. */
  101. public List<Integer> getReadOnlyForums() {
  102. return this.readOnly;
  103. }
  104. public List<Integer> getAllowedGroups() {
  105. return this.groups;
  106. }
  107. /**
  108. * Forums where attachments are allowed
  109. * @return
  110. */
  111. public List<Integer> getAttachments() {
  112. return this.attachments;
  113. }
  114. /**
  115. * Forums where HTML is allowed
  116. * @return
  117. */
  118. public List<Integer> getHtml() {
  119. return this.html;
  120. }
  121. /**
  122. * Forums the group can moderate
  123. * @return
  124. */
  125. public List<Integer> getModerateForums() {
  126. return this.moderateForums;
  127. }
  128. /**
  129. * Forums where replies should also be moderated
  130. * @return
  131. */
  132. public List<Integer> getModeratedReplies() {
  133. return this.moderatedReplies;
  134. }
  135. /**
  136. * Allowed categories
  137. * @return
  138. */
  139. public List<Integer> getAllowedCategories() {
  140. return this.categories;
  141. }
  142. /**
  143. * Allowed forums
  144. * @return
  145. */
  146. public List<Integer> getAllowedForums() {
  147. return this.forums;
  148. }
  149. /**
  150. * @return true if post editing is allowed
  151. */
  152. public boolean getCanEditPosts() {
  153. return canEditPosts;
  154. }
  155. /**
  156. * @return true if post removal is allowed
  157. */
  158. public boolean getCanRemovePosts() {
  159. return canRemovePosts;
  160. }
  161. /**
  162. * @return true if topic moving is allowed
  163. */
  164. public boolean getCanMoveTopics() {
  165. return canMoveTopics;
  166. }
  167. /**
  168. * @return true if topic locking and unlocking is allowed
  169. */
  170. public boolean getCanLockUnlock() {
  171. return canLockUnlock;
  172. }
  173. /**
  174. * @return true if download of existing attachments is allowed
  175. */
  176. public List<Integer> getDownloadAttachments() {
  177. return attachmentsDownload;
  178. }
  179. /**
  180. * @return true if it is a moderator
  181. */
  182. public boolean isModerator() {
  183. return moderator;
  184. }
  185. /**
  186. * @return true if approving moderated messages is allowed
  187. */
  188. public boolean getCanApproveMessages() {
  189. return canApproveMessages;
  190. }
  191. /**
  192. * @return true if it is an administrator
  193. */
  194. public boolean isAdministrator() {
  195. return administrator;
  196. }
  197. /**
  198. * @return true if can create sticky or announcement topics
  199. */
  200. public boolean getCanCreateStickyAnnouncement() {
  201. return stickyAnnouncement;
  202. }
  203. /**
  204. * @return true if can create polls
  205. */
  206. public boolean getCanCreatePoll() {
  207. return poll;
  208. }
  209. /**
  210. * @return true if can vote on existing polls
  211. */
  212. public boolean getAllowPollVote() {
  213. return pollVote;
  214. }
  215. public void setReplyOnly(int... replyOnly) {
  216. this.replyOnly = this.safeList(replyOnly);
  217. }
  218. public void setReadOnly(int... readOnly) {
  219. this.readOnly = this.safeList(readOnly);
  220. }
  221. public void setModeratedReplies(int... moderatedReplies) {
  222. this.moderatedReplies = this.safeList(moderatedReplies);
  223. }
  224. public void setGroups(int... groups) {
  225. this.groups = this.safeList(groups);
  226. }
  227. public void setHtml(int... html) {
  228. this.html = this.safeList(html);
  229. }
  230. public void setAttachments(int... attachments) {
  231. this.attachments = this.safeList(attachments);
  232. }
  233. public void setModerateForums(int... moderateForums) {
  234. this.moderateForums = this.safeList(moderateForums);
  235. }
  236. public void setCanRemovePosts(boolean canRemovePosts) {
  237. this.canRemovePosts = canRemovePosts;
  238. }
  239. public void setCanEditPosts(boolean canEditPosts) {
  240. this.canEditPosts = canEditPosts;
  241. }
  242. public void setCanMoveTopics(boolean canMoveTopics) {
  243. this.canMoveTopics = canMoveTopics;
  244. }
  245. public void setCanLockUnlock(boolean canLockUnlock) {
  246. this.canLockUnlock = canLockUnlock;
  247. }
  248. public void setAttachmentsDownload(int... attachmentsDownload) {
  249. this.attachmentsDownload = this.safeList(attachmentsDownload);
  250. }
  251. public void setModerator(boolean moderator) {
  252. this.moderator = moderator;
  253. }
  254. public void setCanApproveMessages(boolean canApproveMessages) {
  255. this.canApproveMessages = canApproveMessages;
  256. }
  257. public void setAdministrator(boolean administrator) {
  258. this.administrator = administrator;
  259. }
  260. public void setStickyAnnouncement(boolean stickyAnnouncement) {
  261. this.stickyAnnouncement = stickyAnnouncement;
  262. }
  263. public void setPoll(boolean poll) {
  264. this.poll = poll;
  265. }
  266. public void setPollVote(boolean pollVote) {
  267. this.pollVote = pollVote;
  268. }
  269. public void setCategories(int... categories) {
  270. this.categories = this.safeList(categories);
  271. }
  272. public void setForums(int... forums) {
  273. this.forums = this.safeList(forums);
  274. }
  275. private List<Integer> safeList(int... data) {
  276. if (data == null) {
  277. return new ArrayList<Integer>();
  278. }
  279. // Arrays.asList() does not work right with int[] (only with Integer[])
  280. List<Integer> l = new ArrayList<Integer>();
  281. for (int value : data) {
  282. l.add(value);
  283. }
  284. return l;
  285. }
  286. /**
  287. * Just check for the reference or instanceof.
  288. * This is a wrong implementation of equals(), and it only
  289. * exists because it's needed in the test cases
  290. */
  291. @Override
  292. public boolean equals(Object o) {
  293. return o == this || o instanceof PermissionOptions;
  294. }
  295. /**
  296. * @param roleExists
  297. */
  298. public void setCanManageForums(boolean value) {
  299. this.canManageForums = value;
  300. }
  301. public boolean getCanManageForums() {
  302. return this.canManageForums;
  303. }
  304. public void setCoAdministrator(boolean value) {
  305. this.isCoAdministrator = value;
  306. }
  307. public boolean isCoAdministrator() {
  308. return this.isCoAdministrator;
  309. }
  310. public void setPmOnlyToModerators(boolean pmOnlyToModerators) {
  311. this.pmOnlyToModerators = pmOnlyToModerators;
  312. }
  313. public boolean isPmOnlyToModerators() {
  314. return pmOnlyToModerators;
  315. }
  316. public void setCanViewActivityLog(boolean canViewActivityLog) {
  317. this.canViewActivityLog = canViewActivityLog;
  318. }
  319. public boolean getCanViewActivityLog() {
  320. return canViewActivityLog;
  321. }
  322. public void setCanViewFullActivityLog(boolean canViewFullActivityLog) {
  323. this.canViewFullActivityLog = canViewFullActivityLog;
  324. }
  325. public boolean getCanViewFullActivityLog() {
  326. return canViewFullActivityLog;
  327. }
  328. }