Tout d'abord :
- Eteindre le serveur
- Supprimer le custom-nodetypes.xml
- Redémarrer le serveur
Service annuaire de lien
Le service a été migré, les paramètres sont donc typés et il faut passer le script suivant :
Oups !
La copie dans le presse papier a échouée. Ouvrez le code et copier-le manuellement.function convertStringPropertyToBoolean(node, propertyName)
{
var hasChanged = false;
if (node.hasProperty(propertyName))
{
var property = node.getProperty(propertyName);
if (property.getType() == 1) // 1 is for string
{
var valueAsString = property.getString();
property.remove();
if (valueAsString == "true" || valueAsString == "false")
{
ConsoleHelper.setProperty(node, propertyName, valueAsString == "true");
}
hasChanged = true;
}
}
return hasChanged;
}
var qm = session.getWorkspace().getQueryManager();
var query = qm.createQuery("//element(*, ametys:zoneItem)[@ametys-internal:type = 'SERVICE' and @ametys-internal:service = 'org.ametys.plugins.linkdirectory.DirectoryService']", javax.jcr.query.Query.XPATH);
var nodes = query.execute().getNodes();
var count = 0;
while (nodes.hasNext())
{
var node = nodes.nextNode().getNode("ametys:service_parameters");
var hasChanges = convertStringPropertyToBoolean(node, "ametys:displayUserLinks");
hasChanges = convertStringPropertyToBoolean(node, "ametys:configurable") || hasChanges;
hasChanges = convertStringPropertyToBoolean(node, "ametys:showUrl") || hasChanges;
hasChanges = convertStringPropertyToBoolean(node, "ametys:showThemes") || hasChanges;
if (hasChanges)
{
count++;
}
}
session.save();
print(count + " updated link directory services.");
function convertStringPropertyToBoolean(node, propertyName)
{
var hasChanged = false;
if (node.hasProperty(propertyName))
{
var property = node.getProperty(propertyName);
if (property.getType() == 1) // 1 is for string
{
var valueAsString = property.getString();
property.remove();
if (valueAsString == "true" || valueAsString == "false")
{
ConsoleHelper.setProperty(node, propertyName, valueAsString == "true");
}
hasChanged = true;
}
}
return hasChanged;
}
var qm = session.getWorkspace().getQueryManager();
var query = qm.createQuery("//element(*, ametys:zoneItem)[@ametys-internal:type = 'SERVICE' and @ametys-internal:service = 'org.ametys.plugins.linkdirectory.DirectoryService']", javax.jcr.query.Query.XPATH);
var nodes = query.execute().getNodes();
var count = 0;
while (nodes.hasNext())
{
var node = nodes.nextNode().getNode("ametys:service_parameters");
var hasChanges = convertStringPropertyToBoolean(node, "ametys:displayUserLinks");
hasChanges = convertStringPropertyToBoolean(node, "ametys:configurable") || hasChanges;
hasChanges = convertStringPropertyToBoolean(node, "ametys:showUrl") || hasChanges;
hasChanges = convertStringPropertyToBoolean(node, "ametys:showThemes") || hasChanges;
if (hasChanges)
{
count++;
}
}
session.save();
print(count + " updated link directory services.");
function convertStringPropertyToBoolean(node, propertyName)
{
var hasChanged = false;
if (node.hasProperty(propertyName))
{
var property = node.getProperty(propertyName);
if (property.getType() == 1) // 1 is for string
{
var valueAsString = property.getString();
property.remove();
if (valueAsString == "true" || valueAsString == "false")
{
ConsoleHelper.setProperty(node, propertyName, valueAsString == "true");
}
hasChanged = true;
}
}
return hasChanged;
}
var qm = session.getWorkspace().getQueryManager();
var query = qm.createQuery("//element(*, ametys:zoneItem)[@ametys-internal:type = 'SERVICE' and @ametys-internal:service = 'org.ametys.plugins.linkdirectory.DirectoryService']", javax.jcr.query.Query.XPATH);
var nodes = query.execute().getNodes();
var count = 0;
while (nodes.hasNext())
{
var node = nodes.nextNode().getNode("ametys:service_parameters");
var hasChanges = convertStringPropertyToBoolean(node, "ametys:displayUserLinks");
hasChanges = convertStringPropertyToBoolean(node, "ametys:configurable") || hasChanges;
hasChanges = convertStringPropertyToBoolean(node, "ametys:showUrl") || hasChanges;
hasChanges = convertStringPropertyToBoolean(node, "ametys:showThemes") || hasChanges;
if (hasChanges)
{
count++;
}
}
session.save();
print(count + " updated link directory services.");
Reconstruire le workspace Live pour appliquer ces modifications aux pages publiées.
Limitation d'accès
La limitation d'accès aux liens s'appuie désormais sur la nouvelle gestion des droits :
- Un lien public est un lien pour laquelle le profil "Lecteur" est autorisé pour Anonymous
- Un lien privé est un lien pour laquelle le profil "Lecteur" est exclu pour Anonymous
Exécutez le script suivant pour migrer vos liens :
Oups !
La copie dans le presse papier a échouée. Ouvrez le code et copier-le manuellement.var ConsoleHelper = Java.type('org.ametys.workspaces.repository.ConsoleHelper');
// Profil Lecteur
var readerProfile = Java.to(['READER'], "java.lang.String[]")
var query = session.getWorkspace().getQueryManager().createQuery("//element(*, ametys:directoryLink)", javax.jcr.query.Query.XPATH);
var nodes = query.execute().getNodes();
var count = 0;
while (nodes.hasNext())
{
var node = nodes.next();
var hasChanged = false;
if (!node.hasProperty("ametys-internal:status"))
{
node.setProperty("ametys-internal:status", "NORMAL");
hasChanged = true;
}
if (!node.hasNode('ametys-internal:acl'))
{
var aclNode = node.addNode("ametys-internal:acl", "ametys:acl");
var grantAnyUser = node.hasProperty("ametys-internal:grant-any-user") ? node.getProperty("ametys-internal:grant-any-user").getBoolean() : false;
if (grantAnyUser)
{
ConsoleHelper.setProperty(aclNode, "ametys:denied-anonymous-profiles", readerProfile );
}
else
{
// Set ACL for anonymous
ConsoleHelper.setProperty(aclNode, "ametys:allowed-anonymous-profiles", readerProfile);
ConsoleHelper.setProperty(aclNode, "ametys:allowed-any-connected-profiles", readerProfile);
}
if (node.hasProperty("ametys-internal:grant-any-user"))
{
node.getProperty("ametys-internal:grant-any-user").remove();
}
if (node.hasNode('ametys-internal:granted-users'))
{
// Migrate ACL for users
var parentNode = node.getNode("ametys-internal:granted-users");
var usersNode = aclNode.addNode("users", "nt:unstructured");
var oldUsersNodes = parentNode.getNodes();
while (oldUsersNodes.hasNext())
{
var oldUserNode = oldUsersNodes.next();
var userPopulation = oldUserNode.getProperty("ametys:population").getString();
if (!usersNode.hasNode(userPopulation))
{
usersNode.addNode(userPopulation, "nt:unstructured");
}
var popNode = usersNode.getNode(userPopulation);
var login = oldUserNode.getProperty("ametys:login").getString();
var userNode = popNode.addNode(login, "ametys:acl-user");
ConsoleHelper.setProperty(userNode, "ametys:allowed-profiles", readerProfile);
}
parentNode.remove();
}
if (node.hasNode('ametys-internal:granted-groups'))
{
// Migrate ACL for groups
var parentNode = node.getNode("ametys-internal:granted-groups");
var groupsNode = aclNode.addNode("groups", "nt:unstructured");
var oldGroupsNodes = parentNode.getNodes();
while (oldGroupsNodes.hasNext())
{
var oldGroupNode = oldGroupsNodes.next();
var groupDirectory = oldGroupNode.getProperty("ametys:groupDirectory").getString();
if (!groupsNode.hasNode(groupDirectory))
{
groupsNode.addNode(groupDirectory, "nt:unstructured");
}
var dirNode = groupsNode.getNode(groupDirectory);
var groupId = oldGroupNode.getProperty("ametys:groupId").getString();
var gpNode = dirNode.addNode(groupId, "ametys:acl-group");
ConsoleHelper.setProperty(gpNode, "ametys:allowed-profiles", readerProfile);
}
parentNode.remove();
}
hasChanged = true;
}
if (hasChanged)
{
session.save();
count++;
}
}
print(count + " links have been updated");
var ConsoleHelper = Java.type('org.ametys.workspaces.repository.ConsoleHelper');
// Profil Lecteur
var readerProfile = Java.to(['READER'], "java.lang.String[]")
var query = session.getWorkspace().getQueryManager().createQuery("//element(*, ametys:directoryLink)", javax.jcr.query.Query.XPATH);
var nodes = query.execute().getNodes();
var count = 0;
while (nodes.hasNext())
{
var node = nodes.next();
var hasChanged = false;
if (!node.hasProperty("ametys-internal:status"))
{
node.setProperty("ametys-internal:status", "NORMAL");
hasChanged = true;
}
if (!node.hasNode('ametys-internal:acl'))
{
var aclNode = node.addNode("ametys-internal:acl", "ametys:acl");
var grantAnyUser = node.hasProperty("ametys-internal:grant-any-user") ? node.getProperty("ametys-internal:grant-any-user").getBoolean() : false;
if (grantAnyUser)
{
ConsoleHelper.setProperty(aclNode, "ametys:denied-anonymous-profiles", readerProfile );
}
else
{
// Set ACL for anonymous
ConsoleHelper.setProperty(aclNode, "ametys:allowed-anonymous-profiles", readerProfile);
ConsoleHelper.setProperty(aclNode, "ametys:allowed-any-connected-profiles", readerProfile);
}
if (node.hasProperty("ametys-internal:grant-any-user"))
{
node.getProperty("ametys-internal:grant-any-user").remove();
}
if (node.hasNode('ametys-internal:granted-users'))
{
// Migrate ACL for users
var parentNode = node.getNode("ametys-internal:granted-users");
var usersNode = aclNode.addNode("users", "nt:unstructured");
var oldUsersNodes = parentNode.getNodes();
while (oldUsersNodes.hasNext())
{
var oldUserNode = oldUsersNodes.next();
var userPopulation = oldUserNode.getProperty("ametys:population").getString();
if (!usersNode.hasNode(userPopulation))
{
usersNode.addNode(userPopulation, "nt:unstructured");
}
var popNode = usersNode.getNode(userPopulation);
var login = oldUserNode.getProperty("ametys:login").getString();
var userNode = popNode.addNode(login, "ametys:acl-user");
ConsoleHelper.setProperty(userNode, "ametys:allowed-profiles", readerProfile);
}
parentNode.remove();
}
if (node.hasNode('ametys-internal:granted-groups'))
{
// Migrate ACL for groups
var parentNode = node.getNode("ametys-internal:granted-groups");
var groupsNode = aclNode.addNode("groups", "nt:unstructured");
var oldGroupsNodes = parentNode.getNodes();
while (oldGroupsNodes.hasNext())
{
var oldGroupNode = oldGroupsNodes.next();
var groupDirectory = oldGroupNode.getProperty("ametys:groupDirectory").getString();
if (!groupsNode.hasNode(groupDirectory))
{
groupsNode.addNode(groupDirectory, "nt:unstructured");
}
var dirNode = groupsNode.getNode(groupDirectory);
var groupId = oldGroupNode.getProperty("ametys:groupId").getString();
var gpNode = dirNode.addNode(groupId, "ametys:acl-group");
ConsoleHelper.setProperty(gpNode, "ametys:allowed-profiles", readerProfile);
}
parentNode.remove();
}
hasChanged = true;
}
if (hasChanged)
{
session.save();
count++;
}
}
print(count + " links have been updated");
var ConsoleHelper = Java.type('org.ametys.workspaces.repository.ConsoleHelper');
// Profil Lecteur
var readerProfile = Java.to(['READER'], "java.lang.String[]")
var query = session.getWorkspace().getQueryManager().createQuery("//element(*, ametys:directoryLink)", javax.jcr.query.Query.XPATH);
var nodes = query.execute().getNodes();
var count = 0;
while (nodes.hasNext())
{
var node = nodes.next();
var hasChanged = false;
if (!node.hasProperty("ametys-internal:status"))
{
node.setProperty("ametys-internal:status", "NORMAL");
hasChanged = true;
}
if (!node.hasNode('ametys-internal:acl'))
{
var aclNode = node.addNode("ametys-internal:acl", "ametys:acl");
var grantAnyUser = node.hasProperty("ametys-internal:grant-any-user") ? node.getProperty("ametys-internal:grant-any-user").getBoolean() : false;
if (grantAnyUser)
{
ConsoleHelper.setProperty(aclNode, "ametys:denied-anonymous-profiles", readerProfile );
}
else
{
// Set ACL for anonymous
ConsoleHelper.setProperty(aclNode, "ametys:allowed-anonymous-profiles", readerProfile);
ConsoleHelper.setProperty(aclNode, "ametys:allowed-any-connected-profiles", readerProfile);
}
if (node.hasProperty("ametys-internal:grant-any-user"))
{
node.getProperty("ametys-internal:grant-any-user").remove();
}
if (node.hasNode('ametys-internal:granted-users'))
{
// Migrate ACL for users
var parentNode = node.getNode("ametys-internal:granted-users");
var usersNode = aclNode.addNode("users", "nt:unstructured");
var oldUsersNodes = parentNode.getNodes();
while (oldUsersNodes.hasNext())
{
var oldUserNode = oldUsersNodes.next();
var userPopulation = oldUserNode.getProperty("ametys:population").getString();
if (!usersNode.hasNode(userPopulation))
{
usersNode.addNode(userPopulation, "nt:unstructured");
}
var popNode = usersNode.getNode(userPopulation);
var login = oldUserNode.getProperty("ametys:login").getString();
var userNode = popNode.addNode(login, "ametys:acl-user");
ConsoleHelper.setProperty(userNode, "ametys:allowed-profiles", readerProfile);
}
parentNode.remove();
}
if (node.hasNode('ametys-internal:granted-groups'))
{
// Migrate ACL for groups
var parentNode = node.getNode("ametys-internal:granted-groups");
var groupsNode = aclNode.addNode("groups", "nt:unstructured");
var oldGroupsNodes = parentNode.getNodes();
while (oldGroupsNodes.hasNext())
{
var oldGroupNode = oldGroupsNodes.next();
var groupDirectory = oldGroupNode.getProperty("ametys:groupDirectory").getString();
if (!groupsNode.hasNode(groupDirectory))
{
groupsNode.addNode(groupDirectory, "nt:unstructured");
}
var dirNode = groupsNode.getNode(groupDirectory);
var groupId = oldGroupNode.getProperty("ametys:groupId").getString();
var gpNode = dirNode.addNode(groupId, "ametys:acl-group");
ConsoleHelper.setProperty(gpNode, "ametys:allowed-profiles", readerProfile);
}
parentNode.remove();
}
hasChanged = true;
}
if (hasChanged)
{
session.save();
count++;
}
}
print(count + " links have been updated");