Skip to content

Commit

Permalink
ENG-5491: Preset owner group and join groups from user preferences
Browse files Browse the repository at this point in the history
  • Loading branch information
eugeniosant committed Mar 26, 2024
1 parent 4c8722d commit 2561344
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,18 @@
*/
package com.agiletec.plugins.jacms.apsadmin.content;

import static com.opensymphony.xwork2.Action.SUCCESS;

import org.entando.entando.ent.util.EntLogging.EntLogger;
import org.entando.entando.ent.util.EntLogging.EntLogFactory;

import com.agiletec.aps.system.services.group.Group;
import com.agiletec.apsadmin.system.ApsAdminSystemConstants;
import com.agiletec.plugins.jacms.aps.system.services.content.model.Content;
import java.util.Arrays;
import org.apache.commons.lang.StringUtils;
import org.entando.entando.aps.system.services.userpreferences.IUserPreferencesManager;
import org.entando.entando.aps.system.services.userpreferences.UserPreferences;

/**
* Action gestore delle operazioni di creazione nuovo contenuto.
Expand Down Expand Up @@ -69,13 +75,31 @@ public String createNewVoid() {
public String createNew() {
try {
_logger.debug("Create new content");
String username = getCurrentUser().getUsername();
Content prototype = this.getContentManager().createContentType(this.getContentTypeCode());
if (null == prototype) {
this.addFieldError("contentTypeCode", this.getText("error.content.type.invalid"));
_logger.debug("Invalid content type");
return INPUT;
}
prototype.setFirstEditor(this.getCurrentUser().getUsername());
prototype.setFirstEditor(username);
UserPreferences pref = this.getUserPreferencesManager().getUserPreferences(username);
if (pref != null) {
String defaultContentOwnerGroup = pref.getDefaultContentOwnerGroup();
String defaultContentJoinGroups = pref.getDefaultContentJoinGroups();
if (StringUtils.isNotBlank(defaultContentJoinGroups)) {
String[] joinGroup = defaultContentJoinGroups.split(";");
Arrays.stream(joinGroup).filter(c -> null != this.getGroup(c))
.forEach(g -> {
_logger.info("adding join group {} from user {} preferences", g, username);
prototype.addGroup(g);
});
}
if (StringUtils.isNotBlank(defaultContentOwnerGroup) && null != this.getGroup(defaultContentOwnerGroup)) {
prototype.setMainGroup(defaultContentOwnerGroup);
_logger.info("setting ownerGroup to {}", defaultContentOwnerGroup);
}
}
this.fillSessionAttribute(prototype);
} catch (Throwable t) {
_logger.error("error in createNew", t);
Expand Down Expand Up @@ -149,10 +173,19 @@ public String getContentStatus() {
public void setContentStatus(String contentStatus) {
this._contentStatus = contentStatus;
}

public IUserPreferencesManager getUserPreferencesManager() {
return userPreferencesManager;
}
public void setUserPreferencesManager(IUserPreferencesManager userPreferencesManager) {
this.userPreferencesManager = userPreferencesManager;
}

private String _contentTypeCode;
private String _contentDescription;
private String _contentMainGroup;
private String _contentStatus;

private transient IUserPreferencesManager userPreferencesManager;

}
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
<property name="resourceManager" ref="jacmsResourceManager" />
<property name="pageModelManager" ref="PageModelManager" />
<property name="widgetTypeManager" ref="WidgetTypeManager" />
<property name="userPreferencesManager" ref="UserPreferencesManager" />
</bean>

<bean id="jacmsEntryContentActionActionsHookPoint" class="com.agiletec.apsadmin.system.plugin.HookPointElementContainer" >
Expand Down

0 comments on commit 2561344

Please sign in to comment.