Search in sources :

Example 1 with CmsUser

use of org.opencms.file.CmsUser in project opencms-core by alkacon.

the class CmsModuleAddResourceTypeThread method lockTemporary.

/**
 * Locks the given resource temporarily.<p>
 *
 * @param resource the resource to lock
 *
 * @throws CmsException if locking fails
 */
private void lockTemporary(CmsResource resource) throws CmsException {
    CmsObject cms = getCms();
    CmsUser user = cms.getRequestContext().getCurrentUser();
    CmsLock lock = cms.getLock(resource);
    if (!lock.isOwnedBy(user)) {
        cms.lockResourceTemporary(resource);
    } else if (!lock.isOwnedInProjectBy(user, cms.getRequestContext().getCurrentProject())) {
        cms.changeLock(resource);
    }
}
Also used : CmsObject(org.opencms.file.CmsObject) CmsUser(org.opencms.file.CmsUser) CmsLock(org.opencms.lock.CmsLock)

Example 2 with CmsUser

use of org.opencms.file.CmsUser in project opencms-core by alkacon.

the class CmsPublishEngine method sendMessage.

/**
 * Sends a message to the given user, if publish notification is enabled or an error is shown in the message.<p>
 *
 * @param toUserId the id of the user to send the message to
 * @param message the message to send
 * @param hasErrors flag to determine if the message to send shows an error
 */
protected void sendMessage(CmsUUID toUserId, String message, boolean hasErrors) {
    CmsDbContext dbc = m_dbContextFactory.getDbContext();
    try {
        CmsUser toUser = m_driverManager.readUser(dbc, toUserId);
        CmsUserSettings settings = new CmsUserSettings(toUser);
        if (settings.getShowPublishNotification() || hasErrors) {
            // only show message if publish notification is enabled or the message shows an error
            OpenCms.getSessionManager().sendBroadcast(null, message, toUser, ContentMode.plain);
        }
    } catch (CmsException e) {
        dbc.rollback();
        LOG.error(e.getLocalizedMessage(), e);
    } finally {
        dbc.clear();
    }
}
Also used : CmsDbContext(org.opencms.db.CmsDbContext) CmsUserSettings(org.opencms.db.CmsUserSettings) CmsException(org.opencms.main.CmsException) CmsUser(org.opencms.file.CmsUser)

Example 3 with CmsUser

use of org.opencms.file.CmsUser in project opencms-core by alkacon.

the class CmsWorkplaceAppManager method setUserQuickLaunchApps.

/**
 * Writes the user quick launch apps setting to the user additional info.<p>
 *
 * @param cms the cms context
 * @param apps the app ids
 *
 * @throws Exception in case writing the user fails
 */
protected void setUserQuickLaunchApps(CmsObject cms, List<String> apps) throws Exception {
    JSONArray appIds = new JSONArray(apps);
    CmsUser user = cms.getRequestContext().getCurrentUser();
    String infoValue = appIds.toString();
    String previousApps = (String) user.getAdditionalInfo(QUICK_LAUCH_APPS_KEY);
    // remove the additional info value to use default setting, in case the selected apps match the default apps
    if (new JSONArray(DEFAULT_USER_APPS).toString().equals(infoValue)) {
        infoValue = null;
    }
    // check if the additional info value needs to be changed
    if ((infoValue == previousApps) || ((infoValue != null) && infoValue.equals(previousApps))) {
        return;
    }
    if (infoValue == null) {
        user.deleteAdditionalInfo(QUICK_LAUCH_APPS_KEY);
    } else {
        user.setAdditionalInfo(QUICK_LAUCH_APPS_KEY, infoValue);
    }
    cms.writeUser(user);
}
Also used : JSONArray(org.opencms.json.JSONArray) CmsUser(org.opencms.file.CmsUser)

Example 4 with CmsUser

use of org.opencms.file.CmsUser in project opencms-core by alkacon.

the class CmsWorkplaceManager method checkWorkplaceRequest.

/**
 * Checks whether the workplace is accessed through the workplace server, and sends an error message otherwise.<p>
 *
 * @param request the request to check
 * @param cms the CmsObject to use
 */
