From 0c11f7c645c466cd70e942558d4d56c320308cf1 Mon Sep 17 00:00:00 2001 From: srosse <none@none> Date: Wed, 29 Jun 2016 17:17:46 +0200 Subject: [PATCH] OO-2057: add remove access rights and user details --- .../olat/admin/user/UserShortDescription.java | 18 +++++---- .../AssessedIdentityLargeInfosController.java | 2 + .../modules/portfolio/PortfolioService.java | 2 + .../manager/PortfolioServiceImpl.java | 22 +++++++++++ .../ui/AccessRightsEditController.java | 29 ++++++++++++++ .../portfolio/ui/PublishController.java | 4 ++ .../portfolio/ui/_content/access_rights.html | 6 +++ .../ui/_i18n/LocalStrings_de.properties | 1 + .../ui/_i18n/LocalStrings_en.properties | 1 + .../portfolio/ui/event/AccessRightsEvent.java | 39 +++++++++++++++++++ 10 files changed, 116 insertions(+), 8 deletions(-) create mode 100644 src/main/java/org/olat/modules/portfolio/ui/event/AccessRightsEvent.java diff --git a/src/main/java/org/olat/admin/user/UserShortDescription.java b/src/main/java/org/olat/admin/user/UserShortDescription.java index a7f07d4e91a..9acb1d251ea 100644 --- a/src/main/java/org/olat/admin/user/UserShortDescription.java +++ b/src/main/java/org/olat/admin/user/UserShortDescription.java @@ -28,7 +28,6 @@ package org.olat.admin.user; import java.util.List; import org.olat.basesecurity.BaseSecurityModule; -import org.olat.core.CoreSpringFactory; import org.olat.core.gui.UserRequest; import org.olat.core.gui.components.Component; import org.olat.core.gui.components.velocity.VelocityContainer; @@ -39,6 +38,7 @@ import org.olat.core.id.Identity; import org.olat.core.id.Roles; import org.olat.user.UserManager; import org.olat.user.propertyhandlers.UserPropertyHandler; +import org.springframework.beans.factory.annotation.Autowired; /** * @@ -51,23 +51,25 @@ import org.olat.user.propertyhandlers.UserPropertyHandler; */ public class UserShortDescription extends BasicController { - private VelocityContainer velocityContainer; private static final String usageIdentifyer = UserShortDescription.class.getCanonicalName(); - private List<UserPropertyHandler> userPropertyHandlers; - + + @Autowired + private UserManager userManager; + @Autowired + private BaseSecurityModule securityModule; public UserShortDescription(UserRequest ureq, WindowControl wControl, Identity identity) { super(ureq, wControl); String usernameLabel = translate("table.user.login"); //use the PropertyHandlerTranslator for the velocityContainer - setTranslator(UserManager.getInstance().getPropertyHandlerTranslator(getTranslator())); - velocityContainer = createVelocityContainer("userShortDescription"); + setTranslator(userManager.getPropertyHandlerTranslator(getTranslator())); + VelocityContainer velocityContainer = createVelocityContainer("userShortDescription"); Roles roles = ureq.getUserSession().getRoles(); - boolean isAdministrativeUser = CoreSpringFactory.getImpl(BaseSecurityModule.class).isUserAllowedAdminProps(roles); + boolean isAdministrativeUser = securityModule.isUserAllowedAdminProps(roles); //(roles.isAuthor() || roles.isGroupManager() || roles.isUserManager() || roles.isOLATAdmin()); - userPropertyHandlers = UserManager.getInstance().getUserPropertyHandlersFor(usageIdentifyer, isAdministrativeUser); + List<UserPropertyHandler> userPropertyHandlers = userManager.getUserPropertyHandlersFor(usageIdentifyer, isAdministrativeUser); velocityContainer.contextPut("userPropertyHandlers", userPropertyHandlers); velocityContainer.contextPut("user", identity.getUser()); velocityContainer.contextPut("identityKey", identity.getKey()); diff --git a/src/main/java/org/olat/course/assessment/ui/tool/AssessedIdentityLargeInfosController.java b/src/main/java/org/olat/course/assessment/ui/tool/AssessedIdentityLargeInfosController.java index 21377155747..93661ea2677 100644 --- a/src/main/java/org/olat/course/assessment/ui/tool/AssessedIdentityLargeInfosController.java +++ b/src/main/java/org/olat/course/assessment/ui/tool/AssessedIdentityLargeInfosController.java @@ -48,9 +48,11 @@ public class AssessedIdentityLargeInfosController extends BasicController { portraitCtr = new DisplayPortraitController(ureq, getWindowControl(), assessedIdentity, true, true); mainVC.put("portrait", portraitCtr.getInitialComponent()); + listenTo(portraitCtr); userShortDescrCtr = new UserShortDescription(ureq, getWindowControl(), assessedIdentity); mainVC.put("userShortDescription", userShortDescrCtr.getInitialComponent()); + listenTo(userShortDescrCtr); putInitialPanel(mainVC); } diff --git a/src/main/java/org/olat/modules/portfolio/PortfolioService.java b/src/main/java/org/olat/modules/portfolio/PortfolioService.java index 79edce97d45..8407d2f5d74 100644 --- a/src/main/java/org/olat/modules/portfolio/PortfolioService.java +++ b/src/main/java/org/olat/modules/portfolio/PortfolioService.java @@ -160,6 +160,8 @@ public interface PortfolioService { public void changeAccessRights(List<Identity> identities, List<AccessRightChange> changes); + public void removeAccessRights(Binder binder, Identity identity); + public List<Category> getCategories(PortfolioElement element); /** diff --git a/src/main/java/org/olat/modules/portfolio/manager/PortfolioServiceImpl.java b/src/main/java/org/olat/modules/portfolio/manager/PortfolioServiceImpl.java index a4f857051c9..356a94fa64b 100644 --- a/src/main/java/org/olat/modules/portfolio/manager/PortfolioServiceImpl.java +++ b/src/main/java/org/olat/modules/portfolio/manager/PortfolioServiceImpl.java @@ -68,6 +68,7 @@ import org.olat.modules.portfolio.PageBody; import org.olat.modules.portfolio.PagePart; import org.olat.modules.portfolio.PageStatus; import org.olat.modules.portfolio.PortfolioElement; +import org.olat.modules.portfolio.PortfolioElementType; import org.olat.modules.portfolio.PortfolioRoles; import org.olat.modules.portfolio.PortfolioService; import org.olat.modules.portfolio.Section; @@ -319,6 +320,27 @@ public class PortfolioServiceImpl implements PortfolioService { } } + @Override + public void removeAccessRights(Binder binder, Identity identity) { + List<AccessRights> rights = getAccessRights(binder, identity); + for(AccessRights right:rights) { + Group baseGroup; + if(right.getType() == PortfolioElementType.binder) { + baseGroup = binderDao.loadByKey(right.getBinderKey()).getBaseGroup(); + } else if(right.getType() == PortfolioElementType.section) { + baseGroup = binderDao.loadSectionByKey(right.getSectionKey()).getBaseGroup(); + } else if(right.getType() == PortfolioElementType.page) { + baseGroup = pageDao.loadByKey(right.getPageKey()).getBaseGroup(); + } else { + continue; + } + + if(groupDao.hasRole(baseGroup, identity, right.getRole().name())) { + groupDao.removeMembership(baseGroup, identity, right.getRole().name()); + } + } + } + private Group getGroup(PortfolioElement element) { if(element instanceof Page) { return pageDao.getGroup((Page)element); diff --git a/src/main/java/org/olat/modules/portfolio/ui/AccessRightsEditController.java b/src/main/java/org/olat/modules/portfolio/ui/AccessRightsEditController.java index 48e46ec292c..c23b7327f79 100644 --- a/src/main/java/org/olat/modules/portfolio/ui/AccessRightsEditController.java +++ b/src/main/java/org/olat/modules/portfolio/ui/AccessRightsEditController.java @@ -24,12 +24,17 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import org.olat.admin.user.UserShortDescription; import org.olat.core.gui.UserRequest; +import org.olat.core.gui.components.form.flexible.FormItem; import org.olat.core.gui.components.form.flexible.FormItemContainer; +import org.olat.core.gui.components.form.flexible.elements.FormLink; import org.olat.core.gui.components.form.flexible.elements.MultipleSelectionElement; import org.olat.core.gui.components.form.flexible.impl.Form; import org.olat.core.gui.components.form.flexible.impl.FormBasicController; +import org.olat.core.gui.components.form.flexible.impl.FormEvent; import org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer; +import org.olat.core.gui.components.link.Link; import org.olat.core.gui.control.Controller; import org.olat.core.gui.control.Event; import org.olat.core.gui.control.WindowControl; @@ -42,6 +47,8 @@ import org.olat.modules.portfolio.PortfolioService; import org.olat.modules.portfolio.Section; import org.olat.modules.portfolio.model.AccessRightChange; import org.olat.modules.portfolio.model.AccessRights; +import org.olat.modules.portfolio.ui.event.AccessRightsEvent; +import org.olat.user.DisplayPortraitController; import org.springframework.beans.factory.annotation.Autowired; /** @@ -55,6 +62,8 @@ public class AccessRightsEditController extends FormBasicController { private static final String[] theKeys = new String[]{ "xx" }; private static final String[] theValues = new String[]{ "" }; + private FormLink removeLink; + private int counter; private final Binder binder; private final Identity member; @@ -93,6 +102,17 @@ public class AccessRightsEditController extends FormBasicController { @Override protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) { + if(member != null && formLayout instanceof FormLayoutContainer) { + FormLayoutContainer layoutCont = (FormLayoutContainer)formLayout; + + Controller portraitCtr = new DisplayPortraitController(ureq, getWindowControl(), member, true, true); + layoutCont.getFormItemComponent().put("portrait", portraitCtr.getInitialComponent()); + listenTo(portraitCtr); + Controller userShortDescrCtr = new UserShortDescription(ureq, getWindowControl(), member); + layoutCont.getFormItemComponent().put("userShortDescription", userShortDescrCtr.getInitialComponent()); + listenTo(userShortDescrCtr); + } + //binder MultipleSelectionElement coachEl = uifactory.addCheckboxesHorizontal("access-" + (counter++), null, formLayout, theKeys, theValues); MultipleSelectionElement reviewerEl = uifactory.addCheckboxesHorizontal("access-" + (counter++), null, formLayout, theKeys, theValues); @@ -132,6 +152,7 @@ public class AccessRightsEditController extends FormBasicController { buttonsCont.setRootForm(mainForm); formLayout.add("buttons", buttonsCont); uifactory.addFormCancelButton("cancel", buttonsCont, ureq, getWindowControl()); + removeLink = uifactory.addFormLink("remove", buttonsCont, Link.BUTTON); if(canEdit) { uifactory.addFormSubmitButton("save", buttonsCont); } @@ -175,6 +196,14 @@ public class AccessRightsEditController extends FormBasicController { } } + @Override + protected void formInnerEvent(UserRequest ureq, FormItem source, FormEvent event) { + if(removeLink == source) { + fireEvent(ureq, new AccessRightsEvent(AccessRightsEvent.REMOVE_ALL_RIGHTS)); + } + super.formInnerEvent(ureq, source, event); + } + @Override protected void formCancelled(UserRequest ureq) { if(hasButtons) { diff --git a/src/main/java/org/olat/modules/portfolio/ui/PublishController.java b/src/main/java/org/olat/modules/portfolio/ui/PublishController.java index 02c789165d3..c68f2d8b712 100644 --- a/src/main/java/org/olat/modules/portfolio/ui/PublishController.java +++ b/src/main/java/org/olat/modules/portfolio/ui/PublishController.java @@ -66,6 +66,7 @@ import org.olat.modules.portfolio.Section; import org.olat.modules.portfolio.SectionStatus; import org.olat.modules.portfolio.model.AccessRightChange; import org.olat.modules.portfolio.model.AccessRights; +import org.olat.modules.portfolio.ui.event.AccessRightsEvent; import org.olat.modules.portfolio.ui.renderer.PortfolioRendererHelper; import org.olat.modules.portfolio.ui.wizard.AccessRightsContext; import org.olat.modules.portfolio.ui.wizard.AddMember_1_ChooseMemberStep; @@ -252,6 +253,9 @@ public class PublishController extends BasicController implements TooledControll List<Identity> identities = Collections.singletonList(editAccessRightsCtrl.getMember()); portfolioService.changeAccessRights(identities, changes); reloadData(); + } else if(AccessRightsEvent.REMOVE_ALL_RIGHTS.equals(event.getCommand())) { + portfolioService.removeAccessRights(binder, editAccessRightsCtrl.getMember()); + reloadData(); } cmc.deactivate(); cleanUp(); diff --git a/src/main/java/org/olat/modules/portfolio/ui/_content/access_rights.html b/src/main/java/org/olat/modules/portfolio/ui/_content/access_rights.html index ccbfa9f75db..b5550afb576 100644 --- a/src/main/java/org/olat/modules/portfolio/ui/_content/access_rights.html +++ b/src/main/java/org/olat/modules/portfolio/ui/_content/access_rights.html @@ -1,3 +1,9 @@ +#if($r.available("userShortDescription")) +<div class="o_user_infos"> + <div class="o_user_portrait">$r.render("portrait")</div> + <div class="o_user_infos_inner">$r.render("userShortDescription")</div> +</div> +#end <div class="o_portfolio_rights"> <table class="table"> <thead><tr> diff --git a/src/main/java/org/olat/modules/portfolio/ui/_i18n/LocalStrings_de.properties b/src/main/java/org/olat/modules/portfolio/ui/_i18n/LocalStrings_de.properties index 6e4f8946bd1..66c47c0ca4f 100644 --- a/src/main/java/org/olat/modules/portfolio/ui/_i18n/LocalStrings_de.properties +++ b/src/main/java/org/olat/modules/portfolio/ui/_i18n/LocalStrings_de.properties @@ -126,6 +126,7 @@ publish=Eintrag publizieren publish.confirm.descr=Wollen Sie diesen Eintrag "{0}" publizieren? publish.confirm.title=Publizieren publish.status.title=Freigabe Status der Mappe "{0}" +remove=Entfernen reopen=Neu \u00F6ffnen section.delete=Bereich l\u00F6schen section.edit=Bereich bearbeiten diff --git a/src/main/java/org/olat/modules/portfolio/ui/_i18n/LocalStrings_en.properties b/src/main/java/org/olat/modules/portfolio/ui/_i18n/LocalStrings_en.properties index 598bb01bd62..e6351599797 100644 --- a/src/main/java/org/olat/modules/portfolio/ui/_i18n/LocalStrings_en.properties +++ b/src/main/java/org/olat/modules/portfolio/ui/_i18n/LocalStrings_en.properties @@ -127,6 +127,7 @@ publish=Publish entry publish.confirm.descr=Do you want to publish this entry "{0}"? publish.confirm.title=Publish publish.status.title=Publish status of binder "{0}" +remove=Remove reopen=Reopen section.delete=Delete section section.edit=Edit section diff --git a/src/main/java/org/olat/modules/portfolio/ui/event/AccessRightsEvent.java b/src/main/java/org/olat/modules/portfolio/ui/event/AccessRightsEvent.java new file mode 100644 index 00000000000..241a5f4898f --- /dev/null +++ b/src/main/java/org/olat/modules/portfolio/ui/event/AccessRightsEvent.java @@ -0,0 +1,39 @@ +/** + * <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.modules.portfolio.ui.event; + +import org.olat.core.gui.control.Event; + +/** + * + * Initial date: 29.06.2016<br> + * @author srosse, stephane.rosse@frentix.com, http://www.frentix.com + * + */ +public class AccessRightsEvent extends Event { + + private static final long serialVersionUID = -6683138293820085093L; + public static final String REMOVE_ALL_RIGHTS = "remove-all-access-rights"; + + public AccessRightsEvent(String cmd) { + super(cmd); + } + +} -- GitLab