Skip to content
Open
1 change: 1 addition & 0 deletions src/System Application/App/Agent/Setup/AgentCard.Page.al
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ page 4315 "Agent Card"
Caption = 'Setup';
ToolTip = 'Set up agent';
Image = SetupLines;
Enabled = Rec."Can Curr. User Configure Agent";

trigger OnAction()
begin
Expand Down
64 changes: 10 additions & 54 deletions src/System Application/App/Agent/Setup/AgentImpl.Codeunit.al
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ codeunit 4301 "Agent Impl."
Agent.Insert(true);

if TempAgentAccessControl.IsEmpty() then
GetUserAccess(Agent, TempAgentAccessControl, true);
// If no access control is provided, the server is giving access to the user creating the agent.
GetUserAccess(Agent, TempAgentAccessControl);

AssignCompany(Agent."User Security ID", CompanyName());
AssignDefaultProfile(Agent."User Security ID");
Expand All @@ -54,47 +55,25 @@ codeunit 4301 "Agent Impl."
ChangeAgentState(AgentUserSecurityID, false);
end;

procedure InsertCurrentOwnerIfNoOwnersDefined(var Agent: Record Agent; var AgentAccessControl: Record "Agent Access Control")
begin
SetOwnerFilters(AgentAccessControl);
AgentAccessControl.SetRange("Agent User Security ID", Agent."User Security ID");
if not AgentAccessControl.IsEmpty() then
exit;
InsertCurrentOwner(Agent."User Security ID", AgentAccessControl);
end;

procedure InsertCurrentOwner(AgentUserSecurityID: Guid; var AgentAccessControl: Record "Agent Access Control")
begin
AgentAccessControl."Can Configure Agent" := true;
AgentAccessControl."Agent User Security ID" := AgentUserSecurityID;
AgentAccessControl."User Security ID" := UserSecurityId();
AgentAccessControl.Insert();
end;

procedure GetUserAccess(AgentUserSecurityID: Guid; var TempAgentAccessControl: Record "Agent Access Control" temporary)
var
Agent: Record Agent;
begin
GetAgent(Agent, AgentUserSecurityID);

GetUserAccess(Agent, TempAgentAccessControl, false);
GetUserAccess(Agent, TempAgentAccessControl);
end;

local procedure GetUserAccess(var Agent: Record Agent; var TempAgentAccessControl: Record "Agent Access Control" temporary; InsertCurrentUserAsOwner: Boolean)
local procedure GetUserAccess(var Agent: Record Agent; var TempAgentAccessControl: Record "Agent Access Control" temporary)
var
AgentAccessControl: Record "Agent Access Control";
begin
TempAgentAccessControl.Reset();
TempAgentAccessControl.DeleteAll();

AgentAccessControl.SetRange("Agent User Security ID", Agent."User Security ID");
if AgentAccessControl.IsEmpty() then begin
if not InsertCurrentUserAsOwner then
exit;

InsertCurrentOwnerIfNoOwnersDefined(Agent, TempAgentAccessControl);
if AgentAccessControl.IsEmpty() then
exit;
end;

AgentAccessControl.FindSet();
repeat
Expand Down Expand Up @@ -323,30 +302,12 @@ codeunit 4301 "Agent Impl."

procedure AssignPermissionSets(var UserSecurityID: Guid; var TempAccessControlBuffer: Record "Access Control Buffer" temporary)
var
AccessControl: Record "Access Control";
AgentUtilities: Codeunit "Agent Utilities";
begin
AccessControl.SetRange("User Security ID", UserSecurityID);
if AccessControl.FindSet() then
repeat
if not TempAccessControlBuffer.Get(AccessControl."Company Name", AccessControl.Scope, AccessControl."App ID", AccessControl."Role ID") then
AccessControl.Delete(true);
until AccessControl.Next() = 0;

AccessControl.Reset();
TempAccessControlBuffer.Reset();
if not TempAccessControlBuffer.FindSet() then
exit;

repeat
if not AccessControl.Get(UserSecurityID, TempAccessControlBuffer."Role ID", TempAccessControlBuffer."Company Name", TempAccessControlBuffer.Scope, TempAccessControlBuffer."App ID") then begin
AccessControl."User Security ID" := UserSecurityID;
AccessControl."Role ID" := TempAccessControlBuffer."Role ID";
AccessControl."Company Name" := TempAccessControlBuffer."Company Name";
AccessControl.Scope := TempAccessControlBuffer.Scope;
AccessControl."App ID" := TempAccessControlBuffer."App ID";
AccessControl.Insert();
end;
until TempAccessControlBuffer.Next() = 0;
// Calling system codeunit to allow the assignment of permissions to Agents without SUPER or SECURITY.
// This method ensure that the user has Configure permission for the specified agent in all the companies
// for which permissions are modified (both removed and added).
AgentUtilities.UpdateAccessControl(UserSecurityID, TempAccessControlBuffer);
end;

procedure GetPermissionSets(AgentUserSecurityID: Guid; var TempAccessControlBuffer: Record "Access Control Buffer" temporary)
Expand Down Expand Up @@ -449,11 +410,6 @@ codeunit 4301 "Agent Impl."
Error('');
end;

local procedure SetOwnerFilters(var AgentAccessControl: Record "Agent Access Control")
begin
AgentAccessControl.SetFilter("Can Configure Agent", '%1', true);
end;

procedure ShowNoAgentsAvailableNotification()
var
NoAgentsNotification: Notification;
Expand Down
1 change: 1 addition & 0 deletions src/System Application/App/Agent/Setup/AgentList.Page.al
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ page 4316 "Agent List"
Caption = 'Setup';
ToolTip = 'Set up the agent';
Image = SetupLines;
Enabled = Rec."Can Curr. User Configure Agent";

trigger OnAction()
var
Expand Down
Loading