Search in sources :

Example 76 with ContextEntry

use of org.olat.core.id.context.ContextEntry in project openolat by klemens.

the class DialogCourseNodeIndexer method checkAccess.

@Override
public boolean checkAccess(ContextEntry contextEntry, BusinessControl businessControl, Identity identity, Roles roles) {
    ContextEntry ce = businessControl.popLauncherContextEntry();
    if (ce == null || ce.getOLATResourceable() == null || ce.getOLATResourceable().getResourceableId() == null) {
        // it's the node itself
        return true;
    }
    OLATResourceable ores = ce.getOLATResourceable();
    if (isLogDebugEnabled())
        logDebug("OLATResourceable=" + ores);
    if (ores.getResourceableTypeName().startsWith("path=")) {
        // => it is a file element, typeName format: 'path=/test1/test2/readme.txt'
        return true;
    } else if (ores.getResourceableTypeName().equals(OresHelper.calculateTypeName(Message.class))) {
        // it is message => check message access
        Long resourceableId = ores.getResourceableId();
        Message message = ForumManager.getInstance().loadMessage(resourceableId);
        Message threadtop = message.getThreadtop();
        if (threadtop == null) {
            threadtop = message;
        }
        boolean isMessageHidden = Status.getStatus(threadtop.getStatusCode()).isHidden();
        // TODO: (LD) fix this!!! - the contextEntry is not the right context for this check
        if (isMessageHidden) {
            boolean isOwner = BaseSecurityManager.getInstance().isIdentityPermittedOnResourceable(identity, Constants.PERMISSION_ACCESS, contextEntry.getOLATResourceable());
            return isOwner;
        }
        return true;
    } else {
        logWarn("In DialogCourseNode unkown OLATResourceable=" + ores, null);
        return false;
    }
}
Also used : Message(org.olat.modules.fo.Message) OLATResourceable(org.olat.core.id.OLATResourceable) ContextEntry(org.olat.core.id.context.ContextEntry)

Example 77 with ContextEntry

use of org.olat.core.id.context.ContextEntry in project openolat by klemens.

the class UserInfoMainController method activate.

@Override
public void activate(UserRequest ureq, List<ContextEntry> entries, StateEntry state) {
    if (entries == null || entries.isEmpty())
        return;
    String type = entries.get(0).getOLATResourceable().getResourceableTypeName();
    if (StringHelper.containsNonWhitespace(type)) {
        Controller controller = createComponent(ureq, type);
        if (controller != null) {
            if (controller instanceof Activateable2) {
                List<ContextEntry> subEntries = entries.subList(1, entries.size());
                ((Activateable2) controller).activate(ureq, subEntries, entries.get(0).getTransientState());
            }
            main.setContent(controller.getInitialComponent());
            TreeNode selectedNode = TreeHelper.findNodeByUserObject(type, menuTree.getTreeModel().getRootNode());
            if (selectedNode != null) {
                menuTree.setSelectedNode(selectedNode);
            }
        }
    }
}
Also used : Activateable2(org.olat.core.gui.control.generic.dtabs.Activateable2) GenericTreeNode(org.olat.core.gui.components.tree.GenericTreeNode) TreeNode(org.olat.core.gui.components.tree.TreeNode) WeeklyCalendarController(org.olat.commons.calendar.ui.WeeklyCalendarController) LayoutMain3ColsController(org.olat.core.commons.fullWebApp.LayoutMain3ColsController) FolderRunController(org.olat.core.commons.modules.bc.FolderRunController) Controller(org.olat.core.gui.control.Controller) ContactFormController(org.olat.modules.co.ContactFormController) MainLayoutBasicController(org.olat.core.gui.control.controller.MainLayoutBasicController) EPMapRunController(org.olat.portfolio.ui.EPMapRunController) ContextEntry(org.olat.core.id.context.ContextEntry)

Example 78 with ContextEntry

use of org.olat.core.id.context.ContextEntry in project openolat by klemens.

the class UserNameReadOnlyPropertyHandler method getUserPropertyAsHTML.

