Skip to content

Commit

Permalink
Merge pull request #697 from tianlu-root/master
Browse files Browse the repository at this point in the history
fix:storyboard permission bug fix
  • Loading branch information
scottsut authored Jan 27, 2022
2 parents cec6004 + 3ab886a commit df07dbe
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 187 deletions.
2 changes: 1 addition & 1 deletion core/src/main/java/datart/core/base/consts/Const.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public class Const {
public static final String DEFAULT_VARIABLE_QUOTE = "$";
//变量匹配符
public static final Pattern VARIABLE_PATTERN = Pattern.compile("\\$\\S+\\$");

//变量正则模板
public static final String VARIABLE_PATTERN_TEMPLATE = "\\$%s\\$";

/**
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ private static VariablePlaceholder createPlaceholder(SqlDialect sqlDialect, Stri
String variableExpression = tryMatchVariableExpression(sql, variableFragment);

SqlCall sqlCall = parseAsSqlCall(variableExpression, variableFragment);

if (sqlCall == null) {
return new SimpleVariablePlaceholder(variable, sqlDialect, variableFragment);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,35 +55,6 @@ public ReplacementPair replacementPair() {
return new ReplacementPair(originalSqlFragment, formatValue(variable));
}

private String formatValue(ScriptVariable variable) {
switch (variable.getValueType()) {
case NUMERIC:
case KEYWORD:
case SNIPPET:
case FRAGMENT:
case IDENTIFIER:
return formatWithoutQuote(variable.getValues());
default:
return formatWithQuote(variable.getValues());
}
}

private String formatWithoutQuote(Set<String> values) {
if (CollectionUtils.isEmpty(values)) {
return "";
}
return String.join(",", values);
}

private String formatWithQuote(Set<String> values) {
if (CollectionUtils.isEmpty(values)) {
return "";
}
return values.stream().map(SqlSimpleStringLiteral::new)
.map(node -> SqlNodeUtils.toSql(node, sqlDialect))
.collect(Collectors.joining(","));
}

@Override
public int getStartPos() {
return Integer.MAX_VALUE;
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -289,11 +289,40 @@ protected ReplacementPair replaceAsSting() {
Matcher matcher = variablePattern.matcher(originalSqlFragment);
if (matcher.find()) {
String group = matcher.group();
SqlNode sqlNode = SqlNodeUtils.toSingleSqlLiteral(variable, SqlParserPos.ZERO);
replacement = replacement.replace(group, sqlNode.toSqlString(sqlDialect).getSql());
replacement = replacement.replace(group, formatValue(variable));
}
}
return new ReplacementPair(originalSqlFragment, replacement);
}

protected String formatValue(ScriptVariable variable) {
switch (variable.getValueType()) {
case NUMERIC:
case KEYWORD:
case SNIPPET:
case FRAGMENT:
case IDENTIFIER:
return formatWithoutQuote(variable.getValues());
default:
return formatWithQuote(variable.getValues());
}
}

protected String formatWithoutQuote(Set<String> values) {
if (org.springframework.util.CollectionUtils.isEmpty(values)) {
return "";
}
return String.join(",", values);
}

protected String formatWithQuote(Set<String> values) {
if (org.springframework.util.CollectionUtils.isEmpty(values)) {
return "";
}
return values.stream().map(SqlSimpleStringLiteral::new)
.map(node -> SqlNodeUtils.toSql(node, sqlDialect))
.collect(Collectors.joining(","));
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public void requirePermission(Storyboard storyboard, int permission) {
}

private boolean hasPermission(Role role, Storyboard storyboard, int permission) {
if (storyboard.getId() == null || (permission & Const.CREATE) == permission) {
if (storyboard.getId() == null || (permission & Const.CREATE) == Const.CREATE) {
return securityManager.hasPermission(PermissionHelper.vizPermission(storyboard.getOrgId(), role.getId(), ResourceType.STORYBOARD.name(), permission));
} else {
return securityManager.hasPermission(PermissionHelper.vizPermission(storyboard.getOrgId(), role.getId(), storyboard.getId(), permission));
Expand Down

0 comments on commit df07dbe

Please sign in to comment.