Esempio n. 1
0
  /**
   * @throws SDataException
   * @throws RepositoryException
   */
  public CHSNodeMap(ContentEntity n, int depth, ResourceDefinition rp) throws SDataException {
    String lock = ContentHostingService.AUTH_RESOURCE_HIDDEN;
    sessionManager = Kernel.sessionManager();
    entityManager = Kernel.entityManager();
    String userId = sessionManager.getCurrentSessionUserId();
    String reference = n.getReference();
    Reference referenceObj = entityManager.newReference(reference);
    Collection<?> groups = referenceObj.getAuthzGroups();

    boolean canSeeHidden = Kernel.securityService().unlock(userId, lock, reference, groups);

    if (!canSeeHidden && !n.isAvailable()) {
      throw new SDataAccessException(403, "Permission denied on item");
    }
    contentHostingService = Kernel.contentHostingService();
    authZGroupService = Kernel.authzGroupService();
    depth--;
    put("mixinNodeType", getMixinTypes(n));
    put("properties", getProperties(n));
    put("name", getName(n));
    if (rp != null) {
      put("path", rp.getExternalPath(n.getId()));
    }
    put("permissions", getPermissions(n));

    if (n instanceof ContentResource) {
      put("primaryNodeType", "nt:file");
      addFile((ContentResource) n);
    } else {
      put("primaryNodeType", "nt:folder");
      addFolder((ContentCollection) n, rp, depth);
    }
  }
  /**
   * Implementation of command pattern. Will be called by ScheduledInvocationManager for delayed
   * announcement notifications
   *
   * @param opaqueContext reference (context) for message
   */
  public void execute(String opaqueContext) {
    // get the message
    final Reference ref = entityManager.newReference(opaqueContext);

    // needed to access the message
    enableSecurityAdvisorToGetAnnouncement();

    final AnnouncementMessage msg = (AnnouncementMessage) ref.getEntity();
    final AnnouncementMessageHeader hdr = (AnnouncementMessageHeader) msg.getAnnouncementHeader();

    // read the notification options
    final String notification = msg.getProperties().getProperty("notificationLevel");

    int noti = NotificationService.NOTI_OPTIONAL;
    if ("r".equals(notification)) {
      noti = NotificationService.NOTI_REQUIRED;
    } else if ("n".equals(notification)) {
      noti = NotificationService.NOTI_NONE;
    }

    final Event delayedNotificationEvent =
        eventTrackingService.newEvent("annc.schInv.notify", msg.getReference(), true, noti);
    //		eventTrackingService.post(event);

    NotificationEdit notify = notificationService.addTransientNotification();

    super.notify(notify, delayedNotificationEvent);

    // since we build the notification by accessing the
    // message within the super class, can't remove the
    // SecurityAdvisor until this point
    // done with access, need to remove from stack
    disableSecurityAdvisor();
  }
