public void execute( Context context, Parameters parameters, MVCContext mvcContext, TemplatingContext templatingContext, HttpContext httpContext, CoralSession coralSession) throws ProcessingException { try { long groupId = parameters.getLong("group_id"); RoleResource group = RoleResourceImpl.getRoleResource(coralSession, groupId); long[] roleIds = parameters.getLongs("role_id"); Set<Role> roles = new HashSet<Role>(); for (int i = 0; i < roleIds.length; i++) { roles.add(coralSession.getSecurity().getRole(roleIds[i])); } long[] selectedRoleIds = parameters.getLongs("selected_role_id"); Set<Role> selectedRoles = new HashSet<Role>(); for (int i = 0; i < selectedRoleIds.length; i++) { selectedRoles.add(coralSession.getSecurity().getRole(selectedRoleIds[i])); } RoleImplication[] roleImplications = group.getRole().getImplications(); Set<Role> currentRoles = new HashSet<Role>(); for (RoleImplication ri : roleImplications) { if (ri.getSuperRole().equals(group.getRole())) { currentRoles.add(ri.getSubRole()); } } CoralSession rootCoralSession = sessionFactory.getRootSession(); try { for (Role role : roles) { if (selectedRoles.contains(role)) { if (!currentRoles.contains(role)) { rootCoralSession.getSecurity().addSubRole(group.getRole(), role); } } else { if (currentRoles.contains(role)) { rootCoralSession.getSecurity().deleteSubRole(group.getRole(), role); } } } } finally { rootCoralSession.close(); } templatingContext.put("result", "updated_successfully"); } catch (Exception e) { templatingContext.put("result", "exception"); templatingContext.put("trace", new StackTrace(e)); } }
public boolean checkAccessRights(Context context) throws ProcessingException { CoralSession coralSession = (CoralSession) context.getAttribute(CoralSession.class); RequestParameters parameters = RequestParameters.getRequestParameters(context); try { NavigationNodeResource node = getCmsData(context).getNode(); NavigationNodeResource originalNode = NavigationNodeResourceImpl.getNavigationNodeResource( coralSession, parameters.getLong("original_node_id")); Permission addInboundAlias = coralSession.getSecurity().getUniquePermission("cms.structure.add_inbound_alias"); return node.canAddChild(coralSession, coralSession.getUserSubject()) && coralSession.getUserSubject().hasPermission(originalNode, addInboundAlias); } catch (EntityDoesNotExistException e) { throw new ProcessingException("missing or invalid parameters", e); } }
public boolean checkAccessRights(Context context) throws ProcessingException { Parameters parameters = RequestParameters.getRequestParameters(context); CoralSession coralSession = (CoralSession) context.getAttribute(CoralSession.class); try { long dirId = parameters.getLong("parent_id", -1); if (dirId == -1) { return true; } else { Resource resource = coralSession.getStore().getResource(dirId); Permission permission = coralSession.getSecurity().getUniquePermission("cms.files.write"); return coralSession.getUserSubject().hasPermission(resource, permission); } } catch (Exception e) { logger.error("Subject has no rights to view this screen", e); return false; } }
public boolean checkAccessRights(Context context) throws ProcessingException { CoralSession coralSession = (CoralSession) context.getAttribute(CoralSession.class); try { SiteResource site = getSite(); Role role = null; if (site != null) { CmsData cmsData = cmsDataFactory.getCmsData(context); if (!cmsData.isApplicationEnabled("statistics")) { logger.debug("Application 'statistics' not enabled in site"); return false; } role = site.getAdministrator(); } else { role = coralSession.getSecurity().getUniqueRole("cms.administrator"); } return coralSession.getUserSubject().hasRole(role); } catch (ProcessingException e) { logger.error("Subject has no rights to view this screen", e); return false; } }
public void process( Parameters parameters, MVCContext mvcContext, TemplatingContext templatingContext, HttpContext httpContext, I18nContext i18nContext, CoralSession coralSession) throws ProcessingException { SimpleDateFormat df = new SimpleDateFormat(DateAttributeHandler.DATE_TIME_FORMAT); Resource[] states = coralSession .getStore() .getResourceByPath("/cms/workflow/automata/structure.navigation_node/states/*"); templatingContext.put("states", states); SiteResource site = getSite(); // categories CategoryQueryResourceData queryData = CategoryQueryResourceData.getData(httpContext, null); templatingContext.put("query_data", queryData); Set<Long> expandedCategoriesIds = new HashSet<Long>(); // setup pool data and table data if (queryData.isNew()) { queryData.init(coralSession, null, categoryQueryService, integrationService); // prepare expanded categories - includes inherited ones Map initialState = queryData.getCategoriesSelection().getEntities(coralSession); for (Iterator i = initialState.keySet().iterator(); i.hasNext(); ) { CategoryResource category = (CategoryResource) (i.next()); CategoryResource[] cats = categoryService.getImpliedCategories(category, true); for (int j = 0; j < cats.length; j++) { expandedCategoriesIds.add(cats[j].getIdObject()); } } } else { queryData.update(parameters); } // categories prepareGlobalCategoriesTableTool( coralSession, templatingContext, i18nContext, expandedCategoriesIds, false); prepareSiteCategoriesTableTool( coralSession, templatingContext, i18nContext, expandedCategoriesIds, site, false); templatingContext.put( "category_tool", new CategoryInfoTool(context, integrationService, categoryService)); if (parameters.get("show", "").length() == 0) { return; } CategoryQueryBuilder parsedQuery = new CategoryQueryBuilder( coralSession, queryData.getCategoriesSelection(), queryData.useIdsAsIdentifiers()); templatingContext.put("parsed_query", parsedQuery); Resource state = null; Date validityStart = null; Date validityEnd = null; Date createdStart = null; Date createdEnd = null; Subject creator = null; // prepare the conditions... if (parameters.get("validity_start", "").length() > 0) { validityStart = new Date(parameters.getLong("validity_start")); templatingContext.put("validity_start", validityStart); } if (parameters.get("validity_end", "").length() > 0) { validityEnd = new Date(parameters.getLong("validity_end")); templatingContext.put("validity_end", validityEnd); } if (parameters.get("created_start", "").length() > 0) { createdStart = new Date(parameters.getLong("created_start")); templatingContext.put("created_start", createdStart); } if (parameters.get("created_end", "").length() > 0) { createdEnd = new Date(parameters.getLong("created_end")); templatingContext.put("created_end", createdEnd); } String createdBy = parameters.get("created_by", ""); long stateId = parameters.getLong("selected_state", -1); boolean selectedCategory = false; HashSet<Resource> fromCategorySet = new HashSet<Resource>(); int counter = 0; try { if (stateId != -1) { state = coralSession.getStore().getResource(stateId); templatingContext.put("selected_state", state); } String catQuery = parsedQuery.getQuery(); if (catQuery != null && catQuery.length() > 0) { selectedCategory = true; try { Resource[] docs = categoryQueryService.forwardQuery(coralSession, catQuery); for (Resource doc : docs) { fromCategorySet.add(doc); } } catch (Exception e) { throw new ProcessingException("failed to execute category query", e); } } /** * if (parameters.get("category_id","").length() > 0) { long categoryId = * parameters.getLong("category_id", -1); category = * CategoryResourceImpl.getCategoryResource(coralSession, categoryId); * templatingContext.put("category", category); } */ if (createdBy.length() > 0) { try { String dn = userManager.getUserByLogin(createdBy).getName(); creator = coralSession.getSecurity().getSubject(dn); templatingContext.put("created_by", createdBy); } catch (Exception e) { // do nothing...or maybe report that user is unknown! templatingContext.put("result", "unknown_user"); } } } catch (Exception e) { throw new ProcessingException("Exception occured during query preparation"); } boolean nextCondition = false; StringBuilder sb = new StringBuilder("FIND RESOURCE FROM documents.document_node"); if (site != null) { nextCondition = true; sb.append(" WHERE site = "); sb.append(site.getIdString()); } if (state != null) { if (nextCondition) { sb.append(" AND "); } else { sb.append(" WHERE "); } sb.append("state = " + state.getIdString()); nextCondition = true; } if (creator != null) { if (nextCondition) { sb.append(" AND "); } else { sb.append(" WHERE "); } sb.append("created_by = " + creator.getIdString()); nextCondition = true; } if (validityStart != null) { if (nextCondition) { sb.append(" AND "); } else { sb.append(" WHERE "); } sb.append("validityStart > '" + df.format(validityStart) + "'"); nextCondition = true; } if (validityEnd != null) { if (nextCondition) { sb.append(" AND "); } else { sb.append(" WHERE "); } sb.append("validityStart < '" + df.format(validityEnd) + "'"); nextCondition = true; } if (createdStart != null) { if (nextCondition) { sb.append(" AND "); } else { sb.append(" WHERE "); } sb.append("creation_time > '" + df.format(createdStart) + "'"); nextCondition = true; } if (createdEnd != null) { if (nextCondition) { sb.append(" AND "); } else { sb.append(" WHERE "); } sb.append("creation_time < '" + df.format(createdEnd) + "'"); nextCondition = true; } String query = sb.toString(); templatingContext.put("query", query); try { QueryResults results = coralSession.getQuery().executeQuery(query); List<NavigationNodeResource> nodes = (List<NavigationNodeResource>) results.getList(1); if (selectedCategory) { nodes.retainAll(fromCategorySet); } templatingContext.put("counter", nodes.size()); if (site != null) { Map<Subject, StatisticsItem> statistics = new HashMap<Subject, StatisticsItem>(); for (NavigationNodeResource node : nodes) { updateStatistics(statistics, node); } TableModel<StatisticsItem> model = new ListTableModel<StatisticsItem>( new ArrayList<StatisticsItem>(statistics.values()), new BeanTableColumn<StatisticsItem>( StatisticsItem.class, "subject", new NameComparator(i18nContext.getLocale())), new BeanTableColumn<StatisticsItem>(StatisticsItem.class, "redactorCount"), new BeanTableColumn<StatisticsItem>(StatisticsItem.class, "acceptorCount"), new BeanTableColumn<StatisticsItem>(StatisticsItem.class, "editorCount"), new BeanTableColumn<StatisticsItem>(StatisticsItem.class, "creatorCount")); final Role teamMember = site.getTeamMember(); TableFilter<StatisticsItem> teamMemberFilter = new TableFilter<StatisticsItem>() { @Override public boolean accept(StatisticsItem item) { return item.getSubject().hasRole(teamMember); } }; TableState teamState = tableStateManager.getState(context, getClass().getName() + "$team"); if (teamState.isNew()) { teamState.setSortColumnName("subject"); teamState.setPageSize(0); } List<TableFilter<StatisticsItem>> filters = new ArrayList<TableFilter<StatisticsItem>>(); filters.add(teamMemberFilter); TableTool<StatisticsItem> teamTable = new TableTool<StatisticsItem>(teamState, filters, model); templatingContext.put("teamTable", teamTable); TableState nonTeamState = tableStateManager.getState(context, getClass().getName() + "$nonteam"); if (nonTeamState.isNew()) { nonTeamState.setSortColumnName("subject"); nonTeamState.setPageSize(0); } filters.clear(); filters.add(new InverseFilter<StatisticsItem>(teamMemberFilter)); TableTool<StatisticsItem> nonTeamTable = new TableTool<StatisticsItem>(nonTeamState, filters, model); templatingContext.put("nonTeamTable", nonTeamTable); StatisticsItem teamTotals = new StatisticsItem(null); StatisticsItem nonTeamTotals = new StatisticsItem(null); calculateTotals(statistics, teamMember, teamTotals, nonTeamTotals); templatingContext.put("teamTotals", teamTotals); templatingContext.put("nonTeamTotals", nonTeamTotals); } } catch (Exception e) { throw new ProcessingException("Exception occured during query execution", e); } }