@Override
public String getUserPropertyAsHTML(User user, Locale locale) {
    String val = getInternalValue(user);
    if (val != null) {
        Identity identity = ((UserImpl) user).getIdentity();
        ContextEntry ce = BusinessControlFactory.getInstance().createContextEntry(identity);
        String homepage = BusinessControlFactory.getInstance().getAsURIString(Collections.singletonList(ce), false);
        return "<a href='" + homepage + "'>" + StringHelper.escapeHtml(val) + "</a>";
    }
    return "";
}
Also used : UserImpl(org.olat.user.UserImpl) Identity(org.olat.core.id.Identity) ContextEntry(org.olat.core.id.context.ContextEntry)

Example 79 with ContextEntry

use of org.olat.core.id.context.ContextEntry in project openolat by klemens.

the class VideoListingController method doShowVideo.

/**
 * Launch a single video and add to breadcrumb
 * @param ureq
 * @param id the video resource ID
 */
private void doShowVideo(UserRequest ureq, Long id) {
    RepositoryEntry videoEntry = repositoryManager.lookupRepositoryEntry(id);
    if (repositoryManager.isAllowed(ureq, videoEntry).canLaunch()) {
        boolean readOnly = repositoryManager.createRepositoryEntryStatus(videoEntry.getStatusCode()).isClosed();
        VideoDisplayController videoDisplayCtr = new VideoDisplayController(ureq, getWindowControl(), videoEntry, true, true, true, true, null, false, true, null, readOnly);
        listenTo(videoDisplayCtr);
        toolbarPanel.pushController(videoEntry.getDisplayname(), videoDisplayCtr);
        // Update launch counter
        repositoryService.incrementLaunchCounter(videoEntry);
        // Update business path and URL
        ContextEntry ce = BusinessControlFactory.getInstance().createContextEntry(videoEntry);
        ThreadLocalUserActivityLogger.addLoggingResourceInfo(LoggingResourceable.wrapBusinessPath(ce.getOLATResourceable()));
        WindowControl bwControl = BusinessControlFactory.getInstance().createBusinessWindowControl(ce, getWindowControl());
        addToHistory(ureq, bwControl);
    }
}
Also used : RepositoryEntry(org.olat.repository.RepositoryEntry) WindowControl(org.olat.core.gui.control.WindowControl) ContextEntry(org.olat.core.id.context.ContextEntry)

Example 80 with ContextEntry

use of org.olat.core.id.context.ContextEntry in project openolat by klemens.

the class ItemsController method event.

