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 98e5cb0
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@
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 +73,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 +171,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 @@ -45,7 +45,9 @@
</bean>

<bean id="jacmsIntroNewContentAction" scope="prototype"
class="com.agiletec.plugins.jacms.apsadmin.content.IntroNewContentAction" parent="jacmsAbstractContentAction" />
class="com.agiletec.plugins.jacms.apsadmin.content.IntroNewContentAction" parent="jacmsAbstractContentAction" >
<property name="userPreferencesManager" ref="UserPreferencesManager" />
</bean>

<bean id="jacmsContentAction" scope="prototype"
class="com.agiletec.plugins.jacms.apsadmin.content.ContentAction"
Expand Down

0 comments on commit 98e5cb0

Please sign in to comment.