Skip to content

Commit

Permalink
Handle empty permissions
Browse files Browse the repository at this point in the history
  • Loading branch information
Zeegaan committed Dec 12, 2024
1 parent 89061f1 commit 3e5d38b
Showing 1 changed file with 22 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,31 @@ public IEnumerable<IPermissionPresentationModel> MapManyAsync(IEnumerable<IGranu

public IEnumerable<IGranularPermission> MapToGranularPermissions(IPermissionPresentationModel permissionViewModel)
{
if (permissionViewModel is DocumentPermissionPresentationModel documentPermissionPresentationModel)
if (permissionViewModel is not DocumentPermissionPresentationModel documentPermissionPresentationModel)
{
foreach (var verb in documentPermissionPresentationModel.Verbs)
yield break;
}

if(documentPermissionPresentationModel.Verbs.Any() is false || (documentPermissionPresentationModel.Verbs.Count == 1 && documentPermissionPresentationModel.Verbs.Contains(string.Empty)))

Check warning on line 50 in src/Umbraco.Cms.Api.Management/Mapping/Permissions/DocumentPermissionMapper.cs

View check run for this annotation

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (v15/dev)

❌ New issue: Complex Conditional

MapToGranularPermissions has 1 complex conditionals with 2 branches, threshold = 2. A complex conditional is an expression inside a branch (e.g. if, for, while) which consists of multiple, logical operators such as AND/OR. The more logical operators in an expression, the more severe the code smell.
{
yield return new DocumentGranularPermission
{
yield return new DocumentGranularPermission
{
Key = documentPermissionPresentationModel.Document.Id,
Permission = verb,
};
Key = documentPermissionPresentationModel.Document.Id,
Permission = string.Empty,
};
yield break;
}
foreach (var verb in documentPermissionPresentationModel.Verbs)
{
if (string.IsNullOrEmpty(verb))
{
continue;
}
yield return new DocumentGranularPermission
{
Key = documentPermissionPresentationModel.Document.Id,
Permission = verb,
};
}
}
}

0 comments on commit 3e5d38b

Please sign in to comment.