La limitation d'accès aux enquêtes s'appuie désormais sur la nouvelle gestion des droits :
Une enquête publique est une enquête pour laquelle le profil "Lecteur" est autorisé pour Anonymous
Une enquête privée est une enquête pour laquelle le profil "Lecteur" est exclu pour Anonymous
Exécutez le script suivant, en modifiant la valeur des variables POPULATION_ID et GROUP_DIRECTORY selon vos propres données, pour migrer vos enquêtes :
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');
// A PERSONNALISER
var POPULATION_ID = 'ametys_demo_users';
var GROUP_DIRECTORY = 'groupes-sql';
// Profil Lecteur
var readerProfile = Java.to(['READER'], "java.lang.String[]")
var query = session.getWorkspace().getQueryManager().createQuery("//element(*, ametys:survey)", javax.jcr.query.Query.XPATH);
var nodes = query.execute().getNodes();
var count = 0;
while (nodes.hasNext())
{
var node = nodes.next();
if (node.hasProperty("ametys-internal:private") && !node.hasNode('ametys-internal:acl'))
{
var property = node.getProperty("ametys-internal:private");
var isPrivate = property.getValue().getBoolean();
if (isPrivate)
{
// Get granted users and groups
var aclNode = node.addNode("ametys-internal:acl", "ametys:acl");
ConsoleHelper.setProperty(aclNode, "ametys:denied-anonymous-profiles", readerProfile );
if (node.hasProperty('ametys-internal:grantedUsers'))
{
// Migrate ACL for users
var usersProp = node.getProperty("ametys-internal:grantedUsers");
var logins = usersProp.getValues();
var usersNode = aclNode.addNode("users", "nt:unstructured");
var popNode = usersNode.addNode(POPULATION_ID, "nt:unstructured");
for (var i=0; i < logins.length; i++)
{
var userNode = popNode.addNode(logins[i].getString(), "ametys:acl-user");
ConsoleHelper.setProperty(userNode, "ametys:allowed-profiles", readerProfile);
}
usersProp.remove();
}
if (node.hasProperty('ametys-internal:grantedGroups'))
{
// Migrate ACL for groups
var groupsProp = node.getProperty("ametys-internal:grantedGroups");
var ids = groupsProp.getValues();
var groupsNode = aclNode.addNode("groups", "nt:unstructured");
var dirNode = groupsNode.addNode(GROUP_DIRECTORY, "nt:unstructured");
for (var i=0; i < ids.length; i++)
{
var gpNode = dirNode.addNode(ids[i].getString(), "ametys:acl-group");
ConsoleHelper.setProperty(gpNode, "ametys:allowed-profiles", readerProfile);
}
groupsProp.remove();
}
}
else if (!node.hasNode('ametys-internal:acl'))
{
// Set ACL for anonymous
var aclNode = node.addNode("ametys-internal:acl", "ametys:acl");
ConsoleHelper.setProperty(aclNode, "ametys:allowed-anonymous-profiles", readerProfile);
}
node.getProperty("ametys-internal:private").remove();
session.save()
count++;
}
}
print(count + " surveys have been updated");
var ConsoleHelper = Java.type('org.ametys.workspaces.repository.ConsoleHelper');
// A PERSONNALISER
var POPULATION_ID = 'ametys_demo_users';
var GROUP_DIRECTORY = 'groupes-sql';
// Profil Lecteur
var readerProfile = Java.to(['READER'], "java.lang.String[]")
var query = session.getWorkspace().getQueryManager().createQuery("//element(*, ametys:survey)", javax.jcr.query.Query.XPATH);
var nodes = query.execute().getNodes();
var count = 0;
while (nodes.hasNext())
{
var node = nodes.next();
if (node.hasProperty("ametys-internal:private") && !node.hasNode('ametys-internal:acl'))
{
var property = node.getProperty("ametys-internal:private");
var isPrivate = property.getValue().getBoolean();
if (isPrivate)
{
// Get granted users and groups
var aclNode = node.addNode("ametys-internal:acl", "ametys:acl");
ConsoleHelper.setProperty(aclNode, "ametys:denied-anonymous-profiles", readerProfile );
if (node.hasProperty('ametys-internal:grantedUsers'))
{
// Migrate ACL for users
var usersProp = node.getProperty("ametys-internal:grantedUsers");
var logins = usersProp.getValues();
var usersNode = aclNode.addNode("users", "nt:unstructured");
var popNode = usersNode.addNode(POPULATION_ID, "nt:unstructured");
for (var i=0; i < logins.length; i++)
{
var userNode = popNode.addNode(logins[i].getString(), "ametys:acl-user");
ConsoleHelper.setProperty(userNode, "ametys:allowed-profiles", readerProfile);
}
usersProp.remove();
}
if (node.hasProperty('ametys-internal:grantedGroups'))
{
// Migrate ACL for groups
var groupsProp = node.getProperty("ametys-internal:grantedGroups");
var ids = groupsProp.getValues();
var groupsNode = aclNode.addNode("groups", "nt:unstructured");
var dirNode = groupsNode.addNode(GROUP_DIRECTORY, "nt:unstructured");
for (var i=0; i < ids.length; i++)
{
var gpNode = dirNode.addNode(ids[i].getString(), "ametys:acl-group");
ConsoleHelper.setProperty(gpNode, "ametys:allowed-profiles", readerProfile);
}
groupsProp.remove();
}
}
else if (!node.hasNode('ametys-internal:acl'))
{
// Set ACL for anonymous
var aclNode = node.addNode("ametys-internal:acl", "ametys:acl");
ConsoleHelper.setProperty(aclNode, "ametys:allowed-anonymous-profiles", readerProfile);
}
node.getProperty("ametys-internal:private").remove();
session.save()
count++;
}
}
print(count + " surveys have been updated");
var ConsoleHelper = Java.type('org.ametys.workspaces.repository.ConsoleHelper');
// A PERSONNALISER
var POPULATION_ID = 'ametys_demo_users';
var GROUP_DIRECTORY = 'groupes-sql';
// Profil Lecteur
var readerProfile = Java.to(['READER'], "java.lang.String[]")
var query = session.getWorkspace().getQueryManager().createQuery("//element(*, ametys:survey)", javax.jcr.query.Query.XPATH);
var nodes = query.execute().getNodes();
var count = 0;
while (nodes.hasNext())
{
var node = nodes.next();
if (node.hasProperty("ametys-internal:private") && !node.hasNode('ametys-internal:acl'))
{
var property = node.getProperty("ametys-internal:private");
var isPrivate = property.getValue().getBoolean();
if (isPrivate)
{
// Get granted users and groups
var aclNode = node.addNode("ametys-internal:acl", "ametys:acl");
ConsoleHelper.setProperty(aclNode, "ametys:denied-anonymous-profiles", readerProfile );
if (node.hasProperty('ametys-internal:grantedUsers'))
{
// Migrate ACL for users
var usersProp = node.getProperty("ametys-internal:grantedUsers");
var logins = usersProp.getValues();
var usersNode = aclNode.addNode("users", "nt:unstructured");
var popNode = usersNode.addNode(POPULATION_ID, "nt:unstructured");
for (var i=0; i < logins.length; i++)
{
var userNode = popNode.addNode(logins[i].getString(), "ametys:acl-user");
ConsoleHelper.setProperty(userNode, "ametys:allowed-profiles", readerProfile);
}
usersProp.remove();
}
if (node.hasProperty('ametys-internal:grantedGroups'))
{
// Migrate ACL for groups
var groupsProp = node.getProperty("ametys-internal:grantedGroups");
var ids = groupsProp.getValues();
var groupsNode = aclNode.addNode("groups", "nt:unstructured");
var dirNode = groupsNode.addNode(GROUP_DIRECTORY, "nt:unstructured");
for (var i=0; i < ids.length; i++)
{
var gpNode = dirNode.addNode(ids[i].getString(), "ametys:acl-group");
ConsoleHelper.setProperty(gpNode, "ametys:allowed-profiles", readerProfile);
}
groupsProp.remove();
}
}
else if (!node.hasNode('ametys-internal:acl'))
{
// Set ACL for anonymous
var aclNode = node.addNode("ametys-internal:acl", "ametys:acl");
ConsoleHelper.setProperty(aclNode, "ametys:allowed-anonymous-profiles", readerProfile);
}
node.getProperty("ametys-internal:private").remove();
session.save()
count++;
}
}
print(count + " surveys have been updated");
Migration des tables SQL
Tout utilisateur est désormais identifié par son login et sa population.
La table SQL Survey_Session nécessite les modifications ci-après. Attention, remplacez l'identifiant de la population 'ametys_demo_users' par l'identifiant de votre propre population!
Oups !
La copie dans le presse papier a échouée. Ouvrez le code et copier-le manuellement.
ALTER TABLE Survey_Session ADD population varchar(255);
UPDATE Survey_Session SET population='ametys_demo_users' WHERE login != '';
ALTER TABLE Survey_Session ADD population varchar(255);
UPDATE Survey_Session SET population='ametys_demo_users' WHERE login != '';
ALTER TABLE Survey_Session ADD population varchar(255);
UPDATE Survey_Session SET population='ametys_demo_users' WHERE login != '';