@Override
protected void event(UserRequest ureq, Controller source, Event event) {
    // reload feed for this event and make sure the updated feed object is
    // in the view
    feedResource = feedManager.loadFeed(feedResource);
    accessibleItems = feedManager.loadFilteredAndSortedItems(feedResource, callback, ureq.getIdentity());
    if (source == cmc) {
        if (event.equals(CloseableModalController.CLOSE_MODAL_EVENT)) {
            removeAsListenerAndDispose(cmc);
            cmc = null;
            removeAsListenerAndDispose(itemFormCtr);
            itemFormCtr = null;
            // Check if this item has ever been added to the feed. If not,
            // remove the temp dir
            cleanupTmpItemMediaDir(currentItem);
            // internally or subscribe to an external feed.
            if (!feedManager.hasItems(feedResource)) {
                feedResource = feedManager.updateFeedMode(null, feedResource);
                makeInternalAndExternalButtons();
            }
            // release lock
            feedManager.releaseLock(lock);
        }
    } else if (source == confirmDialogCtr && DialogBoxUIFactory.isYesEvent(event)) {
        // The user confirmed that the item shall be deleted
        Item item = (Item) ((DialogBoxController) source).getUserObject();
        lock = feedManager.acquireLock(feedResource, item, getIdentity());
        if (lock.isSuccess()) {
            // remove the item from the naviCtr
            naviCtr.remove(item);
            // permanently remove item
            feedResource = feedManager.deleteItem(item);
            // remove delete and edit buttons of this item
            for (Link deleteButton : deleteButtons) {
                if (item.equals(deleteButton.getUserObject())) {
                    deleteButtons.remove(deleteButton);
                    break;
                }
            }
            for (Link editButton : editButtons) {
                if (item.equals(editButton.getUserObject())) {
                    editButtons.remove(editButton);
                    break;
                }
            }
            // items manually or from an external source/feed.
            if (!feedManager.hasItems(feedResource)) {
                makeInternalAndExternalButtons();
                // The subscription/feed url from the feed info is obsolete
                fireEvent(ureq, ItemsController.FEED_INFO_IS_DIRTY_EVENT);
            } else {
                if (callback.mayEditItems() || callback.mayCreateItems()) {
                    createEditButtons(ureq, feedResource);
                }
                createCommentsAndRatingsLinks(ureq, feedResource);
            }
            vcItems.setDirty(true);
            // in case we were in single item view, show all items
            mainPanel.setContent(vcItems);
            feedManager.releaseLock(lock);
            lock = null;
            // do logging
            ThreadLocalUserActivityLogger.log(FeedLoggingAction.FEED_ITEM_DELETE, getClass(), LoggingResourceable.wrap(item));
        } else {
            String fullName = userManager.getUserDisplayName(lock.getOwner());
            showInfo("feed.item.is.being.edited.by", fullName);
        }
    } else if (source == itemFormCtr) {
        if (event.equals(Event.CHANGED_EVENT) || event.equals(Event.CANCELLED_EVENT)) {
            if (event.equals(Event.CHANGED_EVENT)) {
                FileElement mediaFile = currentItem.getMediaFile();
                if (feedManager.getItemContainer(currentItem) == null) {
                    // Ups, deleted in the meantime by someone else
                    // remove the item from the naviCtr
                    naviCtr.remove(currentItem);
                } else {
                    if (!accessibleItems.contains(currentItem)) {
                        // Add the modified item if it is not part of the
                        // feed
                        feedResource = feedManager.createItem(feedResource, currentItem, mediaFile);
                        if (feedResource != null) {
                            createButtonsForItem(ureq, feedResource, currentItem);
                            createItemLink(currentItem);
                            // Add date component
                            String guid = currentItem.getGuid();
                            if (currentItem.getDate() != null) {
                                DateComponentFactory.createDateComponentWithYear("date." + guid, currentItem.getDate(), vcItems);
                            }
                            // Add comments and rating
                            createCommentsAndRatingsLink(ureq, feedResource, currentItem);
                            // add it to the navigation controller
                            naviCtr.add(currentItem);
                            accessibleItems = feedManager.loadFilteredAndSortedItems(feedResource, callback, ureq.getIdentity());
                            if (accessibleItems != null && accessibleItems.size() == 1) {
                                // First item added, show feed url (for
                                // subscription)
                                fireEvent(ureq, ItemsController.FEED_INFO_IS_DIRTY_EVENT);
                                // Set the base URI of the feed for the
                                // current user. All users
                                // have unique URIs.
                                helper.setURIs(currentItem.getFeed());
                            }
                        }
                    } else {
                        // Write item file
                        currentItem = feedManager.updateItem(currentItem, mediaFile);
                        if (itemCtr != null) {
                            displayItemController(ureq, currentItem);
                        }
                        ThreadLocalUserActivityLogger.log(FeedLoggingAction.FEED_ITEM_EDIT, getClass(), LoggingResourceable.wrap(currentItem));
                    }
                }
                vcItems.setDirty(true);
                // if the current item is displayed, update the view
                if (itemCtr != null) {
                    itemCtr.getInitialComponent().setDirty(true);
                }
            } else if (event.equals(Event.CANCELLED_EVENT)) {
                // Check if this item has ever been added to the feed. If
                // not, remove the temp dir
                cleanupTmpItemMediaDir(currentItem);
                // internally or subscribe to an external feed.
                if (!feedManager.hasItems(feedResource)) {
                    feedResource = feedManager.updateFeedMode(null, feedResource);
                    makeInternalAndExternalButtons();
                }
            }
            // release the lock
            feedManager.releaseLock(lock);
            // Dispose the cmc and the podcastFormCtr.
            cmc.deactivate();
            removeAsListenerAndDispose(cmc);
            cmc = null;
            removeAsListenerAndDispose(itemFormCtr);
            itemFormCtr = null;
        }
    } else if (source == externalUrlCtr) {
        if (event.equals(Event.CHANGED_EVENT)) {
            String externalUrl = externalUrlCtr.getExternalFeedUrlEl();
            feedManager.updateExternalFeedUrl(feedResource, externalUrl);
        } else if (event.equals(Event.CHANGED_EVENT)) {
        // nothing to do
        }
        cmc.deactivate();
        removeAsListenerAndDispose(cmc);
        cmc = null;
        removeAsListenerAndDispose(externalUrlCtr);
        externalUrlCtr = null;
    } else if (source == naviCtr && event instanceof NavigationEvent) {
        List<? extends Dated> selItems = ((NavigationEvent) event).getSelectedItems();
        List<Item> items = new ArrayList<>();
        for (Dated item : selItems) {
            if (item instanceof Item) {
                items.add((Item) item);
            }
        }
        if (callback.mayEditItems() || callback.mayCreateItems()) {
            createEditButtons(ureq, feedResource);
        }
        createCommentsAndRatingsLinks(ureq, feedResource);
        vcItems.setDirty(true);
        mainPanel.setContent(vcItems);
    } else if (source == itemCtr) {
        if (event == Event.BACK_EVENT) {
            mainPanel.setContent(vcItems);
            removeAsListenerAndDispose(itemCtr);
            itemCtr = null;
        }
    } else if (source instanceof UserCommentsAndRatingsController) {
        UserCommentsAndRatingsController commentsRatingsCtr = (UserCommentsAndRatingsController) source;
        if (event == UserCommentsAndRatingsController.EVENT_COMMENT_LINK_CLICKED) {
            // go to details page
            Item item = (Item) commentsRatingsCtr.getUserObject();
            if (item != null) {
                ItemController myItemCtr = displayItemController(ureq, item);
                List<ContextEntry> entries = BusinessControlFactory.getInstance().createCEListFromResourceType(ItemController.ACTIVATION_KEY_COMMENTS);
                myItemCtr.activate(ureq, entries, null);
            }
        }
    }
    // reload everything
    if (feedResource != null) {
        resetItems(ureq, feedResource);
    }
}
Also used : NavigationEvent(org.olat.core.commons.controllers.navigation.NavigationEvent) ArrayList(java.util.ArrayList) ContextEntry(org.olat.core.id.context.ContextEntry) DialogBoxController(org.olat.core.gui.control.generic.modal.DialogBoxController) Item(org.olat.modules.webFeed.Item) UserCommentsAndRatingsController(org.olat.core.commons.services.commentAndRating.ui.UserCommentsAndRatingsController) FileElement(org.olat.core.gui.components.form.flexible.elements.FileElement) Dated(org.olat.core.commons.controllers.navigation.Dated) Link(org.olat.core.gui.components.link.Link)

