CCM NG: Setup for content sections
git-svn-id: https://svn.libreccm.org/ccm/ccm_ng@4193 8810af33-2d31-482b-a856-94f89814c4dfpull/2/head
parent
aa1aeef686
commit
0e291a87b9
|
|
@ -3,6 +3,10 @@
|
|||
*/
|
||||
package org.librecms;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.libreccm.categorization.Category;
|
||||
import org.libreccm.core.CoreConstants;
|
||||
import org.libreccm.modules.CcmModule;
|
||||
import org.libreccm.modules.InitEvent;
|
||||
import org.libreccm.modules.InstallEvent;
|
||||
|
|
@ -10,6 +14,12 @@ import org.libreccm.modules.Module;
|
|||
import org.libreccm.modules.RequiredModule;
|
||||
import org.libreccm.modules.ShutdownEvent;
|
||||
import org.libreccm.modules.UnInstallEvent;
|
||||
import org.librecms.contentsection.ContentSection;
|
||||
import org.librecms.contentsection.ContentSectionSetup;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.Properties;
|
||||
|
||||
@Module(packageName = "org.libreccm.cms",
|
||||
requiredModules = {
|
||||
|
|
@ -18,16 +28,33 @@ import org.libreccm.modules.UnInstallEvent;
|
|||
)
|
||||
public class Cms implements CcmModule {
|
||||
|
||||
private static final Logger LOGGER = LogManager.getLogger(Cms.class);
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public void install(final InstallEvent event) {
|
||||
//ToDo Create initial data for the module if neccessary
|
||||
|
||||
// Create initial content section
|
||||
|
||||
// Create initial content section(s)
|
||||
// If a list of sections is provided in the integration properties
|
||||
// use that list, otherwise create a content section named 'info'.
|
||||
|
||||
LOGGER.info("Trying to load integration properties...");
|
||||
final Properties integrationProps = new Properties();
|
||||
try (final InputStream inputStream = getClass().getResourceAsStream(
|
||||
CoreConstants.INTEGRATION_PROPS)) {
|
||||
integrationProps.load(inputStream);
|
||||
} catch (IOException ex) {
|
||||
LOGGER.warn(
|
||||
"Failed to load integration properties. Using default values.",
|
||||
ex);
|
||||
}
|
||||
|
||||
final ContentSectionSetup contentSectionSetup = new ContentSectionSetup(
|
||||
event);
|
||||
contentSectionSetup.setup();
|
||||
|
||||
// Map given domains to content section(s)
|
||||
|
||||
// Also create the following roles for each content section and assign
|
||||
// the permissions
|
||||
//
|
||||
|
|
@ -40,6 +67,15 @@ public class Cms implements CcmModule {
|
|||
// * Content Reader: View Published Items
|
||||
}
|
||||
|
||||
private void createContentSection(final String contentSectionName) {
|
||||
final ContentSection section = new ContentSection();
|
||||
section.setLabel(contentSectionName);
|
||||
|
||||
final Category rootFolder = new Category();
|
||||
rootFolder.setName(String.format("%s_root", contentSectionName));
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init(final InitEvent event) {
|
||||
//ToDo Add initialisation logic necessary for your module
|
||||
|
|
|
|||
|
|
@ -23,13 +23,28 @@ package org.librecms;
|
|||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||
*/
|
||||
public class CmsConstants {
|
||||
|
||||
|
||||
public static final String CMS_XML_NS = "http://cms.libreccm.org";
|
||||
|
||||
|
||||
public static final String DB_SCHEMA = "CCM_CMS";
|
||||
|
||||
|
||||
public static final String PRIVILEGE_ADMINISTER_CATEGORIES = "administer_categories";
|
||||
public static final String PRIVILEGE_ADMINISTER_CONTENT_TYPES = "administer_content_types";
|
||||
public static final String PRIVILEGE_ADMINISTER_LIFECYLES = "administer_lifecyles";
|
||||
public static final String PRIVILEGE_ADMINISTER_ROLES = "administer_roles";
|
||||
public static final String PRIVILEGE_ADMINISTER_WORKFLOW = "administer_workflow";
|
||||
public static final String PRIVILEGE_ITEMS_APPROVE = "approve_items";
|
||||
public static final String PRIVILEGE_ITEMS_PUBLISH = "publish_items";
|
||||
public static final String PRIVILEGE_ITEMS_CATEGORIZE = "categories_items";
|
||||
public static final String PRIVILEGE_ITEMS_CREATE_NEW = "create_new_items";
|
||||
public static final String PRIVILEGE_ITEMS_DELETE = "delete_items";
|
||||
public static final String PRIVILEGE_ITEMS_EDIT = "edit_items";
|
||||
public static final String PRIVILEGE_ITEMS_PREVIEW = "preview_items";
|
||||
public static final String PRIVILEGE_ITEMS_VIEW_PUBLISHED = "view_published_items";
|
||||
public static final String PRIVILEGE_APPLY_ALTERNATE_WORKFLOW = "apply_alternate_workflow";
|
||||
|
||||
private CmsConstants() {
|
||||
//Nothing
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,150 @@
|
|||
/*
|
||||
* Copyright (C) 2016 LibreCCM Foundation.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
* MA 02110-1301 USA
|
||||
*/
|
||||
package org.librecms.contentsection;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.libreccm.categorization.Category;
|
||||
import org.libreccm.modules.InstallEvent;
|
||||
import org.libreccm.security.Role;
|
||||
import org.libreccm.web.AbstractCcmApplicationSetup;
|
||||
|
||||
import static org.librecms.CmsConstants.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||
*/
|
||||
public class ContentSectionSetup extends AbstractCcmApplicationSetup {
|
||||
|
||||
private static final Logger LOGGER = LogManager.getLogger(
|
||||
ContentSectionSetup.class);
|
||||
|
||||
private static final String INITIAL_CONTENT_SECTIONS
|
||||
= "org.librecms.initial_content_sections";
|
||||
|
||||
public ContentSectionSetup(final InstallEvent event) {
|
||||
super(event);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setup() {
|
||||
final String contentSectionNames;
|
||||
if (getIntegrationProps().containsKey(INITIAL_CONTENT_SECTIONS)) {
|
||||
contentSectionNames = getIntegrationProps().getProperty(
|
||||
INITIAL_CONTENT_SECTIONS);
|
||||
} else {
|
||||
contentSectionNames = "info";
|
||||
}
|
||||
|
||||
for (final String contentSectionName : contentSectionNames.split(",")) {
|
||||
createContentSection(contentSectionName);
|
||||
}
|
||||
}
|
||||
|
||||
private void createContentSection(final String contentSectionName) {
|
||||
final ContentSection section = new ContentSection();
|
||||
section.setLabel(contentSectionName);
|
||||
|
||||
final Category rootFolder = new Category();
|
||||
rootFolder.setName(String.format("%s_root", contentSectionName));
|
||||
|
||||
final Category rootAssetFolder = new Category();
|
||||
rootFolder.setName(String.format("%s_assets", contentSectionName));
|
||||
|
||||
section.setRootDocumentFolder(rootFolder);
|
||||
section.setRootAssetsFolder(rootAssetFolder);
|
||||
|
||||
getEntityManager().persist(section);
|
||||
getEntityManager().persist(rootFolder);
|
||||
getEntityManager().persist(rootAssetFolder);
|
||||
|
||||
final Role alertRecipient = createRole(String.format(
|
||||
"%s_alert_recipient", contentSectionName));
|
||||
final Role author = createRole(String.format("%s_author",
|
||||
contentSectionName));
|
||||
final Role editor = createRole(String.format("%s_editor",
|
||||
contentSectionName));
|
||||
final Role manager = createRole(String.format("%s_manager",
|
||||
contentSectionName));
|
||||
final Role publisher = createRole(String.format("%s_publisher",
|
||||
contentSectionName));
|
||||
final Role contentReader = createRole(String.format("%s_content_reader",
|
||||
contentSectionName));
|
||||
|
||||
grantPermissions(author,
|
||||
rootFolder,
|
||||
PRIVILEGE_ITEMS_CATEGORIZE,
|
||||
PRIVILEGE_ITEMS_CREATE_NEW,
|
||||
PRIVILEGE_ITEMS_EDIT,
|
||||
PRIVILEGE_ITEMS_VIEW_PUBLISHED,
|
||||
PRIVILEGE_ITEMS_PREVIEW);
|
||||
|
||||
grantPermissions(editor,
|
||||
rootFolder,
|
||||
PRIVILEGE_ITEMS_CATEGORIZE,
|
||||
PRIVILEGE_ITEMS_CREATE_NEW,
|
||||
PRIVILEGE_ITEMS_EDIT,
|
||||
PRIVILEGE_ITEMS_APPROVE,
|
||||
PRIVILEGE_ITEMS_DELETE,
|
||||
PRIVILEGE_ITEMS_VIEW_PUBLISHED,
|
||||
PRIVILEGE_ITEMS_PREVIEW);
|
||||
|
||||
grantPermissions(manager,
|
||||
rootFolder,
|
||||
PRIVILEGE_ADMINISTER_ROLES,
|
||||
PRIVILEGE_ADMINISTER_WORKFLOW,
|
||||
PRIVILEGE_ADMINISTER_LIFECYLES,
|
||||
PRIVILEGE_ADMINISTER_CATEGORIES,
|
||||
PRIVILEGE_ADMINISTER_CONTENT_TYPES,
|
||||
PRIVILEGE_ITEMS_CATEGORIZE,
|
||||
PRIVILEGE_ITEMS_CREATE_NEW,
|
||||
PRIVILEGE_ITEMS_EDIT,
|
||||
PRIVILEGE_ITEMS_APPROVE,
|
||||
PRIVILEGE_ITEMS_PUBLISH,
|
||||
PRIVILEGE_ITEMS_DELETE,
|
||||
PRIVILEGE_ITEMS_VIEW_PUBLISHED,
|
||||
PRIVILEGE_ITEMS_PREVIEW);
|
||||
|
||||
grantPermissions(editor,
|
||||
rootFolder,
|
||||
PRIVILEGE_ITEMS_CATEGORIZE,
|
||||
PRIVILEGE_ITEMS_CREATE_NEW,
|
||||
PRIVILEGE_ITEMS_EDIT,
|
||||
PRIVILEGE_ITEMS_APPROVE,
|
||||
PRIVILEGE_ITEMS_PUBLISH,
|
||||
PRIVILEGE_ITEMS_DELETE,
|
||||
PRIVILEGE_ITEMS_VIEW_PUBLISHED,
|
||||
PRIVILEGE_ITEMS_PREVIEW);
|
||||
|
||||
grantPermissions(contentReader,
|
||||
rootFolder,
|
||||
PRIVILEGE_ITEMS_VIEW_PUBLISHED);
|
||||
|
||||
|
||||
getEntityManager().persist(alertRecipient);
|
||||
getEntityManager().persist(author);
|
||||
getEntityManager().persist(editor);
|
||||
getEntityManager().persist(manager);
|
||||
getEntityManager().persist(publisher);
|
||||
getEntityManager().persist(contentReader);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -24,7 +24,6 @@ import org.libreccm.core.CcmObject;
|
|||
import org.libreccm.core.CoreConstants;
|
||||
import org.libreccm.modules.InstallEvent;
|
||||
import org.libreccm.security.ApplicationRoleSetup;
|
||||
import org.libreccm.security.Permission;
|
||||
import org.libreccm.security.Role;
|
||||
|
||||
import java.io.IOException;
|
||||
|
|
@ -82,6 +81,20 @@ public abstract class AbstractCcmApplicationSetup {
|
|||
appRoleSetup.grantPermission(role, privilege, ccmObject);
|
||||
}
|
||||
|
||||
public void grantPermissions(final Role role, final String... privileges) {
|
||||
for(final String privilege : privileges) {
|
||||
grantPermission(role, privilege);
|
||||
}
|
||||
}
|
||||
|
||||
public void grantPermissions(final Role role,
|
||||
final CcmObject ccmObject,
|
||||
final String... privileges) {
|
||||
for(final String privilege : privileges) {
|
||||
grantPermission(role, privilege, ccmObject);
|
||||
}
|
||||
}
|
||||
|
||||
public abstract void setup();
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue