Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/maven/fixes/9.1' into maven/rele…
Browse files Browse the repository at this point in the history
…ase/9.1
  • Loading branch information
metaventis-build committed Nov 19, 2024
2 parents d9b9759 + 11ed4a7 commit c188101
Show file tree
Hide file tree
Showing 47 changed files with 1,401 additions and 1,175 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -949,6 +949,21 @@ private List<MetadataSort> getSorts() throws XPathExpressionException {
}
}
}
if (name.equals("defaultSearch")) {
NodeList list3 = data.getChildNodes();
for (int k = 0; k < list3.getLength(); k++) {
if(sort.getDefaultValueSearch() == null) {
sort.setDefaultValueSearch(new MetadataSort.MetadataSortDefault());
}
Node data2 = list3.item(k);
if (data2.getNodeName().equals("sortBy")) {
sort.getDefaultValueSearch().setSortBy(data2.getTextContent());
}
if (data2.getNodeName().equals("sortAscending")) {
sort.getDefaultValueSearch().setSortAscending(Boolean.parseBoolean(data2.getTextContent()));
}
}
}
if (name.equals("columns")) {
List<MetadataSortColumn> columns = getMetadataSortColumns(data);
sort.setColumns(columns);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package org.edu_sharing.metadataset.v2;

import com.fasterxml.jackson.annotation.JsonPropertyDescription;
import lombok.Getter;
import lombok.Setter;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

public class MetadataSort implements Serializable {
public class MetadataSortDefault implements Serializable {
public static class MetadataSortDefault implements Serializable {
private String sortBy;
private boolean sortAscending;

Expand All @@ -27,7 +30,14 @@ public void setSortAscending(boolean sortAscending) {
}
private String id;
private String mode;
@JsonPropertyDescription("Default sort state (for both with and without a search string)")
@Getter
@Setter
private MetadataSortDefault defaultValue=new MetadataSortDefault();
@JsonPropertyDescription("Default sort state only when searching (when unset, defaultValue is used)")
@Getter
@Setter
private MetadataSortDefault defaultValueSearch=null;
private List<MetadataSortColumn> columns;

public String getId() {
Expand All @@ -53,14 +63,6 @@ public void setColumns(List<MetadataSortColumn> columns) {
this.columns = columns;
}

public MetadataSortDefault getDefaultValue() {
return defaultValue;
}

public void setDefaultValue(MetadataSortDefault defaultValue) {
this.defaultValue = defaultValue;
}

@Override
public boolean equals(Object obj) {
if(obj instanceof MetadataSort){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,14 @@

import jakarta.servlet.ServletContext;
import java.io.File;
import java.util.HashMap;
import java.util.Map;

/**
* Class to load language data from the angular i18n files (json)
*/
public class I18nAngular {
private static Map<String,String> I18N_CACHE = new HashMap<>();
public static final String GENDER_SEPARATOR = "*";
public static Logger logger=Logger.getLogger(I18nAngular.class);
public static String getTranslationAngular(String scope,String key){
Expand Down Expand Up @@ -54,9 +57,16 @@ public static JSONObject getLanguageStrings() throws Exception{
*/
private static String getTranslationAngular(String scope,String key,String language){
try {
String cache = I18N_CACHE.get(language + ":" + key);
if(cache != null) {
return cache;
}
String override=getTranslationFromOverride(key,language);
if(override!=null)
return replaceGenderSeperator(override);
if(override!=null) {
override = replaceGenderSeperator(override);
I18N_CACHE.put(language + ":" + key, override);
return override;
}
// Using global instance singe it only is used for file reading
ServletContext servletContext = Context.getGlobalContext();
if(servletContext == null) {
Expand All @@ -75,7 +85,9 @@ private static String getTranslationAngular(String scope,String key,String langu
object=object.getJSONObject(list[i]);
}
String result = object.getString(list[list.length-1]);
return replaceGenderSeperator(result);
result = replaceGenderSeperator(result);
I18N_CACHE.put(language + ":" + key, result);
return result;
} catch (Exception e) {
if(language.startsWith("de-")) {
return getTranslationAngular(scope, key, "de");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
import org.alfresco.repo.security.authentication.AuthenticationUtil;
import org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork;
import org.alfresco.repo.security.permissions.AccessDeniedException;
import org.alfresco.service.ServiceRegistry;
import org.alfresco.service.cmr.repository.DuplicateChildNodeNameException;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.security.PermissionService;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.namespace.QName;
import org.apache.commons.codec.digest.DigestUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.log4j.Logger;
Expand All @@ -25,6 +27,7 @@
import org.edu_sharing.restservices.shared.GroupProfile;
import org.edu_sharing.service.authority.AuthorityService;
import org.edu_sharing.service.authority.AuthorityServiceFactory;
import org.edu_sharing.service.authority.AuthorityServiceHelper;
import org.edu_sharing.service.nodeservice.NodeServiceHelper;
import org.edu_sharing.service.notification.NotificationService;
import org.edu_sharing.service.notification.NotificationServiceFactoryUtility;
Expand All @@ -38,6 +41,8 @@
import java.util.*;
import java.util.stream.Collectors;

import static org.alfresco.service.cmr.security.PermissionService.GROUP_PREFIX;

public class GroupDao {

static Logger logger = Logger.getLogger(GroupDao.class);
Expand All @@ -59,31 +64,34 @@ public static GroupDao getGroup(RepositoryDao repoDao, String groupName) throws
}
}

public static GroupDao createGroup(RepositoryDao repoDao, String groupName, GroupProfile profile, String parentGroup) throws DAOException {
public static String createGroup(RepositoryDao repoDao, String groupName, GroupProfile profile, String parentGroup) throws DAOException {
try {
AuthorityService authorityService = AuthorityServiceFactory.getAuthorityService(repoDao.getApplicationInfo().getAppId());
String result = authorityService.createGroup(groupName, profile.getDisplayName(), parentGroup);
GroupDao groupDao = GroupDao.getGroup(repoDao, result);
if (result != null) {
// permission check was done already, so run as system to allow org admin to set properties
AuthenticationUtil.runAsSystem(() -> {
groupDao.applyProfile(profile);
applyProfile(result.startsWith(GROUP_PREFIX) ? result : GROUP_PREFIX + result, profile);
return null;
});
}
// reload data after it was changed
return GroupDao.getGroup(repoDao, result);
return result;
} catch (Exception e) {
throw DAOException.mapping(e);
}
}

void applyProfile(GroupProfile profile) {
setGroupEmail(profile);
setGroupType(profile);
setScopeType(profile);
static void applyProfile(String authorityName, GroupProfile profile) {
ApplicationContext alfApplicationContext = AlfAppContextGate.getApplicationContext();
ServiceRegistry serviceRegistry = (ServiceRegistry) alfApplicationContext.getBean(ServiceRegistry.SERVICE_REGISTRY);
NodeService nodeService = serviceRegistry.getNodeService();

NodeRef authorityRef = AuthorityServiceHelper.getAuthorityNodeRef(authorityName);
setGroupEmail(nodeService, authorityRef, profile);
setGroupType(nodeService, authorityRef, profile);
setScopeType(nodeService, authorityRef, profile);
if(profile.getCustomAttributes() != null && !profile.getCustomAttributes().isEmpty()) {
authorityService.setCustomAttributes(authorityName, profile.getCustomAttributes());
AuthorityServiceFactory.getLocalService().setCustomAttributes(authorityName, profile.getCustomAttributes());
}
}

Expand Down Expand Up @@ -138,13 +146,13 @@ public GroupDao(RepositoryDao repoDao, String groupName) throws DAOException {
this.repoDao = repoDao;

this.authorityName =
groupName.startsWith(PermissionService.GROUP_PREFIX)
groupName.startsWith(GROUP_PREFIX)
? groupName
: PermissionService.GROUP_PREFIX + groupName;
: GROUP_PREFIX + groupName;

this.groupName =
groupName.startsWith(PermissionService.GROUP_PREFIX)
? groupName.substring(PermissionService.GROUP_PREFIX.length())
groupName.startsWith(GROUP_PREFIX)
? groupName.substring(GROUP_PREFIX.length())
: groupName;

this.displayName = ((MCAlfrescoAPIClient) baseClient).getGroupDisplayName(this.groupName);
Expand Down Expand Up @@ -181,7 +189,7 @@ public void changeProfile(GroupProfile profile) throws DAOException {
@Override
public Void doWork() throws Exception {
((MCAlfrescoAPIClient) repoDao.getBaseClient()).createOrUpdateGroup(groupName, profile.getDisplayName());
applyProfile(profile);
applyProfile(authorityName, profile);

// rename admin group
renameSubGroup(profile, org.edu_sharing.alfresco.service.AuthorityService.ADMINISTRATORS_GROUP, org.edu_sharing.alfresco.service.AuthorityService.ADMINISTRATORS_GROUP_DISPLAY_POSTFIX);
Expand Down Expand Up @@ -210,7 +218,7 @@ private void renameOrganisationFolder() {
}

private void renameSubGroup(GroupProfile profile, String subgroup, String postfix) {
String authorityName = PermissionService.GROUP_PREFIX + org.edu_sharing.alfresco.service.AuthorityService.getGroupName(
String authorityName = GROUP_PREFIX + org.edu_sharing.alfresco.service.AuthorityService.getGroupName(
subgroup, groupName);
if (authorityService.authorityExists(authorityName)) {
String newDisplayName = profile.getDisplayName() + postfix;
Expand All @@ -220,23 +228,23 @@ private void renameSubGroup(GroupProfile profile, String subgroup, String postfi
}
}

protected void setGroupType(GroupProfile profile) {
static protected void setGroupType(NodeService nodeService, NodeRef authorityRef, GroupProfile profile) {
if (profile.getGroupType() != null) {
authorityService.addAuthorityAspect(PermissionService.GROUP_PREFIX + groupName, CCConstants.CCM_ASPECT_GROUPEXTENSION);
nodeService.addAspect(authorityRef, QName.createQName(CCConstants.CCM_ASPECT_GROUPEXTENSION), new HashMap<>());
}
authorityService.setAuthorityProperty(PermissionService.GROUP_PREFIX + groupName, CCConstants.CCM_PROP_GROUPEXTENSION_GROUPTYPE, profile.getGroupType());
NodeServiceHelper.setProperty(authorityRef, CCConstants.CCM_PROP_GROUPEXTENSION_GROUPTYPE, profile.getGroupType(), true);
}

protected void setGroupEmail(GroupProfile profile) {
authorityService.setAuthorityProperty(PermissionService.GROUP_PREFIX + groupName, CCConstants.CCM_PROP_GROUPEXTENSION_GROUPEMAIL, profile.getGroupEmail());
static protected void setGroupEmail(NodeService nodeService, NodeRef authorityRef, GroupProfile profile) {
nodeService.setProperty(authorityRef, QName.createQName(CCConstants.CCM_PROP_GROUPEXTENSION_GROUPEMAIL), profile.getGroupEmail());

}

protected void setScopeType(GroupProfile profile) {
static protected void setScopeType(NodeService nodeService, NodeRef authorityRef, GroupProfile profile) {
if (profile.getScopeType() != null) {
authorityService.addAuthorityAspect(PermissionService.GROUP_PREFIX + groupName, CCConstants.CCM_ASPECT_SCOPE);
nodeService.addAspect(authorityRef, QName.createQName(CCConstants.CCM_ASPECT_SCOPE), new HashMap<>());
}
authorityService.setAuthorityProperty(PermissionService.GROUP_PREFIX + groupName, CCConstants.CCM_PROP_SCOPE_TYPE, profile.getScopeType());
nodeService.setProperty(authorityRef, QName.createQName(CCConstants.CCM_PROP_SCOPE_TYPE), profile.getScopeType());
}

public void delete() throws DAOException {
Expand All @@ -246,7 +254,7 @@ public void delete() throws DAOException {
AuthenticationUtil.runAsSystem(new RunAsWork<Void>() {
@Override
public Void doWork() throws Exception {
authorityService.deleteAuthority(PermissionService.GROUP_PREFIX + groupName);
authorityService.deleteAuthority(GROUP_PREFIX + groupName);
return null;
}
});
Expand Down Expand Up @@ -333,7 +341,7 @@ public Group asGroup(boolean resolveOrganizations) {
data.setProfile(profile);
data.setProperties(getProperties());
data.setAspects(getAspects());
data.setSignupMethod(getSignupMethod(ref));
data.setSignupMethod(getSignupMethod(properties));

return data;
}
Expand All @@ -342,8 +350,8 @@ private Map<String, Serializable> getCustomAttributes() {
return authorityService.getCustomAttributes(authorityName);
}

public static GroupSignupMethod getSignupMethod(NodeRef ref) {
String method = NodeServiceHelper.getProperty(ref, CCConstants.CCM_PROP_GROUP_SIGNUP_METHOD);
public static GroupSignupMethod getSignupMethod(Map<String, Object> properties) {
String method = (String) properties.get(CCConstants.CCM_PROP_GROUP_SIGNUP_METHOD);
if (method == null) {
return null;
}
Expand Down Expand Up @@ -426,7 +434,7 @@ public GroupSignupResult signupUser(String password) throws DAOException {
try {
ToolPermissionHelper.throwIfToolpermissionMissing(CCConstants.CCM_VALUE_TOOLPERMISSION_SIGNUP_GROUP);
return AuthenticationUtil.runAsSystem(() -> {
GroupSignupMethod method = getSignupMethod(ref);
GroupSignupMethod method = getSignupMethod(properties);
boolean addMember = false;
NodeRef userRef = authorityService.getAuthorityNodeRef(AuthenticationUtil.getFullyAuthenticatedUser());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2687,22 +2687,23 @@ public void setOwner(String username) {
nodeService.setOwner(this.getId(), username);
}

public void setProperty(String property, Serializable value, boolean keepModifiedDate) {
public static void setProperty(RepositoryDao repoDao, String nodeId, String property, Serializable value, boolean keepModifiedDate) {
NodeService nodeService = NodeServiceFactory.getNodeService(repoDao.getId());
if (keepModifiedDate) {
nodeService.keepModifiedDate(
StoreRef.STORE_REF_WORKSPACE_SPACESSTORE.getProtocol(), StoreRef.STORE_REF_WORKSPACE_SPACESSTORE.getIdentifier(), this.getId(),
() -> setPropertyInternal(property, value)
StoreRef.STORE_REF_WORKSPACE_SPACESSTORE.getProtocol(), StoreRef.STORE_REF_WORKSPACE_SPACESSTORE.getIdentifier(), nodeId,
() -> setPropertyInternal(nodeService, nodeId, property, value)
);
} else {
setPropertyInternal(property, value);
setPropertyInternal(nodeService, nodeId, property, value);
}
}

private void setPropertyInternal(String property, Serializable value) {
private static void setPropertyInternal(NodeService nodeService, String nodeId, String property, Serializable value) {
if (value == null) {
nodeService.removeProperty(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE.getProtocol(), StoreRef.STORE_REF_WORKSPACE_SPACESSTORE.getIdentifier(), this.getId(), property);
nodeService.removeProperty(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE.getProtocol(), StoreRef.STORE_REF_WORKSPACE_SPACESSTORE.getIdentifier(), nodeId, property);
} else {
nodeService.setProperty(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE.getProtocol(), StoreRef.STORE_REF_WORKSPACE_SPACESSTORE.getIdentifier(), this.getId(), property, value, false);
nodeService.setProperty(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE.getProtocol(), StoreRef.STORE_REF_WORKSPACE_SPACESSTORE.getIdentifier(), nodeId, property, value, false);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,31 +1,24 @@
package org.edu_sharing.restservices;

import java.util.List;
import java.util.stream.Collectors;

import org.alfresco.repo.security.authentication.AuthenticationUtil;
import org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork;
import org.alfresco.repo.security.permissions.AccessDeniedException;
import org.alfresco.service.cmr.security.PermissionService;
import org.apache.commons.codec.digest.DigestUtils;
import org.edu_sharing.alfresco.authentication.HttpContext;
import org.edu_sharing.alfresco.service.OrganisationService;
import org.edu_sharing.repository.client.rpc.EduGroup;
import org.edu_sharing.repository.client.tools.CCConstants;
import org.edu_sharing.repository.server.MCAlfrescoAPIClient;
import org.edu_sharing.restservices.organization.v1.model.GroupSignupDetails;
import org.edu_sharing.restservices.shared.Authority;
import org.edu_sharing.restservices.shared.GroupProfile;
import org.edu_sharing.restservices.shared.NodeRef;
import org.edu_sharing.restservices.shared.Organization;
import org.edu_sharing.restservices.shared.*;
import org.edu_sharing.service.authority.AuthorityServiceFactory;
import org.edu_sharing.service.nodeservice.NodeServiceHelper;
import org.edu_sharing.service.organization.OrganizationService;
import org.edu_sharing.service.organization.OrganizationServiceFactory;
import org.edu_sharing.service.organization.GroupSignupMethod;
import org.edu_sharing.service.search.SearchServiceFactory;
import org.edu_sharing.spring.ApplicationContextFactory;

import java.util.List;
import java.util.stream.Collectors;


public class OrganizationDao {

Expand Down Expand Up @@ -168,10 +161,11 @@ public Organization asOrganization() {
data.setAuthorityType(Authority.Type.GROUP);
data.setGroupName(groupName);
data.setAdministrationAccess(hasAdministrationAccess());
data.setSignupMethod(GroupDao.getSignupMethod(ref));

try {
data.setProfile(GroupDao.getGroup(repoDao, authorityName).asGroup().getProfile());
Group group = GroupDao.getGroup(repoDao, authorityName).asGroup();
data.setSignupMethod(group.getSignupMethod());
data.setProfile(group.getProfile());
}catch(Throwable t){
throw new RuntimeException("Error getting profile for organization "+authorityName,t);
}
Expand Down
Loading

0 comments on commit c188101

Please sign in to comment.