Dernière publication:06/04/2018à 07:03LaurenceAumeunier
Ajouts des groupes en tant que membre
Suite à l'ajout des groupes en tant que membre, il est nécessaire de migrer les droits des espaces projets pour éviter les problèmes causés par l'ancien stockage :
Oups !
La copie dans le presse papier a échouée. Ouvrez le code et copier-le manuellement.
var _projectManager = serviceManager.lookup("org.ametys.plugins.workspaces.project.ProjectManager");
var _profileAssignmentStorageEP = serviceManager.lookup("org.ametys.core.right.ProfileAssignmentStorageExtensionPoint");
var _observationManager = serviceManager.lookup("org.ametys.core.observation.ObservationManager");
var _currentUserProvider = serviceManager.lookup("org.ametys.core.user.CurrentUserProvider");
function run()
{
for each (var project in _projectManager.getProjects())
{
var updated = false;
for each (var site in project.getSites())
{
for each (var sitemap in site.getSitemaps())
{
var sitemapAllowedUsers = _profileAssignmentStorageEP.getAllowedUsers(sitemap, "READER");
var dashboardPages = _projectManager.getProjectDashboardPage(project, sitemap.getSitemapName());
// Set the READER profile to all user that have the right on the sitemap
updated = updateDashboardPage(dashboardPages, sitemapAllowedUsers) || updated;
// Set the READER profile for the manager on all module pages
// And remove any denied READER profile on all module pages
updated = updateProjectModules(project, sitemap) || updated;
// remove READER profile on the Sitemap
// And remove any denied READER profile on sitemap
updated = updateSitemap(sitemap) || updated;
if (updated)
{
_observationManager.notify(new org.ametys.core.observation.Event(org.ametys.core.ObservationConstants.EVENT_ACL_UPDATED, _currentUserProvider.getUser(), {
"acl-context": sitemap,
"acl-context-identifier": sitemap.getId()
}));
}
}
}
if (updated)
{
print("Projet '" + project.getTitle() + "' mis à jour");
}
}
}
function updateDashboardPage(dashboardPages, sitemapAllowedUsers)
{
var updated = false;
for each (var dashboardPage in dashboardPages)
{
for each (var sitemapAllowedUser in sitemapAllowedUsers)
{
if (!_profileAssignmentStorageEP.getAllowedProfilesForUser(dashboardPage, sitemapAllowedUser).contains("READER"))
{
_profileAssignmentStorageEP.allowProfileToUser(sitemapAllowedUser, "READER", dashboardPage);
updated = true;
}
}
}
return updated;
}
function updateProjectModules(project, sitemap)
{
var updated = false;
var manager = project.getManager();
for each (var projectModule in _projectManager.getModules(project))
{
for each (var modulePage in projectModule.getModulePages(project, sitemap.getSitemapName()))
{
if (!_profileAssignmentStorageEP.getAllowedProfilesForUser(modulePage, manager).contains("READER"))
{
updated = true;
_profileAssignmentStorageEP.allowProfileToUser(manager, "READER", modulePage);
}
updated = removeNegativeProfile(modulePage, "READER") || updated;
}
var moduleRootNode = projectModule.getModuleRoot(project, false);
updated = removeNegativeProfile(moduleRootNode, "READER") || updated;
}
return updated;
}
function updateSitemap(sitemap)
{
var updated = false;
updated = removeProfile(sitemap, "READER") || updated;
updated = removeNegativeProfile(sitemap, "READER") || updated;
return updated;
}
function removeProfile(target, profile)
{
var updated = false;
var allowedProfiles = _profileAssignmentStorageEP.getAllowedProfilesForUsers(target);
for each (var allowedUser in allowedProfiles.keySet())
{
if (allowedProfiles.get(allowedUser).contains(profile))
{
updated = true;
_profileAssignmentStorageEP.removeAllowedProfileFromUser(allowedUser, profile, target);
}
}
return updated;
}
function removeNegativeProfile(target, profile)
{
var updated = false;
var deniedProfiles = _profileAssignmentStorageEP.getDeniedProfilesForUsers(target);
for each (var deniedUser in deniedProfiles.keySet())
{
if (deniedProfiles.get(deniedUser).contains(profile))
{
updated = true;
_profileAssignmentStorageEP.removeDeniedProfileFromUser(deniedUser, profile, target);
}
}
return updated;
}
run();
var _projectManager = serviceManager.lookup("org.ametys.plugins.workspaces.project.ProjectManager");
var _profileAssignmentStorageEP = serviceManager.lookup("org.ametys.core.right.ProfileAssignmentStorageExtensionPoint");
var _observationManager = serviceManager.lookup("org.ametys.core.observation.ObservationManager");
var _currentUserProvider = serviceManager.lookup("org.ametys.core.user.CurrentUserProvider");
function run()
{
for each (var project in _projectManager.getProjects())
{
var updated = false;
for each (var site in project.getSites())
{
for each (var sitemap in site.getSitemaps())
{
var sitemapAllowedUsers = _profileAssignmentStorageEP.getAllowedUsers(sitemap, "READER");
var dashboardPages = _projectManager.getProjectDashboardPage(project, sitemap.getSitemapName());
// Set the READER profile to all user that have the right on the sitemap
updated = updateDashboardPage(dashboardPages, sitemapAllowedUsers) || updated;
// Set the READER profile for the manager on all module pages
// And remove any denied READER profile on all module pages
updated = updateProjectModules(project, sitemap) || updated;
// remove READER profile on the Sitemap
// And remove any denied READER profile on sitemap
updated = updateSitemap(sitemap) || updated;
if (updated)
{
_observationManager.notify(new org.ametys.core.observation.Event(org.ametys.core.ObservationConstants.EVENT_ACL_UPDATED, _currentUserProvider.getUser(), {
"acl-context": sitemap,
"acl-context-identifier": sitemap.getId()
}));
}
}
}
if (updated)
{
print("Projet '" + project.getTitle() + "' mis à jour");
}
}
}
function updateDashboardPage(dashboardPages, sitemapAllowedUsers)
{
var updated = false;
for each (var dashboardPage in dashboardPages)
{
for each (var sitemapAllowedUser in sitemapAllowedUsers)
{
if (!_profileAssignmentStorageEP.getAllowedProfilesForUser(dashboardPage, sitemapAllowedUser).contains("READER"))
{
_profileAssignmentStorageEP.allowProfileToUser(sitemapAllowedUser, "READER", dashboardPage);
updated = true;
}
}
}
return updated;
}
function updateProjectModules(project, sitemap)
{
var updated = false;
var manager = project.getManager();
for each (var projectModule in _projectManager.getModules(project))
{
for each (var modulePage in projectModule.getModulePages(project, sitemap.getSitemapName()))
{
if (!_profileAssignmentStorageEP.getAllowedProfilesForUser(modulePage, manager).contains("READER"))
{
updated = true;
_profileAssignmentStorageEP.allowProfileToUser(manager, "READER", modulePage);
}
updated = removeNegativeProfile(modulePage, "READER") || updated;
}
var moduleRootNode = projectModule.getModuleRoot(project, false);
updated = removeNegativeProfile(moduleRootNode, "READER") || updated;
}
return updated;
}
function updateSitemap(sitemap)
{
var updated = false;
updated = removeProfile(sitemap, "READER") || updated;
updated = removeNegativeProfile(sitemap, "READER") || updated;
return updated;
}
function removeProfile(target, profile)
{
var updated = false;
var allowedProfiles = _profileAssignmentStorageEP.getAllowedProfilesForUsers(target);
for each (var allowedUser in allowedProfiles.keySet())
{
if (allowedProfiles.get(allowedUser).contains(profile))
{
updated = true;
_profileAssignmentStorageEP.removeAllowedProfileFromUser(allowedUser, profile, target);
}
}
return updated;
}
function removeNegativeProfile(target, profile)
{
var updated = false;
var deniedProfiles = _profileAssignmentStorageEP.getDeniedProfilesForUsers(target);
for each (var deniedUser in deniedProfiles.keySet())
{
if (deniedProfiles.get(deniedUser).contains(profile))
{
updated = true;
_profileAssignmentStorageEP.removeDeniedProfileFromUser(deniedUser, profile, target);
}
}
return updated;
}
run();
var _projectManager = serviceManager.lookup("org.ametys.plugins.workspaces.project.ProjectManager");
var _profileAssignmentStorageEP = serviceManager.lookup("org.ametys.core.right.ProfileAssignmentStorageExtensionPoint");
var _observationManager = serviceManager.lookup("org.ametys.core.observation.ObservationManager");
var _currentUserProvider = serviceManager.lookup("org.ametys.core.user.CurrentUserProvider");
function run()
{
for each (var project in _projectManager.getProjects())
{
var updated = false;
for each (var site in project.getSites())
{
for each (var sitemap in site.getSitemaps())
{
var sitemapAllowedUsers = _profileAssignmentStorageEP.getAllowedUsers(sitemap, "READER");
var dashboardPages = _projectManager.getProjectDashboardPage(project, sitemap.getSitemapName());
// Set the READER profile to all user that have the right on the sitemap
updated = updateDashboardPage(dashboardPages, sitemapAllowedUsers) || updated;
// Set the READER profile for the manager on all module pages
// And remove any denied READER profile on all module pages
updated = updateProjectModules(project, sitemap) || updated;
// remove READER profile on the Sitemap
// And remove any denied READER profile on sitemap
updated = updateSitemap(sitemap) || updated;
if (updated)
{
_observationManager.notify(new org.ametys.core.observation.Event(org.ametys.core.ObservationConstants.EVENT_ACL_UPDATED, _currentUserProvider.getUser(), {
"acl-context": sitemap,
"acl-context-identifier": sitemap.getId()
}));
}
}
}
if (updated)
{
print("Projet '" + project.getTitle() + "' mis à jour");
}
}
}
function updateDashboardPage(dashboardPages, sitemapAllowedUsers)
{
var updated = false;
for each (var dashboardPage in dashboardPages)
{
for each (var sitemapAllowedUser in sitemapAllowedUsers)
{
if (!_profileAssignmentStorageEP.getAllowedProfilesForUser(dashboardPage, sitemapAllowedUser).contains("READER"))
{
_profileAssignmentStorageEP.allowProfileToUser(sitemapAllowedUser, "READER", dashboardPage);
updated = true;
}
}
}
return updated;
}
function updateProjectModules(project, sitemap)
{
var updated = false;
var manager = project.getManager();
for each (var projectModule in _projectManager.getModules(project))
{
for each (var modulePage in projectModule.getModulePages(project, sitemap.getSitemapName()))
{
if (!_profileAssignmentStorageEP.getAllowedProfilesForUser(modulePage, manager).contains("READER"))
{
updated = true;
_profileAssignmentStorageEP.allowProfileToUser(manager, "READER", modulePage);
}
updated = removeNegativeProfile(modulePage, "READER") || updated;
}
var moduleRootNode = projectModule.getModuleRoot(project, false);
updated = removeNegativeProfile(moduleRootNode, "READER") || updated;
}
return updated;
}
function updateSitemap(sitemap)
{
var updated = false;
updated = removeProfile(sitemap, "READER") || updated;
updated = removeNegativeProfile(sitemap, "READER") || updated;
return updated;
}
function removeProfile(target, profile)
{
var updated = false;
var allowedProfiles = _profileAssignmentStorageEP.getAllowedProfilesForUsers(target);
for each (var allowedUser in allowedProfiles.keySet())
{
if (allowedProfiles.get(allowedUser).contains(profile))
{
updated = true;
_profileAssignmentStorageEP.removeAllowedProfileFromUser(allowedUser, profile, target);
}
}
return updated;
}
function removeNegativeProfile(target, profile)
{
var updated = false;
var deniedProfiles = _profileAssignmentStorageEP.getDeniedProfilesForUsers(target);
for each (var deniedUser in deniedProfiles.keySet())
{
if (deniedProfiles.get(deniedUser).contains(profile))
{
updated = true;
_profileAssignmentStorageEP.removeDeniedProfileFromUser(deniedUser, profile, target);
}
}
return updated;
}
run();