Skip to content
Snippets Groups Projects
Commit 8cf6ffeb authored by srosse's avatar srosse
Browse files

OO-1205: fix the upgrader for rights

parent 14a04bd4
No related branches found
No related tags found
No related merge requests found
...@@ -148,7 +148,7 @@ public class GroupsAndRightsController extends FormBasicController { ...@@ -148,7 +148,7 @@ public class GroupsAndRightsController extends FormBasicController {
private MultipleSelectionElement createSelection(boolean selected) { private MultipleSelectionElement createSelection(boolean selected) {
String name = "cb" + UUID.randomUUID().toString().replace("-", ""); String name = "cb" + UUID.randomUUID().toString().replace("-", "");
MultipleSelectionElement selection = new MultipleSelectionElementImpl(name, Layout.vertical); MultipleSelectionElement selection = new MultipleSelectionElementImpl(name, Layout.horizontal);
selection.setKeysAndValues(keys, values); selection.setKeysAndValues(keys, values);
flc.add(name, selection); flc.add(name, selection);
selection.select(keys[0], selected); selection.select(keys[0], selected);
......
...@@ -21,7 +21,6 @@ package org.olat.upgrade; ...@@ -21,7 +21,6 @@ package org.olat.upgrade;
import java.io.File; import java.io.File;
import java.nio.file.Paths; import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Date; import java.util.Date;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
...@@ -46,7 +45,6 @@ import org.olat.core.util.WebappHelper; ...@@ -46,7 +45,6 @@ import org.olat.core.util.WebappHelper;
import org.olat.group.BusinessGroupService; import org.olat.group.BusinessGroupService;
import org.olat.group.manager.BusinessGroupRelationDAO; import org.olat.group.manager.BusinessGroupRelationDAO;
import org.olat.group.right.BGRightManager; import org.olat.group.right.BGRightManager;
import org.olat.group.right.BGRightsRole;
import org.olat.portfolio.manager.EPMapPolicy; import org.olat.portfolio.manager.EPMapPolicy;
import org.olat.properties.Property; import org.olat.properties.Property;
import org.olat.properties.PropertyManager; import org.olat.properties.PropertyManager;
...@@ -195,8 +193,7 @@ public class OLATUpgrade_10_0_0 extends OLATUpgrade { ...@@ -195,8 +193,7 @@ public class OLATUpgrade_10_0_0 extends OLATUpgrade {
do { do {
businessGroups = findBusinessGroups(counter, BATCH_SIZE); businessGroups = findBusinessGroups(counter, BATCH_SIZE);
for(BusinessGroupUpgrade businessGroup:businessGroups) { for(BusinessGroupUpgrade businessGroup:businessGroups) {
BusinessGroupUpgrade up = processBusinessGroup(businessGroup); processBusinessGroup(businessGroup);
processRightGroup(up);
} }
counter += businessGroups.size(); counter += businessGroups.size();
log.audit("Business groups processed: " + businessGroups.size() + ", total processed (" + counter + ")"); log.audit("Business groups processed: " + businessGroups.size() + ", total processed (" + counter + ")");
...@@ -230,38 +227,6 @@ public class OLATUpgrade_10_0_0 extends OLATUpgrade { ...@@ -230,38 +227,6 @@ public class OLATUpgrade_10_0_0 extends OLATUpgrade {
dbInstance.commit(); dbInstance.commit();
return businessGroup; return businessGroup;
} }
private void processRightGroup(BusinessGroupUpgrade businessGroup) {
boolean commit = false;
List<String> tutorRights = findBGRights(businessGroup.getOwnerGroup());
for(String right:tutorRights) {
bgRightManager.addBGRight(right, businessGroup, BGRightsRole.tutor);
commit = true;
}
List<String> participantsRights = findBGRights(businessGroup.getPartipiciantGroup());
for(String right:participantsRights) {
bgRightManager.addBGRight(right, businessGroup, BGRightsRole.participant);
commit = true;
}
if(commit) {
dbInstance.commit();
}
}
private List<String> findBGRights(SecurityGroup secGroup) {
List<Policy> results = securityManager.getPoliciesOfSecurityGroup(secGroup);
// filter all business group rights permissions. group right permissions
// start with bgr.
List<String> rights = new ArrayList<String>();
for (Policy rightPolicy:results) {
String right = rightPolicy.getPermission();
if (right.indexOf("bgr.") == 0) rights.add(right);
}
return rights;
}
private boolean upgradeRepositoryEntries(UpgradeManager upgradeManager, UpgradeHistoryData uhd) { private boolean upgradeRepositoryEntries(UpgradeManager upgradeManager, UpgradeHistoryData uhd) {
if (!uhd.getBooleanDataValue(TASK_REPOENTRIES)) { if (!uhd.getBooleanDataValue(TASK_REPOENTRIES)) {
......
/**
* <a href="http://www.openolat.org">
* OpenOLAT - Online Learning and Training</a><br>
* <p>
* Licensed under the Apache License, Version 2.0 (the "License"); <br>
* you may not use this file except in compliance with the License.<br>
* You may obtain a copy of the License at the
* <a href="http://www.apache.org/licenses/LICENSE-2.0">Apache homepage</a>
* <p>
* Unless required by applicable law or agreed to in writing,<br>
* software distributed under the License is distributed on an "AS IS" BASIS, <br>
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. <br>
* See the License for the specific language governing permissions and <br>
* limitations under the License.
* <p>
* Initial code contributed and copyrighted by<br>
* frentix GmbH, http://www.frentix.com
* <p>
*/
package org.olat.upgrade;
import java.util.ArrayList;
import java.util.List;
import org.olat.admin.layout.LayoutModule;
import org.olat.basesecurity.BaseSecurity;
import org.olat.basesecurity.Policy;
import org.olat.basesecurity.SecurityGroup;
import org.olat.basesecurity.manager.GroupDAO;
import org.olat.core.commons.persistence.DB;
import org.olat.group.BusinessGroupService;
import org.olat.group.manager.BusinessGroupRelationDAO;
import org.olat.group.right.BGRightManager;
import org.olat.group.right.BGRightsRole;
import org.olat.properties.PropertyManager;
import org.olat.repository.RepositoryManager;
import org.olat.repository.manager.RepositoryEntryRelationDAO;
import org.olat.upgrade.model.BusinessGroupUpgrade;
import org.springframework.beans.factory.annotation.Autowired;
/**
*
* Initial date: 27.02.2014<br>
* @author srosse, stephane.rosse@frentix.com, http://www.frentix.com
*
*/
public class OLATUpgrade_10_0_3 extends OLATUpgrade {
private static final int BATCH_SIZE = 50;
private static final String TASK_BUSINESS_GROUPS = "Upgrade rights groups";
private static final String VERSION = "OLAT_10.0.3";
@Autowired
private DB dbInstance;
@Autowired
private BaseSecurity securityManager;
@Autowired
private GroupDAO groupDao;
@Autowired
private RepositoryManager repositoryManager;
@Autowired
private BGRightManager bgRightManager;
@Autowired
private BusinessGroupRelationDAO businessGroupRelationDao;
@Autowired
private RepositoryEntryRelationDAO repositoryEntryToGroupDAO;
@Autowired
private BusinessGroupService businessGroupService;
@Autowired
private PropertyManager propertyManager;
@Autowired
private LayoutModule layoutModule;
public OLATUpgrade_10_0_3() {
super();
}
@Override
public String getVersion() {
return VERSION;
}
@Override
public boolean doPreSystemInitUpgrade(UpgradeManager upgradeManager) {
return false;
}
@Override
public boolean doPostSystemInitUpgrade(UpgradeManager upgradeManager) {
UpgradeHistoryData uhd = upgradeManager.getUpgradesHistory(VERSION);
if (uhd == null) {
// has never been called, initialize
uhd = new UpgradeHistoryData();
} else if (uhd.isInstallationComplete()) {
return false;
}
boolean allOk = true;
allOk &= upgradeBusinessGroups(upgradeManager, uhd);
uhd.setInstallationComplete(allOk);
upgradeManager.setUpgradesHistory(uhd, VERSION);
if(allOk) {
log.audit("Finished OLATUpgrade_10_0_3 successfully!");
} else {
log.audit("OLATUpgrade_10_0_3 not finished, try to restart OpenOLAT!");
}
return allOk;
}
private boolean upgradeBusinessGroups(UpgradeManager upgradeManager, UpgradeHistoryData uhd) {
if (!uhd.getBooleanDataValue(TASK_BUSINESS_GROUPS)) {
int counter = 0;
List<BusinessGroupUpgrade> businessGroups;
do {
businessGroups = findBusinessGroups(counter, BATCH_SIZE);
for(BusinessGroupUpgrade businessGroup:businessGroups) {
processRightGroup(businessGroup);
}
counter += businessGroups.size();
log.audit("Rights groups processed: " + businessGroups.size() + ", total processed (" + counter + ")");
dbInstance.commitAndCloseSession();
} while(businessGroups.size() == BATCH_SIZE);
uhd.setBooleanDataValue(TASK_BUSINESS_GROUPS, true);
upgradeManager.setUpgradesHistory(uhd, VERSION);
}
return true;
}
private void processRightGroup(BusinessGroupUpgrade businessGroup) {
boolean commit = false;
List<String> tutorRights = findBGRights(businessGroup.getOwnerGroup());
List<String> currentTutorRights = bgRightManager.findBGRights(businessGroup, BGRightsRole.tutor);
tutorRights.removeAll(currentTutorRights);
for(String right:tutorRights) {
bgRightManager.addBGRight(right, businessGroup, BGRightsRole.tutor);
commit = true;
}
List<String> participantsRights = findBGRights(businessGroup.getPartipiciantGroup());
List<String> currentParticipantsRights = bgRightManager.findBGRights(businessGroup, BGRightsRole.participant);
participantsRights.removeAll(currentParticipantsRights);
for(String right:participantsRights) {
bgRightManager.addBGRight(right, businessGroup, BGRightsRole.participant);
commit = true;
}
if(commit) {
dbInstance.commit();
}
}
private List<String> findBGRights(SecurityGroup secGroup) {
List<Policy> results = securityManager.getPoliciesOfSecurityGroup(secGroup);
// filter all business group rights permissions. group right permissions
// start with bgr.
List<String> rights = new ArrayList<String>();
for (Policy rightPolicy:results) {
String right = rightPolicy.getPermission();
if (right.indexOf("bgr.") == 0) rights.add(right);
}
return rights;
}
private List<BusinessGroupUpgrade> findBusinessGroups(int firstResult, int maxResults) {
StringBuilder sb = new StringBuilder();
sb.append("select businessgroup from ").append(BusinessGroupUpgrade.class.getName()).append(" businessgroup")
.append(" left join fetch businessgroup.baseGroup as baseGroup")
.append(" left join fetch businessgroup.ownerGroup as ownerGroup")
.append(" left join fetch businessgroup.partipiciantGroup as partipiciantGroup")
.append(" left join fetch businessgroup.waitingGroup as waitingGroup")
.append(" left join fetch businessgroup.resource as resource")
.append(" order by businessgroup.key");
return dbInstance.getCurrentEntityManager().createQuery(sb.toString(), BusinessGroupUpgrade.class)
.setFirstResult(firstResult)
.setMaxResults(maxResults)
.getResultList();
}
}
...@@ -41,6 +41,7 @@ ...@@ -41,6 +41,7 @@
<bean id="upgrade_9_0_0" class="org.olat.upgrade.OLATUpgrade_9_0_0"/> <bean id="upgrade_9_0_0" class="org.olat.upgrade.OLATUpgrade_9_0_0"/>
<bean id="upgrade_9_4_0" class="org.olat.upgrade.OLATUpgrade_9_4_0"/> <bean id="upgrade_9_4_0" class="org.olat.upgrade.OLATUpgrade_9_4_0"/>
<bean id="upgrade_10_0_0" class="org.olat.upgrade.OLATUpgrade_10_0_0"/> <bean id="upgrade_10_0_0" class="org.olat.upgrade.OLATUpgrade_10_0_0"/>
<bean id="upgrade_10_0_3" class="org.olat.upgrade.OLATUpgrade_10_0_3"/>
</list> </list>
</property> </property>
</bean> </bean>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment