Skip to content

Commit 98e5cb0

Browse files
committed
ENG-5491: Preset owner group and join groups from user preferences
1 parent 4c8722d commit 98e5cb0

File tree

2 files changed

+35
-2
lines changed

2 files changed

+35
-2
lines changed

cms-plugin/src/main/java/com/agiletec/plugins/jacms/apsadmin/content/IntroNewContentAction.java

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@
1919
import com.agiletec.aps.system.services.group.Group;
2020
import com.agiletec.apsadmin.system.ApsAdminSystemConstants;
2121
import com.agiletec.plugins.jacms.aps.system.services.content.model.Content;
22+
import java.util.Arrays;
23+
import org.apache.commons.lang.StringUtils;
24+
import org.entando.entando.aps.system.services.userpreferences.IUserPreferencesManager;
25+
import org.entando.entando.aps.system.services.userpreferences.UserPreferences;
2226

2327
/**
2428
* Action gestore delle operazioni di creazione nuovo contenuto.
@@ -69,13 +73,31 @@ public String createNewVoid() {
6973
public String createNew() {
7074
try {
7175
_logger.debug("Create new content");
76+
String username = getCurrentUser().getUsername();
7277
Content prototype = this.getContentManager().createContentType(this.getContentTypeCode());
7378
if (null == prototype) {
7479
this.addFieldError("contentTypeCode", this.getText("error.content.type.invalid"));
7580
_logger.debug("Invalid content type");
7681
return INPUT;
7782
}
78-
prototype.setFirstEditor(this.getCurrentUser().getUsername());
83+
prototype.setFirstEditor(username);
84+
UserPreferences pref = this.getUserPreferencesManager().getUserPreferences(username);
85+
if (pref != null) {
86+
String defaultContentOwnerGroup = pref.getDefaultContentOwnerGroup();
87+
String defaultContentJoinGroups = pref.getDefaultContentJoinGroups();
88+
if (StringUtils.isNotBlank(defaultContentJoinGroups)) {
89+
String[] joinGroup = defaultContentJoinGroups.split(";");
90+
Arrays.stream(joinGroup).filter(c -> null != this.getGroup(c))
91+
.forEach(g -> {
92+
_logger.info("adding join group {} from user {} preferences", g, username);
93+
prototype.addGroup(g);
94+
});
95+
}
96+
if (StringUtils.isNotBlank(defaultContentOwnerGroup) && null != this.getGroup(defaultContentOwnerGroup)) {
97+
prototype.setMainGroup(defaultContentOwnerGroup);
98+
_logger.info("setting ownerGroup to {}", defaultContentOwnerGroup);
99+
}
100+
}
79101
this.fillSessionAttribute(prototype);
80102
} catch (Throwable t) {
81103
_logger.error("error in createNew", t);
@@ -149,10 +171,19 @@ public String getContentStatus() {
149171
public void setContentStatus(String contentStatus) {
150172
this._contentStatus = contentStatus;
151173
}
174+
175+
public IUserPreferencesManager getUserPreferencesManager() {
176+
return userPreferencesManager;
177+
}
178+
public void setUserPreferencesManager(IUserPreferencesManager userPreferencesManager) {
179+
this.userPreferencesManager = userPreferencesManager;
180+
}
152181

153182
private String _contentTypeCode;
154183
private String _contentDescription;
155184
private String _contentMainGroup;
156185
private String _contentStatus;
186+
187+
private transient IUserPreferencesManager userPreferencesManager;
157188

158189
}

cms-plugin/src/main/resources/spring/plugins/jacms/apsadmin/content/contentActionsConfig.xml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,9 @@
4545
</bean>
4646

4747
<bean id="jacmsIntroNewContentAction" scope="prototype"
48-
class="com.agiletec.plugins.jacms.apsadmin.content.IntroNewContentAction" parent="jacmsAbstractContentAction" />
48+
class="com.agiletec.plugins.jacms.apsadmin.content.IntroNewContentAction" parent="jacmsAbstractContentAction" >
49+
<property name="userPreferencesManager" ref="UserPreferencesManager" />
50+
</bean>
4951

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

0 commit comments

Comments
 (0)