Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix:storyboard permission bug fix #697

Merged
merged 2 commits into from
Jan 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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