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);
}
}
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();
}
}
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);
}
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);
}
}
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;
}
Aggregations