Esempio n. 3
0
  private Map<String, String> getPermissions(ContentEntity n) throws SDataException {
    Map<String, String> map = new HashMap<String, String>();

    if (n instanceof ContentCollection) {
      map.put("read", String.valueOf(contentHostingService.allowGetCollection(n.getId())));
      map.put("remove", String.valueOf(contentHostingService.allowRemoveCollection(n.getId())));
      map.put("write", String.valueOf(contentHostingService.allowUpdateCollection(n.getId())));

      String ref = n.getReference();

      Reference reference = entityManager.newReference(n.getReference());
      if (log.isDebugEnabled()) {
        log.debug("Got Reference " + reference + " for " + n.getReference());
      }

      Collection<?> groups = reference.getAuthzGroups();
      String user = sessionManager.getCurrentSessionUserId();
      map.put(
          "admin",
          String.valueOf(
              authZGroupService.isAllowed(
                  sessionManager.getCurrentSessionUserId(),
                  AuthzGroupService.SECURE_UPDATE_AUTHZ_GROUP,
                  groups)));
    } else {
      map.put("read", String.valueOf(contentHostingService.allowGetResource(n.getId())));
      map.put("remove", String.valueOf(contentHostingService.allowRemoveResource(n.getId())));
      map.put("write", String.valueOf(contentHostingService.allowUpdateResource(n.getId())));
    }
    return map;
  }
 /** get announcement group information */
 private String getAnnouncementGroup(AnnouncementMessage a) {
   if (a.getProperties().getProperty(ResourceProperties.PROP_PUBVIEW) != null
       && a.getProperties()
           .getProperty(ResourceProperties.PROP_PUBVIEW)
           .equals(Boolean.TRUE.toString())) {
     return rb.getString("Public");
   } else if (a.getAnnouncementHeader().getAccess().equals(MessageHeader.MessageAccess.CHANNEL)) {
     return rb.getString("Allgroups");
   } else {
     int count = 0;
     String allGroupString = "";
     try {
       Site site = siteService.getSite(entityManager.newReference(a.getReference()).getContext());
       for (Iterator i = a.getAnnouncementHeader().getGroups().iterator(); i.hasNext(); ) {
         Group aGroup = site.getGroup((String) i.next());
         if (aGroup != null) {
           count++;
           if (count > 1) {
             allGroupString = allGroupString.concat(", ").concat(aGroup.getTitle());
           } else {
             allGroupString = aGroup.getTitle();
           }
         }
       }
     } catch (IdUnusedException e) {
       // No site available.
     }
     return allGroupString;
   }
 }
  @Override
  protected String plainTextContent(Event event) {
    StringBuilder buf = new StringBuilder();
    String newline = "\n\r";

    // get the message
    Reference ref = entityManager.newReference(event.getResource());
    AnnouncementMessage msg = (AnnouncementMessage) ref.getEntity();
    AnnouncementMessageHeader hdr = (AnnouncementMessageHeader) msg.getAnnouncementHeader();

    // use either the configured site, or if not configured, the site (context) of the resource
    String siteId = (getSite() != null) ? getSite() : ref.getContext();

    String url = ServerConfigurationService.getPortalUrl() + "/site/" + siteId;

    // get a site title
    String title = siteId;
    try {
      Site site = siteService.getSite(siteId);
      title = site.getTitle();
    } catch (Exception ignore) {

    }

    // Now build up the message text.
    if (AnnouncementService.SECURE_ANNC_ADD.equals(event.getEvent())) {
      buf.append(
          FormattedText.convertFormattedTextToPlaintext(
              rb.getFormattedMessage("noti.header.add", new Object[] {title, url})));

    } else {
      buf.append(
          FormattedText.convertFormattedTextToPlaintext(
              rb.getFormattedMessage("noti.header.update", new Object[] {title, url})));
    }

    buf.append(" " + rb.getString("at_date") + " ");
    buf.append(hdr.getDate().toStringLocalFull());
    buf.append(newline);
    buf.append(FormattedText.convertFormattedTextToPlaintext(msg.getBody()));
    buf.append(newline);

    // add any attachments
    List attachments = hdr.getAttachments();
    if (attachments.size() > 0) {
      buf.append(newline + rb.getString("Attachments") + newline);
      for (Iterator iAttachments = attachments.iterator(); iAttachments.hasNext(); ) {
        Reference attachment = (Reference) iAttachments.next();
        String attachmentTitle =
            attachment.getProperties().getPropertyFormatted(ResourceProperties.PROP_DISPLAY_NAME);
        buf.append(attachmentTitle + ": " + attachment.getUrl() + newline);
      }
    }

    return buf.toString();
  }
