Skip to content

Commit

Permalink
fix: improper operator precedence in dto edit role checks with multip…
Browse files Browse the repository at this point in the history
…le role lists
  • Loading branch information
ascott18 committed Jan 17, 2024
1 parent 7a9ddee commit 784aba3
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 11 deletions.
2 changes: 1 addition & 1 deletion playground/Coalesce.Domain/Person.cs
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ public ItemResult ChangeSpacesToDashesInName()
[Coalesce]
public static ItemResult<int> Add(
int numberOne,
[Range(0, 10000)] int numberTwo
[Range(0, 10000)] int numberTwo = 42
)
{
try
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,13 @@ private IEnumerable<string> GetPropertySetterConditional(
string RoleCheck(string role) => $"context.IsInRoleCached(\"{role.EscapeStringLiteralForCSharp()}\")";
string IncludesCheck(string include) => $"includes == \"{include.EscapeStringLiteralForCSharp()}\"";

string roles = string.Join(" && ", permission.RoleLists.Select(rl => string.Join(" || ", rl.Select(RoleCheck))).Distinct());
string roles = string.Join(" && ", permission.RoleLists
.Select(rl => rl.Count == 1
// Only add wrapping parens if we need them:
? RoleCheck(rl.Single())
: "(" + string.Join(" || ", rl.Select(RoleCheck)) + ")"
)
.Distinct());

var includes = string.Join(" || ", property.DtoIncludes.Select(IncludesCheck));
var excludes = string.Join(" || ", property.DtoExcludes.Select(IncludesCheck));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -244,11 +244,6 @@ static string PropValue(ParameterViewModel p, string prefix)
{
if (src.IsPrimaryKey)
{
// TODO This is a bit of a hack, because right now $primaryKey is unfortunately typed without "null",
// and the api clients emit the PK parameters without allowing null.
// After a bit of a refactor that introduced "ParentSourceProp", I'm keeping the generated output here
// the same in order to keep taking advantage of this misfortune until we can add in proper parameter null checking
// and also fix the type of $primaryKey to include null.
return "this.$primaryKey";
}
return $"this.{src.JsVariable}";
Expand Down
2 changes: 1 addition & 1 deletion src/coalesce-vue/src/api-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ import axios, {
} from "axios";

// Re-exports for more convenient imports in generated code.
export { AxiosPromise, AxiosRequestConfig } from "axios";
export type { AxiosPromise, AxiosRequestConfig } from "axios";

/* Api Response Objects */

Expand Down

0 comments on commit 784aba3

Please sign in to comment.