diff --git a/src/main/java/org/olat/basesecurity/IdentityRelationshipService.java b/src/main/java/org/olat/basesecurity/IdentityRelationshipService.java index 7d6a660f994a775c1981f2fff0dbd90713c0b6ce..420bb11324c3571e4a9db3479c1f8a86d74889ca 100644 --- a/src/main/java/org/olat/basesecurity/IdentityRelationshipService.java +++ b/src/main/java/org/olat/basesecurity/IdentityRelationshipService.java @@ -20,6 +20,7 @@ package org.olat.basesecurity; import java.util.List; +import java.util.Locale; import org.olat.core.id.Identity; @@ -46,6 +47,8 @@ public interface IdentityRelationshipService { public List<RelationRight> getAvailableRights(); + public String getTranslatedName(RelationRight right, Locale locale); + public boolean isInUse(RelationRole relationRole); public void deleteRole(RelationRole role); diff --git a/src/main/java/org/olat/basesecurity/RelationRightProvider.java b/src/main/java/org/olat/basesecurity/RelationRightProvider.java new file mode 100644 index 0000000000000000000000000000000000000000..9fb698cb51fadcd0b49978f7a2451deeea73b2cd --- /dev/null +++ b/src/main/java/org/olat/basesecurity/RelationRightProvider.java @@ -0,0 +1,36 @@ +/** + * <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.basesecurity; + +import java.util.Locale; + +/** + * + * Initial date: 19 Feb 2019<br> + * @author uhensler, urs.hensler@frentix.com, http://www.frentix.com + * + */ +public interface RelationRightProvider { + + public String getRight(); + + public String getTranslatedName(Locale locale); + +} diff --git a/src/main/java/org/olat/basesecurity/manager/IdentityRelationshipServiceImpl.java b/src/main/java/org/olat/basesecurity/manager/IdentityRelationshipServiceImpl.java index 53de2bb028c3e47569e61bbd62b67759661d5668..1609b7f0f55f60d096f5613236a6aa7fb574650c 100644 --- a/src/main/java/org/olat/basesecurity/manager/IdentityRelationshipServiceImpl.java +++ b/src/main/java/org/olat/basesecurity/manager/IdentityRelationshipServiceImpl.java @@ -21,12 +21,16 @@ package org.olat.basesecurity.manager; import java.util.ArrayList; import java.util.List; +import java.util.Locale; + +import javax.annotation.PostConstruct; import org.olat.basesecurity.IdentityRef; import org.olat.basesecurity.IdentityRelationshipService; import org.olat.basesecurity.IdentityToIdentityRelation; import org.olat.basesecurity.IdentityToIdentityRelationManagedFlag; import org.olat.basesecurity.RelationRight; +import org.olat.basesecurity.RelationRightProvider; import org.olat.basesecurity.RelationRole; import org.olat.basesecurity.RelationRoleManagedFlag; import org.olat.core.id.Identity; @@ -49,6 +53,16 @@ public class IdentityRelationshipServiceImpl implements IdentityRelationshipServ @Autowired private IdentityToIdentityRelationDAO identityRelationshipDao; + @Autowired + private List<RelationRightProvider> relationRightProviders; + + @PostConstruct + void ensureRightsExists() { + for (RelationRightProvider relationRightProvider : relationRightProviders) { + relationRightDao.ensureRightExists(relationRightProvider.getRight()); + } + } + @Override public RelationRole createRole(String role, List<RelationRight> rights) { RelationRole relationRole = relationRoleDao.createRelationRole(role, null, null, null); @@ -68,8 +82,6 @@ public class IdentityRelationshipServiceImpl implements IdentityRelationshipServ return relationRole; } - - @Override public RelationRole updateRole(RelationRole relationRole, List<RelationRight> rights) { if(rights == null) { @@ -93,6 +105,21 @@ public class IdentityRelationshipServiceImpl implements IdentityRelationshipServ return relationRightDao.loadRelationRights(); } + @Override + public String getTranslatedName(RelationRight right, Locale locale) { + RelationRightProvider provider = getRelationRightProvider(right); + return provider != null? provider.getTranslatedName(locale): "???"; + } + + private RelationRightProvider getRelationRightProvider(RelationRight right) { + for (RelationRightProvider provider : relationRightProviders) { + if (provider.getRight().equals(right.getRight())) { + return provider; + } + } + return null; + } + @Override public boolean isInUse(RelationRole relationRole) { return identityRelationshipDao.isUsed(relationRole); diff --git a/src/main/java/org/olat/basesecurity/manager/RelationRightDAO.java b/src/main/java/org/olat/basesecurity/manager/RelationRightDAO.java index 23c1f5483f693ee04d4ebb817ea2a4d9fca7a336..3736d0fb5d56b9826f28ba9b05bde719cd8d29cf 100644 --- a/src/main/java/org/olat/basesecurity/manager/RelationRightDAO.java +++ b/src/main/java/org/olat/basesecurity/manager/RelationRightDAO.java @@ -21,8 +21,6 @@ package org.olat.basesecurity.manager; import java.util.Date; import java.util.List; -import java.util.Set; -import java.util.stream.Collectors; import org.olat.basesecurity.RelationRight; import org.olat.basesecurity.model.RelationRightImpl; @@ -79,40 +77,16 @@ public class RelationRightDAO { /** * This method commits and closes the hibernate session. * - * @param rights The rights to create if they not exists + * @param right The right to create if it not exists */ - public void ensureRightsExists(Class<? extends Enum<?>> rightsEnum) { - Enum<?>[] rights = rightsEnum.getEnumConstants(); + public void ensureRightExists(String right) { + if(!StringHelper.containsNonWhitespace(right)) return; - List<RelationRight> relationRights = loadRelationRights(); - Set<String> rightNames = relationRights.stream() - .map(RelationRight::getRight).collect(Collectors.toSet()); - - for(Enum<?> right:rights) { - if(!rightNames.contains(right.name())) { - createRelationRight(right.name()); - } - } - dbInstance.commitAndCloseSession(); - } - - /** - * This method commits and closes the hibernate session. - * - * @param rights The rights to create if they not exists - */ - public void ensureRightsExists(String... rights) { - if(rights == null || rights.length == 0 || rights[0] == null) return; - - List<RelationRight> relationRights = loadRelationRights(); - Set<String> rightNames = relationRights.stream() - .map(RelationRight::getRight).collect(Collectors.toSet()); - - for(String right:rights) { - if(StringHelper.containsNonWhitespace(right) && !rightNames.contains(right)) { - createRelationRight(right); - } + RelationRight relationRight = loadRelationRightByRight(right); + if (relationRight == null) { + createRelationRight(right); } + dbInstance.commitAndCloseSession(); } diff --git a/src/main/java/org/olat/course/CourseModule.java b/src/main/java/org/olat/course/CourseModule.java index 7d6e36768266f650a65f5417045d4d8dcf1464b4..42e817f7bb55217ea55816811ee58946748c7576 100644 --- a/src/main/java/org/olat/course/CourseModule.java +++ b/src/main/java/org/olat/course/CourseModule.java @@ -27,7 +27,6 @@ package org.olat.course; import java.util.HashMap; -import org.olat.basesecurity.manager.RelationRightDAO; import org.olat.core.commons.services.notifications.SubscriptionContext; import org.olat.core.configuration.AbstractSpringModule; import org.olat.core.id.Identity; @@ -37,7 +36,6 @@ import org.olat.core.util.coordinate.CoordinatorManager; import org.olat.core.util.event.GenericEventListener; import org.olat.core.util.resource.OresHelper; import org.olat.course.assessment.AssessmentManager; -import org.olat.course.groupsandrights.CourseRightsEnum; import org.olat.course.nodes.CourseNode; import org.olat.course.run.environment.CourseEnvironment; import org.springframework.beans.factory.annotation.Autowired; @@ -75,9 +73,6 @@ public class CourseModule extends AbstractSpringModule { public static final OLATResourceable ORESOURCEABLE_TYPE_COURSE = OresHelper.lookupType(CourseModule.class); public static final String ORES_COURSE_ASSESSMENT = OresHelper.calculateTypeName(AssessmentManager.class); - @Autowired - private RelationRightDAO relationRightDao; - private static CoordinatorManager coordinatorManager; @Autowired @@ -102,14 +97,6 @@ public class CourseModule extends AbstractSpringModule { @Override public void init() { initFromChangedProperties(); - initCourseRights(); - } - - /** - * Initialize the course rights for user to user relations. - */ - private void initCourseRights() { - relationRightDao.ensureRightsExists(CourseRightsEnum.class); } /** diff --git a/src/main/java/org/olat/course/groupsandrights/ViewCourseCalendarRightProvider.java b/src/main/java/org/olat/course/groupsandrights/ViewCourseCalendarRightProvider.java new file mode 100644 index 0000000000000000000000000000000000000000..4b2db9bd1d0ce86f2386c528154636fa19358f79 --- /dev/null +++ b/src/main/java/org/olat/course/groupsandrights/ViewCourseCalendarRightProvider.java @@ -0,0 +1,49 @@ +/** + * <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.course.groupsandrights; + +import java.util.Locale; + +import org.olat.basesecurity.RelationRightProvider; +import org.olat.core.gui.translator.Translator; +import org.olat.core.util.Util; +import org.springframework.stereotype.Component; + +/** + * + * Initial date: 19 Feb 2019<br> + * @author uhensler, urs.hensler@frentix.com, http://www.frentix.com + * + */ +@Component +public class ViewCourseCalendarRightProvider implements RelationRightProvider { + + @Override + public String getRight() { + return CourseRightsEnum.viewCourseCalendar.name(); + } + + @Override + public String getTranslatedName(Locale locale) { + Translator translator = Util.createPackageTranslator(GroupsAndRightsController.class, locale); + return translator.translate("relation.right.viewCourseCalendar"); + } + +} diff --git a/src/main/java/org/olat/course/groupsandrights/ViewEfficiencyStatementRightProvider.java b/src/main/java/org/olat/course/groupsandrights/ViewEfficiencyStatementRightProvider.java new file mode 100644 index 0000000000000000000000000000000000000000..51657e2a127dc74ffae71d06dc55a994bf8072de --- /dev/null +++ b/src/main/java/org/olat/course/groupsandrights/ViewEfficiencyStatementRightProvider.java @@ -0,0 +1,49 @@ +/** + * <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.course.groupsandrights; + +import java.util.Locale; + +import org.olat.basesecurity.RelationRightProvider; +import org.olat.core.gui.translator.Translator; +import org.olat.core.util.Util; +import org.springframework.stereotype.Component; + +/** + * + * Initial date: 19 Feb 2019<br> + * @author uhensler, urs.hensler@frentix.com, http://www.frentix.com + * + */ +@Component +public class ViewEfficiencyStatementRightProvider implements RelationRightProvider { + + @Override + public String getRight() { + return CourseRightsEnum.viewEfficiencyStatement.name(); + } + + @Override + public String getTranslatedName(Locale locale) { + Translator translator = Util.createPackageTranslator(GroupsAndRightsController.class, locale); + return translator.translate("relation.right.viewCourseCalendar"); + } + +} diff --git a/src/main/java/org/olat/course/groupsandrights/_i18n/LocalStrings_de.properties b/src/main/java/org/olat/course/groupsandrights/_i18n/LocalStrings_de.properties index 4659e760b64ca776eff0073d50f78427504b1736..8c6f2c4595d2cd71c256c932fc1c2b82bd2900fb 100644 --- a/src/main/java/org/olat/course/groupsandrights/_i18n/LocalStrings_de.properties +++ b/src/main/java/org/olat/course/groupsandrights/_i18n/LocalStrings_de.properties @@ -1,29 +1,23 @@ #Mon Mar 02 09:54:04 CET 2009 +add.all=Alle Rechte hinzuf\u00FCgen bgr.archive=Datenarchivierung bgr.assess=Bewertungs-Werkzeug bgr.assessmode=Pr\u00FCfungsmodus +bgr.dbs=Kurs Datenbank bgr.editor=Kurseditor bgr.glossary=Glossar-Werkzeug bgr.groupmngt=Gruppen-Verwaltung bgr.membermngt=Mitglieder-Verwaltung bgr.statistics=Statistiken +menu.rights=Rechte noRestriction=Keine Einschr\u00E4nkung -bgr.dbs=Kurs Datenbank +participant=Teilnehmer +relation.right.viewCourseCalendar=Kurskalender ansehen +relation.right.viewEfficiencyStatement=Leistungnachweise ansehen +remove.all=Alle Rechte Entfernen +repo.participant=Kursteilnehmer +repo.tutor=Kursbetreuer table.header.groups=Gruppe -table.header.role=Rolle table.header.remove=Entfernen -menu.rights=Rechte -remove.all=Alle Rechte Entfernen -add.all=Alle Rechte hinzuf\u00fcgen +table.header.role=Rolle tutor=Betreuer -participant=Teilnehmer -repo.tutor=Kursbetreuer -repo.participant=Kursteilnehmer - - - - - - - - diff --git a/src/main/java/org/olat/course/groupsandrights/_i18n/LocalStrings_en.properties b/src/main/java/org/olat/course/groupsandrights/_i18n/LocalStrings_en.properties index 18600a5756c30f0d91d60d82df12ff2bee61eb42..48011728ce0cb9e8a28a849f4702d535ac40ec7f 100644 --- a/src/main/java/org/olat/course/groupsandrights/_i18n/LocalStrings_en.properties +++ b/src/main/java/org/olat/course/groupsandrights/_i18n/LocalStrings_en.properties @@ -12,18 +12,12 @@ bgr.statistics=Statistics menu.rights=Rights noRestriction=No restriction participant=Participant +relation.right.viewCourseCalendar=View course calenders +relation.right.viewEfficiencyStatement=View efficiency statements remove.all=Remove all permissions +repo.participant=Course participant +repo.tutor=Course coach table.header.groups=Groups table.header.remove=Remove table.header.role=Role tutor=Coach -repo.tutor=Course coach -repo.participant=Course participant - - - - - - - - diff --git a/src/main/java/org/olat/user/_i18n/LocalStrings_de.properties b/src/main/java/org/olat/user/_i18n/LocalStrings_de.properties index 1bad84460c987bc07c9f29bb8b9b1b7b434c16fb..e390a00bc6afb3404243cfba949af0e5e5fa401d 100644 --- a/src/main/java/org/olat/user/_i18n/LocalStrings_de.properties +++ b/src/main/java/org/olat/user/_i18n/LocalStrings_de.properties @@ -103,8 +103,6 @@ pwdav.password.set=******* (Passwort verschl\u00FCsselt) pwdav.password.successful=Ihr neues WebDAV Passwort wurde erfolgreich gespeichert. Es ist ab sofort aktiv. pwdav.title=WebDAV Zugang pwdav.username=WebDAV Benutzername -relation.right.viewEfficiencyStatement=Leistungnachweise ansehen -relation.right.viewCourseCalendar=Kurskalender ansehen replayurl.active=Load Performance URL eingeschaltet reset.desc=Hier k\u00F6nnen Sie die personalisierten Systemkonfiguration wieder auf die Standardeinstellung zur\u00FCcksetzen. W\u00E4hlen Sie unten die Einstellungen aus, die zur\u00FCckgesetzt werden sollen. Um die Einstellungen zu aktivieren werden Sie automatisch aus dem System ausgeloggt\! reset.elements=Einstellungen diff --git a/src/main/java/org/olat/user/_i18n/LocalStrings_en.properties b/src/main/java/org/olat/user/_i18n/LocalStrings_en.properties index 10dc88f14f5afdd0de8de495542babc1961ea822..0160f5d573a56bc8833315589bc4fd39a7a0ed3e 100644 --- a/src/main/java/org/olat/user/_i18n/LocalStrings_en.properties +++ b/src/main/java/org/olat/user/_i18n/LocalStrings_en.properties @@ -104,8 +104,6 @@ pwdav.password.successful=Your new WebDAV password has been saved successfully. pwdav.title=WebDAV access pwdav.username=WebDav user name replayurl.active=Load performance URL active -relation.role.viewEfficiencyStatement=View efficiency statements -relation.role.viewCourseCalendar=View course calenders reset.desc=You can reset your personalized system configuration to the default values using this form. Choose below the settings you want reset. To activate the changes the system will automatically trigger a logout. reset.elements=Configurations reset.elements.guiprefs=Personalized interface components (menu, tool boxes, tables, portal, calendar etc.) diff --git a/src/main/java/org/olat/user/ui/role/EditRelationRoleController.java b/src/main/java/org/olat/user/ui/role/EditRelationRoleController.java index bbf92d6c8761b3ee3fe0e129dccc9c89e926b2c2..d7e90134115c71ce03aba3fec038422d23e4d332 100644 --- a/src/main/java/org/olat/user/ui/role/EditRelationRoleController.java +++ b/src/main/java/org/olat/user/ui/role/EditRelationRoleController.java @@ -81,7 +81,7 @@ public class EditRelationRoleController extends FormBasicController { String[] rightValues = new String[rights.size()]; for(int i=rights.size(); i-->0; ) { rightKeys[i] = rights.get(i).getRight(); - rightValues[i] = translate(RelationRolesAndRightsUIFactory.TRANS_RIGHT_PREFIX.concat(rights.get(i).getRight())); + rightValues[i] = identityRelationsService.getTranslatedName(rights.get(i), getLocale()); } rightsEl = uifactory.addCheckboxesVertical("role.rights", formLayout, rightKeys, rightValues, 2); rightsEl.setEnabled(!RelationRoleManagedFlag.isManaged(relationRole, RelationRoleManagedFlag.rights)); diff --git a/src/main/java/org/olat/user/ui/role/RelationRolesAndRightsUIFactory.java b/src/main/java/org/olat/user/ui/role/RelationRolesAndRightsUIFactory.java index 07bbd0245bc3ddf8570d99e148f61008807a0785..1f84ed46ccbfab2c2dfd67f5796c0b48c48d752f 100644 --- a/src/main/java/org/olat/user/ui/role/RelationRolesAndRightsUIFactory.java +++ b/src/main/java/org/olat/user/ui/role/RelationRolesAndRightsUIFactory.java @@ -28,6 +28,5 @@ package org.olat.user.ui.role; public class RelationRolesAndRightsUIFactory { public static final String TRANS_ROLE_PREFIX = "relation.role."; - public static final String TRANS_RIGHT_PREFIX = "relation.right."; } diff --git a/src/test/java/org/olat/basesecurity/manager/RelationRightDAOTest.java b/src/test/java/org/olat/basesecurity/manager/RelationRightDAOTest.java index 966e62ab4af03f5713a5207d6d97c3f84726967d..d5318ffc6cc4cab219cdb5e3015d7b0591a8a523 100644 --- a/src/test/java/org/olat/basesecurity/manager/RelationRightDAOTest.java +++ b/src/test/java/org/olat/basesecurity/manager/RelationRightDAOTest.java @@ -92,18 +92,13 @@ public class RelationRightDAOTest extends OlatTestCase { } @Test - public void ensureRightsExists_enum() { - relationRightDao.ensureRightsExists(UnitTestRights.class); + public void ensureRightsExists() { + String right = "unitTestRight"; + relationRightDao.ensureRightExists(right); dbInstance.commitAndCloseSession(); - RelationRight firstRight = relationRightDao.loadRelationRightByRight(UnitTestRights.iWantToTest.name()); - Assert.assertNotNull(firstRight); - RelationRight secondRight = relationRightDao.loadRelationRightByRight(UnitTestRights.moreUnitTest.name()); - Assert.assertNotNull(secondRight); + RelationRight loadedRight = relationRightDao.loadRelationRightByRight(right); + Assert.assertNotNull(loadedRight); } - public enum UnitTestRights { - iWantToTest, - moreUnitTest - } }