Search in sources :

Example 1 with PortletLifecycleState

use of org.apereo.portal.portlet.om.PortletLifecycleState in project uPortal by Jasig.

the class PortletAdministrationHelper method updateLifecycleState.

private void updateLifecycleState(PortletDefinitionForm form, IPortletDefinition portletDef, IPerson publisher) {
    /*
         * Manage the metadata for each possible lifecycle state in turn...
         */
    // Will be entered as the timestamp for states that we trigger
    Date now = new Date();
    PortletLifecycleState selectedLifecycleState = form.getLifecycleState();
    /*
         * APPROVED
         */
    if (selectedLifecycleState.isEqualToOrAfter(PortletLifecycleState.APPROVED)) {
        // We are the 'approver' if it isn't previously approved...
        if (portletDef.getApprovalDate() == null) {
            portletDef.setApproverId(publisher.getID());
            portletDef.setApprovalDate(now);
        }
        if (selectedLifecycleState.equals(PortletLifecycleState.APPROVED) && form.getPublishDate() != null && // Permissions check required (of course) to use the auto-publish feature
        hasLifecyclePermission(publisher, PortletLifecycleState.PUBLISHED, form.getCategories())) {
            // We are also the 'publisher' if we scheduled the portlet for (future) publication...
            portletDef.setPublishDate(form.getPublishDateTime());
            portletDef.setPublisherId(publisher.getID());
        }
    } else {
        // Clear previous approval fields, if present...
        portletDef.setApprovalDate(null);
        portletDef.setApproverId(-1);
    }
    /*
         * PUBLISHED
         */
    if (selectedLifecycleState.isEqualToOrAfter(PortletLifecycleState.PUBLISHED)) {
        // We are the 'publisher' if it isn't previously published or the publish time hasn't hit yet...
        if (portletDef.getPublishDate() == null || portletDef.getPublishDate().after(now)) {
            portletDef.setPublisherId(publisher.getID());
            portletDef.setPublishDate(now);
        }
        if (selectedLifecycleState.equals(PortletLifecycleState.PUBLISHED) && form.getExpirationDate() != null && // Permissions check required (of course) to use the auto-expire feature
        hasLifecyclePermission(publisher, PortletLifecycleState.EXPIRED, form.getCategories())) {
            // We are also the 'expirer' if we scheduled the portlet for (future) expiration...
            portletDef.setExpirationDate(form.getExpirationDateTime());
            portletDef.setExpirerId(publisher.getID());
        }
    } else if (!selectedLifecycleState.equals(PortletLifecycleState.APPROVED) || form.getPublishDate() == null) {
        // Clear previous publishing fields, if present...
        portletDef.setPublishDate(null);
        portletDef.setPublisherId(-1);
    }
    /*
         * EXPIRED
         */
    if (selectedLifecycleState.equals(PortletLifecycleState.EXPIRED)) {
        // We are only the 'expirer' if we specifically choose EXPIRED
        // (MAINTENANCE mode is not considered expired)
        portletDef.setExpirerId(publisher.getID());
        portletDef.setExpirationDate(now);
    } else if (!selectedLifecycleState.equals(PortletLifecycleState.PUBLISHED) || form.getExpirationDate() == null) {
        // Clear previous expiration fields, if present...
        portletDef.setExpirationDate(null);
        portletDef.setExpirerId(-1);
    }
    /*
         * MAINTENANCE
         */
    if (selectedLifecycleState.equals(PortletLifecycleState.MAINTENANCE)) {
        // We are placing the portlet into MAINTENANCE mode;
        // an admin will restore it (manually) when available
        portletDef.addParameter(PortletLifecycleState.MAINTENANCE_MODE_PARAMETER_NAME, "true");
    } else {
        // Otherwise we must remove the MAINTENANCE flag, if present
        portletDef.removeParameter(PortletLifecycleState.MAINTENANCE_MODE_PARAMETER_NAME);
    }
}
Also used : PortletLifecycleState(org.apereo.portal.portlet.om.PortletLifecycleState) Date(java.util.Date)

Example 2 with PortletLifecycleState

use of org.apereo.portal.portlet.om.PortletLifecycleState in project uPortal by Jasig.

the class AuthorizationImpl method canPrincipalManage.

/**
     * Answers if the principal has permission to MANAGE this Channel.
     *
     * @return boolean
     * @param principal IAuthorizationPrincipal
     * @param portletDefinitionId
     * @exception AuthorizationException indicates authorization information could not be retrieved.
     */
