SimpleDocument fillDocument(Node node, String lang) throws RepositoryException { SimpleDocumentPK pk = new SimpleDocumentPK( node.getIdentifier(), getStringProperty(node, SLV_PROPERTY_INSTANCEID)); long oldSilverpeasId = getLongProperty(node, SLV_PROPERTY_OLD_ID); pk.setOldSilverpeasId(oldSilverpeasId); String language = lang; if (language == null) { language = I18NHelper.defaultLanguage; } SimpleAttachment file = getAttachment(node, language); if (file == null) { Iterator<String> iter = I18NHelper.getLanguages(); while (iter.hasNext() && file == null) { file = getAttachment(node, iter.next()); } } SimpleDocument doc = new SimpleDocument( pk, getStringProperty(node, SLV_PROPERTY_FOREIGN_KEY), getIntProperty(node, SLV_PROPERTY_ORDER), getBooleanProperty(node, SLV_PROPERTY_VERSIONED), getStringProperty(node, SLV_PROPERTY_OWNER), getDateProperty(node, SLV_PROPERTY_RESERVATION_DATE), getDateProperty(node, SLV_PROPERTY_ALERT_DATE), getDateProperty(node, SLV_PROPERTY_EXPIRY_DATE), getStringProperty(node, SLV_PROPERTY_COMMENT), file); doc.setRepositoryPath(node.getPath()); doc.setCloneId(getStringProperty(node, SLV_PROPERTY_CLONE)); doc.setMajorVersion(getIntProperty(node, SLV_PROPERTY_MAJOR)); doc.setMinorVersion(getIntProperty(node, SLV_PROPERTY_MINOR)); doc.setStatus(getStringProperty(node, SLV_PROPERTY_STATUS)); doc.setDocumentType(DocumentType.fromFolderName(node.getParent().getName())); String nodeName = node.getName(); if ("jcr:frozenNode".equals(nodeName)) { nodeName = doc.computeNodeName(); doc.setNodeName(nodeName); if (!node.getSession().nodeExists(doc.getFullJcrPath())) { nodeName = SimpleDocument.VERSION_PREFIX + doc.getOldSilverpeasId(); } } doc.setNodeName(nodeName); doc.setPublicDocument(!doc.isVersioned() || doc.getMinorVersion() == 0); // Forbidden download for roles String forbiddenDownloadForRoles = getStringProperty(node, SLV_PROPERTY_FORBIDDEN_DOWNLOAD_FOR_ROLES); if (StringUtil.isDefined(forbiddenDownloadForRoles)) { doc.addRolesForWhichDownloadIsForbidden(SilverpeasRole.listFrom(forbiddenDownloadForRoles)); } return doc; }
public Collection<Reply> getRepliesForQuestion(long id) throws QuestionReplyException { SilverpeasRole role = SilverpeasRole.valueOf(userProfil); switch (role) { case user: return getPublicRepliesForQuestion(id); case publisher: return getPrivateRepliesForQuestion(id); case writer: case admin: return getAllRepliesForQuestion(id); } return new ArrayList<Reply>(); }
/* * Recupère la liste des questions selon le profil de l'utilisateur courant */ public Collection<Question> getQuestions() throws QuestionReplyException { SilverpeasRole role = SilverpeasRole.valueOf(userProfil); switch (role) { case user: return getUserQuestions(); case writer: return getWriterQuestions(); case publisher: return getPublisherQuestions(); case admin: return getAdminQuestions(); } return new ArrayList<Question>(); }
/** * Maps a classic Silverpeas role to a JSPWiki role. JSPWiki roles are defined in jspwiki.policy * with their permissions. * * @param userRole the silverpeas role. * @return the JSPWiki corresponding Role. */ protected Role convertSilverpeasRole(String userRole) { SilverpeasRole role = SilverpeasRole.valueOf(userRole); switch (role) { case admin: return new Role("Administrator"); case publisher: case writer: return new Role("Contributor"); case user: return new Role("Reader"); default: return Role.AUTHENTICATED; } }
@Override protected void fillUserRoles( Set<SilverpeasRole> userRoles, AccessControlContext context, String userId, String componentId) { // Personal space or user tool if (componentId == null || getOrganisationController().isToolAvailable(componentId)) { userRoles.add(SilverpeasRole.admin); return; } if (Admin.ADMIN_COMPONENT_ID.equals(componentId)) { if (getOrganisationController().getUserDetail(userId).isAccessAdmin()) { userRoles.add(SilverpeasRole.admin); } return; } ComponentInst componentInst = getOrganisationController().getComponentInst(componentId); if (componentInst == null) { return; } if (componentInst.isPublic() || StringUtil.getBooleanValue( getOrganisationController().getComponentParameterValue(componentId, "publicFiles"))) { userRoles.add(SilverpeasRole.user); if (!CollectionUtils.containsAny( AccessControlOperation.PERSIST_ACTIONS, context.getOperations()) && !context.getOperations().contains(AccessControlOperation.download)) { // In that case, it is not necessary to check deeper the user rights return; } } if (getOrganisationController().isComponentAvailable(componentId, userId)) { Set<SilverpeasRole> roles = SilverpeasRole.from(getOrganisationController().getUserProfiles(userId, componentId)); // If component is available, but user has no rights -> public component if (roles.isEmpty()) { userRoles.add(SilverpeasRole.user); } else { userRoles.addAll(roles); } } }
/** * Adding or removing the [slv:forbiddenDownloadForRoles] optional property. * * @param document * @param documentNode * @throws RepositoryException */ protected void setForbiddenDownloadForRolesOptionalNodeProperty( SimpleDocument document, Node documentNode) throws RepositoryException { if (CollectionUtil.isNotEmpty(document.getForbiddenDownloadForRoles())) { // Adding the mixin (no impact when it is already existing) documentNode.addMixin(SLV_DOWNLOADABLE_MIXIN); addStringProperty( documentNode, SLV_PROPERTY_FORBIDDEN_DOWNLOAD_FOR_ROLES, SilverpeasRole.asString(document.getForbiddenDownloadForRoles())); } else { // Removing the mixin if (documentNode.hasProperty(SLV_PROPERTY_FORBIDDEN_DOWNLOAD_FOR_ROLES)) { documentNode.removeMixin(SLV_DOWNLOADABLE_MIXIN); } } }
public SilverpeasRole getUserRole() { return SilverpeasRole.valueOf(this.userProfil); }