Zugriff auf eine Forum-Instanz kann jetzt beschränkt werden.

git-svn-id: https://svn.libreccm.org/ccm/trunk@1128 8810af33-2d31-482b-a856-94f89814c4df
master
jensp 2011-10-02 09:15:41 +00:00
parent b6f6ad9127
commit 596707a5e5
3 changed files with 301 additions and 295 deletions

View File

@ -63,6 +63,7 @@ import com.arsdigita.web.Application;
*
* @author Kevin Scaldeferri (kevin@arsdigita.com)
* @author chrisg23
* @author Jens Pelzetter (jensp)
* @version $Revision: 1.7 $
* @version $Id: Forum.java 1628 2007-09-17 08:10:40Z chrisg23 $
*/
@ -70,15 +71,13 @@ public class Forum extends Application {
/** Private logger instance for debugging purpose */
private static final Logger s_log = Logger.getLogger(Forum.class);
public static final String BASE_DATA_OBJECT_TYPE =
"com.arsdigita.forum.Forum";
public static final String PACKAGE_TYPE = "forum";
public static final String THREAD_SUBSCRIPTION_GROUPS_NAME =
"Thread Subscription Groups";
private static final ForumConfig s_config = new ForumConfig();
static {
s_log.debug("Static initalizer starting...");
s_config.load();
@ -88,8 +87,6 @@ public class Forum extends Application {
public static ForumConfig getConfig() {
return s_config;
}
//////
//Forum specific privileges
/////
@ -111,7 +108,6 @@ public class Forum extends Application {
// groups of users for their internal use and to provide private forums
// for logged in users only (no public read access).
public static final String FORUM_READ_PRIVILEGE = "forum_read";
///////
// pdl forum attribute/association names
///////
@ -120,18 +116,17 @@ public class Forum extends Application {
private static final String MODERATION = "isModerated";
private static final String PUBLIC = "isPublic";
private static final String NOTICEBOARD = "isNoticeboard";
private static final String ADMIN_GROUP = "adminGroup";
private static final String MODERATION_GROUP = "moderationGroup";
private static final String THREAD_CREATE_GROUP = "threadCreateGroup";
private static final String THREAD_RESPONDER_GROUP = "threadRespondGroup";
private static final String READ_GROUP = "readGroup";
private static final String CATEGORY = "category";
private static final String EXPIRE_AFTER = "expireAfter";
private static final String LIFECYCLE_DEFINITION = "lifecycleDefinition";
// additional attributes added chris.gilbert@westsussex.gov.uk
private static final String ALLOW_FILE_ATTACHMENTS = "fileAttachmentsAllowed";
private static final String ALLOW_FILE_ATTACHMENTS =
"fileAttachmentsAllowed";
private static final String ALLOW_IMAGE_UPLOADS = "imageUploadsAllowed";
private static final String AUTOSUBSCRIBE_THREAD_STARTER =
"autoSubscribeThreadStarter";
@ -203,7 +198,8 @@ public class Forum extends Application {
Application parent, boolean moderated) {
s_log.debug("creating forum " + title);
Forum forum = (Forum) Application.createApplication(BASE_DATA_OBJECT_TYPE,
Forum forum = (Forum) Application.createApplication(
BASE_DATA_OBJECT_TYPE,
urlName,
title, parent, true);
@ -237,8 +233,7 @@ public class Forum extends Application {
if (category == null) {
return createRootCategory();
} else {
return (Category)DomainObjectFactory
.newInstance(category);
return (Category) DomainObjectFactory.newInstance(category);
}
}
@ -279,7 +274,7 @@ public class Forum extends Application {
Group moderators = new Group();
moderators.setName(getTitle() + " Moderators");
setAssociation( MODERATION_GROUP, moderators );
setAssociation(MODERATION_GROUP, moderators);
// This is bit of a hack. For moderator messages to be sent out properly,
// moderator group has to have proper primary email address. Which means
// it has to be unique among all primary email addresses. Failing to the
@ -288,8 +283,8 @@ public class Forum extends Application {
// NPE when trying to retrieve sender's email address, thus stopping any
// further message processing.
// Actually, the only hack involved is making the email address unique.
String email = "forum-moderator-" + getID() + "-" +
moderators.getID() + "@" + s_config.getReplyHostName();
String email = "forum-moderator-" + getID() + "-" + moderators.getID()
+ "@" + s_config.getReplyHostName();
moderators.setPrimaryEmail(new EmailAddress(email));
// chris.gilbert@westsussex.gov.uk create additional groups for privilege
@ -340,7 +335,6 @@ public class Forum extends Application {
}
}
private boolean m_wasNew;
@Override
@ -359,7 +353,7 @@ public class Forum extends Application {
PermissionService.setContext(getRootCategory(), this);
createGroups();
if (getAdminGroup() != null) {
PermissionService.grantPermission( new PermissionDescriptor(
PermissionService.grantPermission(new PermissionDescriptor(
PrivilegeDescriptor.ADMIN,
this,
getAdminGroup()));
@ -387,7 +381,7 @@ public class Forum extends Application {
//
}
if (getModerationGroup() != null ) {
if (getModerationGroup() != null) {
PermissionService.grantPermission(
new PermissionDescriptor(
PrivilegeDescriptor.get(
@ -426,9 +420,14 @@ public class Forum extends Application {
PrivilegeDescriptor.READ,
this,
getReadGroup()));
PermissionService.grantPermission(new PermissionDescriptor(
PrivilegeDescriptor.get(FORUM_READ_PRIVILEGE),
this,
getReadGroup()));
}
KernelExcursion excursion = new KernelExcursion() {
protected void excurse() {
setParty(Kernel.getSystemParty());
// FIXME
@ -457,7 +456,7 @@ public class Forum extends Application {
}
} finally {
if ( null != subs ) {
if (null != subs) {
subs.close();
}
}
@ -477,12 +476,12 @@ public class Forum extends Application {
return BASE_DATA_OBJECT_TYPE;
}
/**
* Gets all the Subscriptions associated with this Forum.
*/
public DataCollection getAllSubscriptions() {
DataAssociationCursor dac = ((DataAssociation) get(SUBSCRIPTIONS)).cursor();
DataAssociationCursor dac = ((DataAssociation) get(SUBSCRIPTIONS)).
cursor();
return dac;
}
@ -510,7 +509,7 @@ public class Forum extends Application {
* to use a custom DataQuery which does this.)
*/
public DataAssociation getPosts() {
return (DataAssociation)get(POSTS);
return (DataAssociation) get(POSTS);
}
/**
@ -549,7 +548,7 @@ public class Forum extends Application {
* top-level posts which are not replies to any other post.
*/
public ThreadCollection getThreads() {
return getThreads((BigDecimal)null);
return getThreads((BigDecimal) null);
}
/**
@ -561,23 +560,20 @@ public class Forum extends Application {
public ThreadCollection getThreads(Party party) {
ThreadCollection threads = getThreads();
if (isModerated() &&
!canModerate(party)) {
s_log.debug( "Only showing approved threads" );
if (isModerated() && !canModerate(party)) {
s_log.debug("Only showing approved threads");
threads.filterUnapproved(party);
}
return threads;
}
/**
* Gets a ThreadCollection of the threads in a specific Category.
*/
public ThreadCollection getThreads(BigDecimal categoryID) {
DataCollection threadsData
= SessionManager.getSession().retrieve(
DataCollection threadsData = SessionManager.getSession().retrieve(
MessageThread.BASE_DATA_OBJECT_TYPE);
@ -586,11 +582,13 @@ public class Forum extends Application {
if (categoryID != null) {
// XXX bad dep on ui package
if (categoryID.equals(com.arsdigita.forum.ui.Constants.TOPIC_NONE)) {
Filter f = threadsData.addNotInSubqueryFilter
("root.id", "com.arsdigita.forum.uncategoryObject");
Filter f =
threadsData.addNotInSubqueryFilter("root.id",
"com.arsdigita.forum.uncategoryObject");
} else {
Filter f = threadsData.addInSubqueryFilter
("root.id", "com.arsdigita.forum.categoryObject");
Filter f =
threadsData.addInSubqueryFilter("root.id",
"com.arsdigita.forum.categoryObject");
f.set("categoryID", categoryID);
}
}
@ -609,9 +607,8 @@ public class Forum extends Application {
Party party) {
ThreadCollection threads = getThreads(categoryID);
if (isModerated() &&
!canModerate(party)) {
s_log.debug( "Only showing approved threads" );
if (isModerated() && !canModerate(party)) {
s_log.debug("Only showing approved threads");
threads.filterUnapproved(party);
}
@ -631,6 +628,7 @@ public class Forum extends Application {
s_log.debug("Creating subscriptions!");
new KernelExcursion() {
protected void excurse() {
setParty(Kernel.getSystemParty());
@ -641,7 +639,7 @@ public class Forum extends Application {
new DailySubscription(Forum.this, party).save();
Group moderators = getModerationGroup();
if ( null != moderators ) {
if (null != moderators) {
s_log.debug("creatiing moderation subscription "
+ moderators.getName());
@ -660,8 +658,8 @@ public class Forum extends Application {
*/
public DataQuery getCategories() {
Session session = SessionManager.getSession();
DataQuery query = session.retrieveQuery
("com.arsdigita.forum.getCategorizationSummary");
DataQuery query = session.retrieveQuery(
"com.arsdigita.forum.getCategorizationSummary");
query.setParameter("forumID", getID());
return query;
}
@ -673,8 +671,8 @@ public class Forum extends Application {
*/
public DataQuery getEmptyCategories() {
Session session = SessionManager.getSession();
DataQuery query = session.retrieveQuery
("com.arsdigita.forum.getUnusedCategories");
DataQuery query = session.retrieveQuery(
"com.arsdigita.forum.getUnusedCategories");
query.setParameter("forumID", getID());
return query;
}
@ -686,8 +684,8 @@ public class Forum extends Application {
*/
public DataQuery getUnCategory() {
Session session = SessionManager.getSession();
DataQuery query = session.retrieveQuery
("com.arsdigita.forum.getUncategorizedSummary");
DataQuery query = session.retrieveQuery(
"com.arsdigita.forum.getUncategorizedSummary");
query.setParameter("forumID", getID());
return query;
}
@ -697,8 +695,9 @@ public class Forum extends Application {
DataAssociationCursor cursor =
root.getRelatedCategories(Category.CHILD);
Filter f = cursor.addInSubqueryFilter
("id", "com.arsdigita.forum.filledCategories");
Filter f =
cursor.addInSubqueryFilter("id",
"com.arsdigita.forum.filledCategories");
return cursor;
}
@ -721,8 +720,8 @@ public class Forum extends Application {
* checks if the user can edit posts in this forum
*/
public boolean canEdit(Party party) {
return (getConfig().canAdminEditPosts() &&
PermissionService.checkPermission(
return (getConfig().canAdminEditPosts() && PermissionService.
checkPermission(
new PermissionDescriptor(PrivilegeDescriptor.EDIT,
this,
party)));
@ -749,15 +748,13 @@ public class Forum extends Application {
* automatically marked as approved.
*/
public void setModerated(boolean moderate) {
Boolean old = (Boolean)get(MODERATION);
if (Boolean.TRUE.equals(old) &&
!moderate) {
Boolean old = (Boolean) get(MODERATION);
if (Boolean.TRUE.equals(old) && !moderate) {
DataAssociationCursor posts = getPosts().cursor();
posts.addEqualsFilter(Post.STATUS, Post.PENDING);
while (posts.next()) {
Post post
= (Post)DomainObjectFactory.newInstance(
Post post = (Post) DomainObjectFactory.newInstance(
posts.getDataObject());
post.setStatus(Post.APPROVED);
post.save();
@ -768,13 +765,13 @@ public class Forum extends Application {
}
public boolean isModerated() {
Boolean isModerated = (Boolean)get(MODERATION);
Boolean isModerated = (Boolean) get(MODERATION);
Assert.exists(isModerated);
return isModerated.booleanValue();
}
public boolean isPublic() {
Boolean isPublic = (Boolean)get(PUBLIC);
Boolean isPublic = (Boolean) get(PUBLIC);
Assert.exists(isPublic);
return isPublic.booleanValue();
}
@ -804,9 +801,9 @@ public class Forum extends Application {
/** Returns the moderator group. Null if it doesn't exist */
public Group getModerationGroup() {
DataObject dObj = (DataObject) get( MODERATION_GROUP );
DataObject dObj = (DataObject) get(MODERATION_GROUP);
Assert.exists(dObj, DataObject.class);
return (Group)DomainObjectFactory.newInstance(dObj);
return (Group) DomainObjectFactory.newInstance(dObj);
}
/** Returns the thread create group. Null if it doesn't exist */
@ -853,10 +850,11 @@ public class Forum extends Application {
// have the same expiration policy.
DataAssociationCursor posts = getPosts().cursor();
while (posts.next()) {
Post post = (Post) DomainObjectFactory.newInstance(posts.getDataObject());
if (post.getThread().getRootMessage().getID()
.equals(post.getID())) {
s_log.debug("Resetting expiration lifecycle for " + post.getOID());
Post post = (Post) DomainObjectFactory.newInstance(posts.
getDataObject());
if (post.getThread().getRootMessage().getID().equals(post.getID())) {
s_log.debug("Resetting expiration lifecycle for "
+ post.getOID());
post.setLifecycle(newLife);
}
}
@ -944,6 +942,7 @@ public class Forum extends Application {
public boolean allowFileAttachments() {
return ((Boolean) get(ALLOW_FILE_ATTACHMENTS)).booleanValue();
}
public boolean allowImageUploads() {
return ((Boolean) get(ALLOW_IMAGE_UPLOADS)).booleanValue();
}
@ -955,6 +954,7 @@ public class Forum extends Application {
public boolean noCategoryPostsAllowed() {
return ((Boolean) get(NO_CATEGORY_POSTS)).booleanValue();
}
public boolean anonymousPostsAllowed() {
return ((Boolean) get(ANONYMOUS_POSTS)).booleanValue();
}
@ -962,9 +962,11 @@ public class Forum extends Application {
public void setAllowFileAttachments(boolean allow) {
set(ALLOW_FILE_ATTACHMENTS, new Boolean(allow));
}
public void setAllowImageUploads(boolean allow) {
set(ALLOW_IMAGE_UPLOADS, new Boolean(allow));
}
public void setAutoSubscribeThreadCreator(boolean subscribe) {
set(AUTOSUBSCRIBE_THREAD_STARTER, new Boolean(subscribe));
}
@ -977,7 +979,7 @@ public class Forum extends Application {
set(ANONYMOUS_POSTS, new Boolean(allow));
}
public void setTitle (String title) {
public void setTitle(String title) {
String oldTitle = getTitle();
super.setTitle(title);
if (!oldTitle.equals(title)) {
@ -990,8 +992,8 @@ public class Forum extends Application {
DataCollection subscriptions = getSubscriptions();
while (subscriptions.next()) {
ForumSubscription
subscription = (ForumSubscription)DomainObjectFactory.
ForumSubscription subscription =
(ForumSubscription) DomainObjectFactory.
newInstance(subscriptions.getDataObject());
subscription.getGroup().setName(subscription.getGroupName(this));
}
@ -1001,7 +1003,8 @@ public class Forum extends Application {
ThreadSubscription threadSub = ThreadSubscription.
getThreadSubscription(
threads.getMessageThread());
threadSub.getGroup().setName(threadSub.getSubscriptionGroupName(this));
threadSub.getGroup().setName(threadSub.getSubscriptionGroupName(
this));
}
@ -1016,7 +1019,6 @@ public class Forum extends Application {
// public String getContextPath() {
// return "/ccm-forum";
// }
/**
* Returns the path name of the location of the applications servlet/JSP.
*

View File

@ -18,7 +18,6 @@
*/
package com.arsdigita.forum;
import com.arsdigita.forum.portlet.MyForumsPortlet;
import com.arsdigita.forum.portlet.RecentPostingsPortlet;
import com.arsdigita.kernel.EmailAddress;
@ -38,7 +37,6 @@ import com.arsdigita.web.ApplicationType;
import org.apache.log4j.Logger;
/**
* Loader executes nonrecurring at install time and loads (installs and
* initializes) the Forum module.
@ -57,6 +55,7 @@ public class Loader extends PackageLoader {
public void run(final ScriptContext ctx) {
new KernelExcursion() {
public void excurse() {
setEffectiveParty(Kernel.getSystemParty());
@ -77,23 +76,22 @@ public class Loader extends PackageLoader {
* @return
*/
private static ApplicationType setupForumAppType() {
ApplicationType type = ApplicationType
.createApplicationType(Forum.PACKAGE_TYPE,
ApplicationType type =
ApplicationType.createApplicationType(Forum.PACKAGE_TYPE,
"Discussion Forum Application",
Forum.BASE_DATA_OBJECT_TYPE);
type.setDescription("An electronic bulletin board system.");
return type;
}
/**
* TODO: What is it for? Execution is currently commented out.
* Referenced class com.arsdigita.forum.Inbox does not exist.
* @return
*/
private static ApplicationType setupInboxAppType() {
ApplicationType type = ApplicationType
.createApplicationType(Forum.PACKAGE_TYPE,
ApplicationType type =
ApplicationType.createApplicationType(Forum.PACKAGE_TYPE,
"Inbox",
"com.arsdigita.forum.Inbox");
type.setDescription("Inbox");
@ -105,14 +103,15 @@ public class Loader extends PackageLoader {
* @return
*/
public static AppPortletType setupRecentPostingsPortletType() {
AppPortletType type = AppPortletType
.createAppPortletType("Recent Forum Postings",
AppPortletType type =
AppPortletType.createAppPortletType(
"Recent Forum Postings",
PortletType.WIDE_PROFILE,
RecentPostingsPortlet.BASE_DATA_OBJECT_TYPE);
type.setProviderApplicationType(Forum.BASE_DATA_OBJECT_TYPE);
type.setPortalApplication(true);
type.setDescription("Displays the most recent postings " +
"to the bulletin board.");
type.setDescription("Displays the most recent postings "
+ "to the bulletin board.");
return type;
}
@ -122,8 +121,8 @@ public class Loader extends PackageLoader {
"My Forums",
PortletType.WIDE_PROFILE,
MyForumsPortlet.BASE_DATA_OBJECT_TYPE);
type.setDescription("Lists forums that user has access to, " + "" +
" with last posting date");
type.setDescription("Lists forums that user has access to, " + ""
+ " with last posting date");
return type;
}
@ -159,22 +158,18 @@ public class Loader extends PackageLoader {
*/
public static void setupPrivileges() {
PrivilegeDescriptor.createPrivilege(
Forum.FORUM_MODERATION_PRIVILEGE);
PrivilegeDescriptor.createPrivilege(
Forum.CREATE_THREAD_PRIVILEGE);
PrivilegeDescriptor.createPrivilege(
Forum.RESPOND_TO_THREAD_PRIVILEGE);
PrivilegeDescriptor.createPrivilege(Forum.FORUM_READ_PRIVILEGE);
PrivilegeDescriptor.createPrivilege(Forum.FORUM_MODERATION_PRIVILEGE);
PrivilegeDescriptor.createPrivilege(Forum.CREATE_THREAD_PRIVILEGE);
PrivilegeDescriptor.createPrivilege(Forum.RESPOND_TO_THREAD_PRIVILEGE);
// Establich privilege hierarchie, eg. moderation includes createThread
PrivilegeDescriptor.addChildPrivilege(
Forum.FORUM_MODERATION_PRIVILEGE,
PrivilegeDescriptor.addChildPrivilege(Forum.FORUM_MODERATION_PRIVILEGE,
Forum.CREATE_THREAD_PRIVILEGE);
PrivilegeDescriptor.addChildPrivilege(
Forum.CREATE_THREAD_PRIVILEGE,
PrivilegeDescriptor.addChildPrivilege(Forum.CREATE_THREAD_PRIVILEGE,
Forum.RESPOND_TO_THREAD_PRIVILEGE);
PrivilegeDescriptor.addChildPrivilege(
Forum.RESPOND_TO_THREAD_PRIVILEGE,
PrivilegeDescriptor.addChildPrivilege(Forum.RESPOND_TO_THREAD_PRIVILEGE,
PrivilegeDescriptor.READ.getName()); // general read privilege
PrivilegeDescriptor.addChildPrivilege(Forum.RESPOND_TO_THREAD_PRIVILEGE,
Forum.FORUM_READ_PRIVILEGE);
}
}

View File

@ -55,13 +55,13 @@ import com.arsdigita.xml.Element;
*
* @author Kevin Scaldeferri (kevin@arsdigita.com)
* @author Chris Gilbert (chrisg23)
* @author Jens Pelzetter (jensp)
* @version $Revision: 1.3 $ $Author: chrisg23 $ $Date: 2006/03/09 13:48:15 $
*/
public class ForumUserCompactView extends ModalContainer implements Constants {
/** Private logger instance for debugging purpose. */
private static Logger s_log = Logger.getLogger(ForumUserCompactView.class);
// Denotes the 6 panels of the user interface, also used as marker to store
// and select the active panel
/** Denotation of the 'threads' forum mode */
@ -79,7 +79,6 @@ public class ForumUserCompactView extends ModalContainer implements Constants {
public static final String MODE_SETUP = "setup";
/** Holds the current active mode */
private StringParameter m_mode;
/** Object containing the threads panel (main working panel for users) */
private ThreadsPanel m_threadsView;
/** Object containing the topics panel */
@ -145,7 +144,7 @@ public class ForumUserCompactView extends ModalContainer implements Constants {
Party party = Kernel.getContext().getParty();
Forum forum = ForumContext.getContext(state).getForum();
String mode = (String)state.getControlEventValue();
String mode = (String) state.getControlEventValue();
state.setValue(m_mode, mode);
setVisible(state, party, forum, mode);
@ -163,11 +162,12 @@ public class ForumUserCompactView extends ModalContainer implements Constants {
* @param forum the forum instance to handle
* @param mode forum mode to check visibility for
*/
protected void setVisible( PageState state, Party party,
protected void setVisible(PageState state, Party party,
Forum forum, String mode) {
PermissionDescriptor forumAdmin =
new PermissionDescriptor(PrivilegeDescriptor.ADMIN, forum, party);
new PermissionDescriptor(PrivilegeDescriptor.ADMIN,
forum, party);
PermissionService.assertPermission(forumAdmin);
@ -249,13 +249,24 @@ public class ForumUserCompactView extends ModalContainer implements Constants {
protected void generateModes(PageState state, Element content,
Party party, Forum forum) {
PermissionDescriptor permission =
new PermissionDescriptor(PrivilegeDescriptor.ADMIN, forum, party);
PermissionDescriptor permission = new PermissionDescriptor(
PrivilegeDescriptor.ADMIN,
forum,
party);
PermissionDescriptor readPermission = new PermissionDescriptor(
PrivilegeDescriptor.get(Forum.FORUM_READ_PRIVILEGE),
forum,
party);
// currently thread panel is always shown. If read access should be
// bound to logged in users, additional logic is required here.
// jensp 2011-10-02: Additional logic added
if (!forum.isPublic()
&& PermissionService.checkPermission(readPermission)) {
generateModeXML(state, content, MODE_THREADS,
Text.gz("forum.ui.modeThreads"));
}
// topics panel is always shoen as well if not restricted to admins.
if (!Forum.getConfig().topicCreationByAdminOnly()) {
generateModeXML(state, content, MODE_TOPICS,
@ -340,15 +351,16 @@ public class ForumUserCompactView extends ModalContainer implements Constants {
protected void generateModeXML(PageState state,
Element parent,
String mode,
GlobalizedMessage label ) {
GlobalizedMessage label) {
String current = (String)state.getValue(m_mode);
String current = (String) state.getValue(m_mode);
if (current == null) {
current = MODE_THREADS; // used as default mode
}
Element content =
parent.newChildElement(FORUM_XML_PREFIX + ":forumMode", FORUM_XML_NS);
parent.newChildElement(FORUM_XML_PREFIX + ":forumMode",
FORUM_XML_NS);
state.setControlEvent(this, "mode", mode);
@ -369,14 +381,11 @@ public class ForumUserCompactView extends ModalContainer implements Constants {
"UNAVAILABLE");
} else {
content.addAttribute("label",
(String)label.localize());
(String) label.localize());
}
// add if current mode is actually selected
content.addAttribute("selected",
current.equals(mode) ? "1" : "0");
state.clearControlEvent();
}
}