Restrictions on access to surveys are now based on the new rights management system:
A public survey is a survey for which the "Reader" profile is authorized for Anonymous.
A private investigation is one for which the "Reader" profile is excluded for Anonymous.
Run the following script , modifying the value of the variables POPULATION_ID and GROUP_DIRECTORY according to your own data, to migrate your surveys:
Oops!
Copy to clipboard failed. Open the code and copy it manually.
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");
Table migration SQL
All users are now identified by their login and population.
The SQL Survey_Session table requires the following modifications. Please replace the population ID 'ametys_demo_users' with your own population ID!
Oops!
Copy to clipboard failed. Open the code and copy it manually.
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 != '';