Codeunit 8933 View If All Related Records, source in 26
Source242526272829metadata in 26
src/System Application/App/Email/src/Email/View Policy/Policies/ViewIfAllRelatedRecords.Codeunit.al101 lines, Copyright (c) Microsoft Corporation. MIT
// ------------------------------------------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.
// ------------------------------------------------------------------------------------------------
namespace System.Email;
using System.Security.AccessControl;
/// <summary>
/// Email policy that show emails to a given user,
/// if that user has access to all of the related records on the email.
/// </summary>
codeunit 8933 "View If All Related Records" implements "Email View Policy"
{
Access = Internal;
InherentPermissions = X;
InherentEntitlements = X;
Permissions = tabledata "Email Related Record" = r,
tabledata "Sent Email" = r,
tabledata "Email Outbox" = r;
procedure GetSentEmails(var SentEmails: Record "Sent Email" temporary)
var
SentEmailsQuery: Query "Sent Emails";
begin
SentEmailsQuery.GetSentEmailsIfAccessToAllRelatedRecords(SentEmails);
end;
procedure GetOutboxEmails(var EmailOutbox: Record "Email Outbox" temporary)
var
OutboxEmailsQuery: Query "Outbox Emails";
begin
OutboxEmailsQuery.GetOutboxEmailsIfAccessToAllRelatedRecords(EmailOutbox);
end;
procedure GetSentEmails(SourceTableId: Integer; var SentEmails: Record "Sent Email" temporary)
var
EmailViewPolicy: Codeunit "Email View Policy";
begin
EmailViewPolicy.GetSentEmailsBasedOnRelatedRecords(Format(SourceTableId), '', Enum::"Email View Policy"::AllRelatedRecordsEmails, SentEmails);
end;
procedure GetOutboxEmails(SourceTableId: Integer; var EmailOutbox: Record "Email Outbox" temporary)
var
EmailViewPolicy: Codeunit "Email View Policy";
begin
EmailViewPolicy.GetEmailOutboxBasedOnRelatedRecords(Format(SourceTableId), '', Enum::"Email View Policy"::AllRelatedRecordsEmails, EmailOutbox);
end;
procedure GetSentEmails(SourceTableId: Integer; SourceSystemId: Guid; var SentEmails: Record "Sent Email" temporary)
var
EmailViewPolicy: Codeunit "Email View Policy";
begin
EmailViewPolicy.GetSentEmailsBasedOnRelatedRecords(Format(SourceTableId), Format(SourceSystemId), Enum::"Email View Policy"::AllRelatedRecordsEmails, SentEmails);
end;
procedure GetOutboxEmails(SourceTableId: Integer; SourceSystemId: Guid; var EmailOutbox: Record "Email Outbox" temporary)
var
EmailViewPolicy: Codeunit "Email View Policy";
begin
EmailViewPolicy.GetEmailOutboxBasedOnRelatedRecords(Format(SourceTableId), Format(SourceSystemId), Enum::"Email View Policy"::AllRelatedRecordsEmails, EmailOutbox);
end;
procedure HasAccess(SentEmail: Record "Sent Email"): Boolean;
begin
exit(HasAccess(SentEmail."Message Id", SentEmail."User Security Id"));
end;
procedure HasAccess(EmailOutbox: Record "Email Outbox"): Boolean;
begin
exit(HasAccess(EmailOutbox."Message Id", EmailOutbox."User Security Id"));
end;
internal procedure HasAccess(MessageId: Guid; UserSecurityId: Guid): Boolean
var
EmailRelatedRecord: Record "Email Related Record";
RecordRef: RecordRef;
begin
if UserSecurityId = UserSecurityId() then // Owner always has access
exit(true);
// Intentionally disregard relations to the Users table as every user has access to it
EmailRelatedRecord.SetFilter("Table Id", '<>%1', Database::User);
EmailRelatedRecord.SetFilter("Email Message Id", MessageId);
if EmailRelatedRecord.FindSet() then begin
repeat
RecordRef.Open(EmailRelatedRecord."Table Id");
if not RecordRef.ReadPermission() then begin
RecordRef.Close();
exit(false);
end;
RecordRef.Close();
until EmailRelatedRecord.Next() = 0;
exit(true);
end;
exit(false);
end;
}