Skip to content

Commit

Permalink
fix #546 : modify permission handling
Browse files Browse the repository at this point in the history
  • Loading branch information
marevol committed Jun 17, 2016
1 parent eb31f5a commit 6519636
Showing 1 changed file with 17 additions and 13 deletions.
30 changes: 17 additions & 13 deletions src/main/java/org/codelibs/fess/helper/LabelTypeHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
*/
package org.codelibs.fess.helper;

import static org.codelibs.core.stream.StreamUtil.stream;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
Expand All @@ -23,6 +25,7 @@
import java.util.Map;
import java.util.Set;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;
Expand All @@ -38,8 +41,6 @@
public class LabelTypeHelper {
private static final Logger logger = LoggerFactory.getLogger(LabelTypeHelper.class);

private static final long serialVersionUID = 1L;

@Resource
protected RoleQueryHelper roleQueryHelper;

Expand Down Expand Up @@ -67,7 +68,7 @@ private void buildLabelTypeItems(final List<LabelType> labelTypeList) {
final LabelTypeItem item = new LabelTypeItem();
item.setLabel(labelType.getName());
item.setValue(labelType.getValue());
item.setRoleValueList(labelType.getRoleValueList());
item.setPermissions(labelType.getPermissions());
itemList.add(item);
}
labelTypeItemList = itemList;
Expand All @@ -82,15 +83,18 @@ public List<Map<String, String>> getLabelTypeItemList() {
final Set<String> roleSet = roleQueryHelper.build();
if (roleSet.isEmpty()) {
for (final LabelTypeItem item : labelTypeItemList) {
final Map<String, String> map = new HashMap<>(2);
map.put(Constants.ITEM_LABEL, item.getLabel());
map.put(Constants.ITEM_VALUE, item.getValue());
itemList.add(map);
if (item.getPermissions().length == 0) {
final Map<String, String> map = new HashMap<>(2);
map.put(Constants.ITEM_LABEL, item.getLabel());
map.put(Constants.ITEM_VALUE, item.getValue());
itemList.add(map);
}
}
} else {
for (final LabelTypeItem item : labelTypeItemList) {
final Set<String> permissions = stream(item.getPermissions()).get(stream -> stream.collect(Collectors.toSet()));
for (final String roleValue : roleSet) {
if (item.getRoleValueList().contains(roleValue)) {
if (permissions.contains(roleValue)) {
final Map<String, String> map = new HashMap<>(2);
map.put(Constants.ITEM_LABEL, item.getLabel());
map.put(Constants.ITEM_VALUE, item.getValue());
Expand Down Expand Up @@ -145,7 +149,7 @@ protected static class LabelTypeItem {

private String value;

private List<String> roleValueList;
private String[] permissions;

public String getLabel() {
return label;
Expand All @@ -163,12 +167,12 @@ public void setValue(final String value) {
this.value = value;
}

public List<String> getRoleValueList() {
return roleValueList;
public String[] getPermissions() {
return permissions;
}

public void setRoleValueList(final List<String> roleValueList) {
this.roleValueList = roleValueList;
public void setPermissions(String[] permissions) {
this.permissions = permissions;
}
}

Expand Down

0 comments on commit 6519636

Please # to comment.