@RequestCache
public boolean canPrincipalManage(IAuthorizationPrincipal principal, String portletDefinitionId) throws AuthorizationException {
    String owner = IPermission.PORTAL_PUBLISH;
    String target = IPermission.PORTLET_PREFIX + portletDefinitionId;
    // retrieve the indicated channel from the channel registry store and
    // determine its current lifecycle state
    IPortletDefinition portlet = this.portletDefinitionRegistry.getPortletDefinition(portletDefinitionId);
    if (portlet == null) {
        return doesPrincipalHavePermission(principal, owner, IPermission.PORTLET_MANAGER_APPROVED_ACTIVITY, target);
    //    	throw new AuthorizationException("Unable to locate channel " + channelPublishId);
    }
    PortletLifecycleState state = portlet.getLifecycleState();
    int order = state.getOrder();
    /*
         * The following code assumes that later lifecycle states imply permission
         * for earlier lifecycle states.  For example, if a user has permission to
         * manage an expired channel, we assume s/he also has permission to
         * create, approve, and publish channels.  The following code counts
         * channels with auto-publish or auto-expiration dates set as requiring
         * publish or expiration permissions for management, even though the channel
         * may not yet be published or expired.
         */
    String activity = IPermission.PORTLET_MANAGER_MAINTENANCE_ACTIVITY;
    if (order <= PortletLifecycleState.MAINTENANCE.getOrder() && doesPrincipalHavePermission(principal, owner, activity, target)) {
        return true;
    }
    activity = IPermission.PORTLET_MANAGER_EXPIRED_ACTIVITY;
    if ((order <= PortletLifecycleState.EXPIRED.getOrder() || portlet.getExpirationDate() != null) && doesPrincipalHavePermission(principal, owner, activity, target)) {
        return true;
    }
    activity = IPermission.PORTLET_MANAGER_ACTIVITY;
    if ((order <= PortletLifecycleState.PUBLISHED.getOrder() || portlet.getPublishDate() != null) && doesPrincipalHavePermission(principal, owner, activity, target)) {
        return true;
    }
    activity = IPermission.PORTLET_MANAGER_APPROVED_ACTIVITY;
    log.debug("order: " + order + ", approved order: " + PortletLifecycleState.APPROVED.getOrder());
    if (order <= PortletLifecycleState.APPROVED.getOrder() && doesPrincipalHavePermission(principal, owner, activity, target)) {
        return true;
    }
    activity = IPermission.PORTLET_MANAGER_CREATED_ACTIVITY;
    if (order <= PortletLifecycleState.CREATED.getOrder() && doesPrincipalHavePermission(principal, owner, activity, target)) {
        return true;
    }
    // if no permissions were found, return false
    return false;
}
Also used : PortletLifecycleState(org.apereo.portal.portlet.om.PortletLifecycleState) IPortletDefinition(org.apereo.portal.portlet.om.IPortletDefinition) RequestCache(org.apereo.portal.concurrency.caching.RequestCache)

Example 3 with PortletLifecycleState

use of org.apereo.portal.portlet.om.PortletLifecycleState in project uPortal by Jasig.

the class AuthorizationImpl method canPrincipalSubscribe.

/**
     * Answers if the principal has permission to SUBSCRIBE to this Channel.
     *
     * @return boolean
     * @param principal IAuthorizationPrincipal
     * @param portletDefinitionId
     * @exception AuthorizationException indicates authorization information could not be retrieved.
     */
@RequestCache
public boolean canPrincipalSubscribe(IAuthorizationPrincipal principal, String portletDefinitionId) {
    String owner = IPermission.PORTAL_SUBSCRIBE;
    // retrieve the indicated channel from the channel registry store and
    // determine its current lifecycle state
    IPortletDefinition portlet = this.portletDefinitionRegistry.getPortletDefinition(portletDefinitionId);
    if (portlet == null) {
        return false;
    }
    String target = PermissionHelper.permissionTargetIdForPortletDefinition(portlet);
    PortletLifecycleState state = portlet.getLifecycleState();
    /*
         * Each channel lifecycle state now has its own subscribe permission.  The
         * following logic checks the appropriate permission for the lifecycle.
         */
    String permission;
    if (state.equals(PortletLifecycleState.PUBLISHED) || state.equals(PortletLifecycleState.MAINTENANCE)) {
        // NB:  There is no separate SUBSCRIBE permission for MAINTENANCE
        // mode;  everyone simply sees the 'out of service' message
        permission = IPermission.PORTLET_SUBSCRIBER_ACTIVITY;
    } else if (state.equals(PortletLifecycleState.APPROVED)) {
        permission = IPermission.PORTLET_SUBSCRIBER_APPROVED_ACTIVITY;
    } else if (state.equals(PortletLifecycleState.CREATED)) {
        permission = IPermission.PORTLET_SUBSCRIBER_CREATED_ACTIVITY;
    } else if (state.equals(PortletLifecycleState.EXPIRED)) {
        permission = IPermission.PORTLET_SUBSCRIBER_EXPIRED_ACTIVITY;
    } else {
        throw new AuthorizationException("Unrecognized lifecycle state for channel " + portletDefinitionId);
    }
    // Test the appropriate permission.
    return doesPrincipalHavePermission(principal, owner, permission, target);
}
Also used : PortletLifecycleState(org.apereo.portal.portlet.om.PortletLifecycleState) AuthorizationException(org.apereo.portal.AuthorizationException) IPortletDefinition(org.apereo.portal.portlet.om.IPortletDefinition) RequestCache(org.apereo.portal.concurrency.caching.RequestCache)

Aggregations

PortletLifecycleState (org.apereo.portal.portlet.om.PortletLifecycleState)3 RequestCache (org.apereo.portal.concurrency.caching.RequestCache)2 IPortletDefinition (org.apereo.portal.portlet.om.IPortletDefinition)2 Date (java.util.Date)1 AuthorizationException (org.apereo.portal.AuthorizationException)1