Aggregations

ContextEntry (org.olat.core.id.context.ContextEntry)270 OLATResourceable (org.olat.core.id.OLATResourceable)78 WindowControl (org.olat.core.gui.control.WindowControl)58 Activateable2 (org.olat.core.gui.control.generic.dtabs.Activateable2)44 ArrayList (java.util.ArrayList)42 TreeNode (org.olat.core.gui.components.tree.TreeNode)30 Controller (org.olat.core.gui.control.Controller)26 RepositoryEntry (org.olat.repository.RepositoryEntry)24 List (java.util.List)22 Identity (org.olat.core.id.Identity)22 BusinessControl (org.olat.core.id.context.BusinessControl)22 LayoutMain3ColsController (org.olat.core.commons.fullWebApp.LayoutMain3ColsController)20 BusinessControlFactory (org.olat.core.id.context.BusinessControlFactory)18 HistoryPoint (org.olat.core.id.context.HistoryPoint)18 CollaborationTools (org.olat.collaboration.CollaborationTools)16 GenericTreeNode (org.olat.core.gui.components.tree.GenericTreeNode)14 UserSession (org.olat.core.util.UserSession)14 CourseNode (org.olat.course.nodes.CourseNode)14 SubscriptionContext (org.olat.core.commons.services.notifications.SubscriptionContext)12 Translator (org.olat.core.gui.translator.Translator)12