public void checkWorkplaceRequest(HttpServletRequest request, CmsObject cms) {
    try {
        if ((OpenCms.getSiteManager().getSites().size() > 1) && !OpenCms.getSiteManager().isWorkplaceRequest(request)) {
            // this is a multi site-configuration, but not a request to the configured Workplace site
            CmsUser user = cms.getRequestContext().getCurrentUser();
            // with the user name as  key
            if (null == m_workplaceServerUserChecks.getIfPresent(user.getName())) {
                m_workplaceServerUserChecks.put(user.getName(), "");
                OpenCms.getSessionManager().sendBroadcast(null, Messages.get().getBundle(getWorkplaceLocale(cms)).key(Messages.ERR_WORKPLACE_SERVER_CHECK_FAILED_0), user, ContentMode.plain);
            }
        }
    } catch (Exception e) {
        LOG.error(e.getLocalizedMessage(), e);
    }
}
Also used : CmsUser(org.opencms.file.CmsUser) CmsRoleViolationException(org.opencms.security.CmsRoleViolationException) PatternSyntaxException(java.util.regex.PatternSyntaxException) CmsException(org.opencms.main.CmsException) CmsVfsResourceNotFoundException(org.opencms.file.CmsVfsResourceNotFoundException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) CmsLoaderException(org.opencms.loader.CmsLoaderException) CmsPermissionViolationException(org.opencms.security.CmsPermissionViolationException) IOException(java.io.IOException)

Example 5 with CmsUser

use of org.opencms.file.CmsUser in project opencms-core by alkacon.

the class CmsExtendedWorkflowManager method generateProjectName.

/**
 * Generates the name for a new workflow project based on the user for whom it is created.<p>
 *
 * @param userCms the user's current CMS context
 * @param shortTime if true, the short time format will be used, else the medium time format
 *
 * @return the workflow project name
 */
protected String generateProjectName(CmsObject userCms, boolean shortTime) {
    CmsUser user = userCms.getRequestContext().getCurrentUser();
    long time = System.currentTimeMillis();
    Date date = new Date(time);
    OpenCms.getLocaleManager();
    Locale locale = CmsLocaleManager.getDefaultLocale();
    DateFormat dateFormat = DateFormat.getDateInstance(DateFormat.SHORT, locale);
    DateFormat timeFormat = DateFormat.getTimeInstance(shortTime ? DateFormat.SHORT : DateFormat.MEDIUM, locale);
    String dateStr = dateFormat.format(date) + " " + timeFormat.format(date);
    String username = user.getName();
    String result = Messages.get().getBundle(locale).key(Messages.GUI_WORKFLOW_PROJECT_NAME_2, username, dateStr);
    result = result.replaceAll("/", "|");
    return result;
}
Also used : Locale(java.util.Locale) DateFormat(java.text.DateFormat) CmsUser(org.opencms.file.CmsUser) Date(java.util.Date)

Aggregations

CmsUser (org.opencms.file.CmsUser)239 CmsException (org.opencms.main.CmsException)100 CmsObject (org.opencms.file.CmsObject)76 ArrayList (java.util.ArrayList)54 CmsUUID (org.opencms.util.CmsUUID)47 CmsResource (org.opencms.file.CmsResource)41 CmsGroup (org.opencms.file.CmsGroup)36 CmsListItem (org.opencms.workplace.list.CmsListItem)33 HashMap (java.util.HashMap)25 List (java.util.List)22 IOException (java.io.IOException)20 CmsRuntimeException (org.opencms.main.CmsRuntimeException)20 CmsRole (org.opencms.security.CmsRole)20 Iterator (java.util.Iterator)19 CmsProject (org.opencms.file.CmsProject)17 CmsLock (org.opencms.lock.CmsLock)17 SQLException (java.sql.SQLException)14 CmsDataAccessException (org.opencms.file.CmsDataAccessException)12 CmsUserSearchParameters (org.opencms.file.CmsUserSearchParameters)11 CmsVfsResourceNotFoundException (org.opencms.file.CmsVfsResourceNotFoundException)11