Esempio n. 6
0
  public ContentResource wrap(final ContentResource content) {
    if (!isFiltered(content)) {
      return content;
    }
    Reference contentRef = entityManager.newReference(content.getReference());
    Reference siteRef = entityManager.newReference(contentRef.getContext());
    Entity entity = siteRef.getEntity();

    String addHtml = content.getProperties().getProperty(ResourceProperties.PROP_ADD_HTML);

    String skinRepo = getSkinRepo();
    String siteSkin = getSiteSkin(entity);

    final boolean detectHtml = addHtml == null || addHtml.equals("auto");
    String title = getTitle(content);
    final String header = MessageFormat.format(headerTemplate, skinRepo, siteSkin, title);
    final String footer = footerTemplate;

    return new WrappedContentResource(content, header, footer, detectHtml);
  }
  /** @inheritDoc */
  public void notify(Notification notification, Event event) {
    // get the message
    Reference ref = entityManager.newReference(event.getResource());
    AnnouncementMessageEdit msg = (AnnouncementMessageEdit) ref.getEntity();
    AnnouncementMessageHeader hdr = (AnnouncementMessageHeader) msg.getAnnouncementHeader();

    // do not do notification for hidden (draft) messages
    if (hdr.getDraft()) return;

    // Put here since if release date after now, do not notify
    // since scheduled notification has been set.
    Time now = timeService.newTime();

    if (now.after(hdr.getDate())) {
      super.notify(notification, event);
    }
  }
  /**
   * Format the announcement notification subject line.
   *
   * @param event The event that matched criteria to cause the notification.
   * @return the announcement notification subject line.
   */
  protected String getSubject(Event event) {
    // get the message
    Reference ref = entityManager.newReference(event.getResource());
    AnnouncementMessage msg = (AnnouncementMessage) ref.getEntity();
    AnnouncementMessageHeader hdr = (AnnouncementMessageHeader) msg.getAnnouncementHeader();

    // use either the configured site, or if not configured, the site (context) of the resource
    String siteId = (getSite() != null) ? getSite() : ref.getContext();

    // get a site title
    String title = siteId;
    try {
      Site site = siteService.getSite(siteId);
      title = site.getTitle();
    } catch (Exception ignore) {
    }

    // use the message's subject
    return rb.getFormattedMessage("noti.subj", new Object[] {title, hdr.getSubject()});
  }
 private String getSiteReference(String siteContext) {
   final Reference ref = entityManager.newReference(siteService.siteReference(siteContext));
   return ref.getReference();
 }
  /**
   * Format the announcement notification from address.
   *
   * @param event The event that matched criteria to cause the notification.
   * @return the announcement notification from address.
   */
  protected String getFromAddress(Event event) {
    Reference ref = entityManager.newReference(event.getResource());

    // SAK-14831, yorkadam, make site title reflected in 'From:' name instead of default
    // ServerConfigurationService.getString("ui.service", "Sakai");
    String siteId = (getSite() != null) ? getSite() : ref.getContext();
    String title = "";
    try {
      Site site = siteService.getSite(siteId);
      title = site.getTitle();
    } catch (Exception ignore) {
    }

    String userEmail =
        ServerConfigurationService.getString(
            "setup.request", "no-reply@" + ServerConfigurationService.getServerName());
    String userDisplay = ServerConfigurationService.getString("ui.service", "Sakai");
    // String no_reply = "From: \"" + userDisplay + "\" <" + userEmail + ">";
    // String no_reply_withTitle = "From: \"" + title + "\" <" + userEmail + ">";
    String from = "From: Sakai"; // fallback value
    if (title != null && !title.equals("")) {
      from = "From: \"" + title + "\" <" + userEmail + ">";
    } else {
      String fromVal = getFrom(event); // should not return null but better safe than sorry
      if (fromVal != null) {
        from = fromVal;
      }
    }

    // get the message
    AnnouncementMessage msg = (AnnouncementMessage) ref.getEntity();
    String userId = msg.getAnnouncementHeader().getFrom().getId();

    // checks if "from" email id has to be included? and whether the notification is a delayed
    // notification?. SAK-13512
    // SAK-20988 - emailFromReplyable@org.sakaiproject.event.api.NotificationService is deprecated
    boolean notificationEmailFromReplyable =
        ServerConfigurationService.getBoolean("notify.email.from.replyable", false);
    if (notificationEmailFromReplyable && from.contains("no-reply@") && userId != null) {
      try {
        User u = userDirectoryService.getUser(userId);
        userDisplay = u.getDisplayName();
        userEmail = u.getEmail();
        if ((userEmail != null) && (userEmail.trim().length()) == 0) userEmail = null;

      } catch (UserNotDefinedException e) {
        M_log.warn(
            "Failed to load user from announcement header: "
                + userId
                + ". Will send from no-reply@"
                + ServerConfigurationService.getServerName()
                + " instead.");
      }

      // some fallback positions
      if (userEmail == null)
        userEmail =
            ServerConfigurationService.getString(
                "setup.request", "no-reply@" + ServerConfigurationService.getServerName());
      if (userDisplay == null)
        userDisplay = ServerConfigurationService.getString("ui.service", "Sakai");
      from = "From: \"" + userDisplay + "\" <" + userEmail + ">";
    }

    return from;
  }