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

LC0068: Assert permissions for page extension source table #950

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
3 changes: 3 additions & 0 deletions BusinessCentral.LinterCop.Test/Rule0068.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ public async Task HasDiagnostic(string testCase)
[TestCase("ProcedureCallsInherentPermissionsProperty")]
[TestCase("ProcedureCallsInherentPermissionsAttribute")]
[TestCase("PageSourceTable")]
#if !LessThenSpring2024
[TestCase("PageExtensionSourceTable")]
#endif
#if !LessThenFall2023RV1
[TestCase("ProcedureCallsPermissionsPropertyFullyQualified")]
#endif
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
pageextension 50000 MyPageExtension extends MyPage
{
trigger OnOpenPage()
var
MyTable: Record MyTable;
begin
[|MyTable.FindFirst();|]
[|MyTable.Insert();|]
[|MyTable.Modify();|]
[|MyTable.Delete();|]
end;
}

page 50000 MyPage
{
SourceTable = MyTable;
}

table 50000 MyTable
{
fields
{
field(1; MyField; Integer) { }
}
}
33 changes: 26 additions & 7 deletions BusinessCentral.LinterCop/Design/Rule0068CheckObjectPermission.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,13 +116,8 @@ private void CheckObjectPermission(OperationAnalysisContext ctx)

ITableTypeSymbol targetTable = (ITableTypeSymbol)((IRecordTypeSymbol)variableType).OriginalDefinition;

if (ctx.ContainingSymbol.GetContainingApplicationObjectTypeSymbol()?.NavTypeKind == NavTypeKind.Page)
{
IPropertySymbol? sourceTableProperty = ctx.ContainingSymbol.GetContainingApplicationObjectTypeSymbol()?.GetProperty(PropertyKind.SourceTable);
if (sourceTableProperty is not null)
if (sourceTableProperty.Value == targetTable)
return;
}
if (TargetTableIsPageSourceTable(ctx, targetTable))
return;

if (variableType.ToString().ToLower().EndsWith("temporary") || (targetTable.TableType == TableTypeKind.Temporary)) return;

Expand Down Expand Up @@ -261,4 +256,28 @@ private bool TableHasInherentPermission(ITableTypeSymbol table, char requestedPe

return false;
}

private bool TargetTableIsPageSourceTable(OperationAnalysisContext ctx, ITableTypeSymbol targetTable)
{
var applicationObjectTypeSymbol = ctx.ContainingSymbol.GetContainingApplicationObjectTypeSymbol();
if (applicationObjectTypeSymbol is not null)
{
IPropertySymbol? sourceTableProperty = null;
switch (applicationObjectTypeSymbol.GetNavTypeKindSafe())
{
case NavTypeKind.Page:
sourceTableProperty = applicationObjectTypeSymbol.GetProperty(PropertyKind.SourceTable);
break;
case NavTypeKind.PageExtension:
var extendedPageSymbol = ((IPageExtensionTypeSymbol)applicationObjectTypeSymbol).Target;
if (extendedPageSymbol is not null)
sourceTableProperty = extendedPageSymbol.GetProperty(PropertyKind.SourceTable);
break;
}
if (sourceTableProperty is not null)
if (sourceTableProperty.Value == targetTable)
return true;
}
return false;
}
}