Skip to content
Open
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
7 changes: 7 additions & 0 deletions spkl/SparkleXrm.Tasks/CrmPluginRegistrationAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ IsolationModeEnum isolationModel
public ImageTypeEnum Image1Type { get; set; }
public ImageTypeEnum Image2Type { get; set; }
public PluginStepOperationEnum? Action { get; set; }
public string ImpersonationUserName { get; set; }
#endregion

#region Constructor Mandatory Properties
Expand Down Expand Up @@ -239,4 +240,10 @@ public enum StageEnum
PostOperation = 40
}

public static class ImpersonationUserName
{
public const string SYSTEM = "SYSTEM";
public const string CallingUser = "CallingUser";
}

#endif
14 changes: 14 additions & 0 deletions spkl/SparkleXrm.Tasks/CustomAttributeDataEx.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,9 @@ public static CrmPluginRegistrationAttribute CreateFromData(this CustomAttribute
case "Action":
attribute.Action = (PluginStepOperationEnum)namedArgument.TypedValue.Value;
break;
case "ImpersonationUserName":
attribute.ImpersonationUserName = (string)namedArgument.TypedValue.Value;
break;
}
}
return attribute;
Expand Down Expand Up @@ -152,6 +155,16 @@ public static string GetAttributeCode(this CrmPluginRegistrationAttribute attrib
additionalParmeters += indentation + ",Offline = " + attribute.Offline;
if (!attribute.Server)
additionalParmeters += indentation + ",Server = " + attribute.Server;
if (attribute.ImpersonationUserName != null)
{
var impersonationUserName =
string.IsNullOrEmpty(attribute.ImpersonationUserName) ? "ImpersonationUserName.CallingUser" :
attribute.ImpersonationUserName == ImpersonationUserName.SYSTEM ? "ImpersonationUserName.SYSTEM" :
"\"" + attribute.ImpersonationUserName + "\"";

additionalParmeters += indentation + ",ImpersonationUserName = " + impersonationUserName;
}

}
if (attribute.Id != null)
additionalParmeters += indentation + ",Id = \"" + attribute.Id + "\"";
Expand All @@ -168,6 +181,7 @@ public static string GetAttributeCode(this CrmPluginRegistrationAttribute attrib
if (attribute.Action != null)
additionalParmeters += indentation + ",Action = PluginStepOperationEnum." + attribute.Action.ToString();


// determine which template to use
if (targetType == TargetType.Plugin)
{
Expand Down
164 changes: 164 additions & 0 deletions spkl/SparkleXrm.Tasks/EntitiesTrim.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6739,6 +6739,159 @@ public SparkleXrm.Tasks.SolutionComponent Referencingsolutioncomponent_parent_so
}
}

/// <summary>
/// Person with access to the Microsoft CRM system and who owns objects in the Microsoft CRM database.
/// </summary>
[System.Runtime.Serialization.DataContractAttribute()]
[Microsoft.Xrm.Sdk.Client.EntityLogicalNameAttribute("systemuser")]
[System.CodeDom.Compiler.GeneratedCodeAttribute("CrmSvcUtil", "9.1.0.28")]
public partial class SystemUser : Microsoft.Xrm.Sdk.Entity, System.ComponentModel.INotifyPropertyChanging, System.ComponentModel.INotifyPropertyChanged
{

/// <summary>
/// Default Constructor.
/// </summary>
public SystemUser() :
base(EntityLogicalName)
{
}

public const string EntityLogicalName = "systemuser";

public const int EntityTypeCode = 8;

public event System.ComponentModel.PropertyChangedEventHandler PropertyChanged;

public event System.ComponentModel.PropertyChangingEventHandler PropertyChanging;

private void OnPropertyChanged(string propertyName)
{
if ((this.PropertyChanged != null))
{
this.PropertyChanged(this, new System.ComponentModel.PropertyChangedEventArgs(propertyName));
}
}

private void OnPropertyChanging(string propertyName)
{
if ((this.PropertyChanging != null))
{
this.PropertyChanging(this, new System.ComponentModel.PropertyChangingEventArgs(propertyName));
}
}

/// <summary>
/// Active Directory domain of which the user is a member.
/// </summary>
[Microsoft.Xrm.Sdk.AttributeLogicalNameAttribute("domainname")]
public string DomainName
{
get
{
return this.GetAttributeValue<string>("domainname");
}
set
{
this.OnPropertyChanging("DomainName");
this.SetAttributeValue("domainname", value);
this.OnPropertyChanged("DomainName");
}
}

/// <summary>
/// First name of the user.
/// </summary>
[Microsoft.Xrm.Sdk.AttributeLogicalNameAttribute("firstname")]
public string FirstName
{
get
{
return this.GetAttributeValue<string>("firstname");
}
set
{
this.OnPropertyChanging("FirstName");
this.SetAttributeValue("firstname", value);
this.OnPropertyChanged("FirstName");
}
}

/// <summary>
/// Full name of the user.
/// </summary>
[Microsoft.Xrm.Sdk.AttributeLogicalNameAttribute("fullname")]
public string FullName
{
get
{
return this.GetAttributeValue<string>("fullname");
}
set
{
this.OnPropertyChanging("fullname");
this.SetAttributeValue("fullname", value);
this.OnPropertyChanged("fullname");
}
}

/// <summary>
/// Last name of the user.
/// </summary>
[Microsoft.Xrm.Sdk.AttributeLogicalNameAttribute("lastname")]
public string LastName
{
get
{
return this.GetAttributeValue<string>("lastname");
}
set
{
this.OnPropertyChanging("LastName");
this.SetAttributeValue("lastname", value);
this.OnPropertyChanged("LastName");
}
}

/// <summary>
/// Unique identifier for the user.
/// </summary>
[Microsoft.Xrm.Sdk.AttributeLogicalNameAttribute("systemuserid")]
public System.Nullable<System.Guid> SystemUserId
{
get
{
return this.GetAttributeValue<System.Nullable<System.Guid>>("systemuserid");
}
set
{
this.OnPropertyChanging("SystemUserId");
this.SetAttributeValue("systemuserid", value);
if (value.HasValue)
{
base.Id = value.Value;
}
else
{
base.Id = System.Guid.Empty;
}
this.OnPropertyChanged("SystemUserId");
}
}

[Microsoft.Xrm.Sdk.AttributeLogicalNameAttribute("systemuserid")]
public override System.Guid Id
{
get
{
return base.Id;
}
set
{
this.SystemUserId = value;
}
}
}

[System.Runtime.Serialization.DataContractAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("CrmSvcUtil", "9.1.0.28")]
public enum webresource_webresourcetype
Expand Down Expand Up @@ -7468,6 +7621,17 @@ public System.Linq.IQueryable<SparkleXrm.Tasks.SolutionComponent> SolutionCompon
}
}

/// <summary>
/// Gets a binding to the set of all <see cref="SparkleXrm.Tasks.SystemUser"/> entities.
/// </summary>
public System.Linq.IQueryable<SparkleXrm.Tasks.SystemUser> SystemUserSet
{
get
{
return this.CreateQuery<SparkleXrm.Tasks.SystemUser>();
}
}

/// <summary>
/// Gets a binding to the set of all <see cref="SparkleXrm.Tasks.WebResource"/> entities.
/// </summary>
Expand Down
30 changes: 29 additions & 1 deletion spkl/SparkleXrm.Tasks/PluginRegistraton.cs
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,8 @@ private List<SdkMessageProcessingStep> GetExistingSteps(PluginType sdkPluginType
EventHandler = s.EventHandler,
AsyncAutoDelete = s.AsyncAutoDelete,
Attributes = s.Attributes,
SdkMessageFilterId = s.SdkMessageFilterId
SdkMessageFilterId = s.SdkMessageFilterId,
ImpersonatingUserId = s.ImpersonatingUserId
}).ToList();

return steps;
Expand Down Expand Up @@ -458,6 +459,33 @@ private void RegisterStep(PluginType sdkPluginType, List<SdkMessageProcessingSte
// If the attribute was set previously because we used to have an async step, reset it
step.AsyncAutoDelete = false;
}

if (pluginStep.ImpersonationUserName == ImpersonationUserName.CallingUser)
{
step.ImpersonatingUserId = null;
}
else if (pluginStep.ImpersonationUserName == ImpersonationUserName.SYSTEM
|| !string.IsNullOrEmpty(pluginStep.ImpersonationUserName))
{
var impersonationUserSet = (from s in _ctx.CreateQuery<SystemUser>()
where s.FullName == pluginStep.ImpersonationUserName
select s).ToArray();

var impersonationUserRef = impersonationUserSet.FirstOrDefault()?.ToEntityReference();

if (impersonationUserSet.Count() == 0)
{
throw new Exception(string.Format("Plugin step registration impersonation user '{0}' does not exist.", pluginStep.ImpersonationUserName));
}

if (impersonationUserSet.Count() > 1)
{
throw new Exception(string.Format("Plugin step registration impersonation user '{0}' found more that 1.", pluginStep.ImpersonationUserName));
}

step.ImpersonatingUserId = impersonationUserRef;
}

step.Rank = pluginStep.ExecutionOrder;
int stage = 10;
switch (pluginStep.Stage)
Expand Down
3 changes: 3 additions & 0 deletions spkl/SparkleXrm.Tasks/Tasks/DownloadPluginMetadataTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,9 @@ private void AddPluginAttributes(OrganizationServiceContext ctx, CodeParser pars
if (step.Description != null)
attribute.Description = step.Description;

if (step.ImpersonatingUserId != null)
attribute.ImpersonationUserName = step.ImpersonatingUserId != null ? step.ImpersonatingUserId.Name : "";

// Add attribute to code
parser.AddAttribute(attribute, step.plugintypeid_sdkmessageprocessingstep.TypeName);
}
Expand Down
5 changes: 4 additions & 1 deletion spkl/SparkleXrm.Tasks/Tasks/Queries.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ join a in ctx.CreateQuery<PluginAssembly>()
on p.PluginAssemblyId.Id equals a.PluginAssemblyId
join m in ctx.CreateQuery<SdkMessage>()
on s.SdkMessageId.Id equals m.SdkMessageId
join iu in ctx.CreateQuery<SystemUser>()
on s.ImpersonatingUserId.Id equals iu.SystemUserId
where p.TypeName == pluginType
select new SdkMessageProcessingStep
{
Expand All @@ -43,7 +45,8 @@ on s.SdkMessageId.Id equals m.SdkMessageId
{
IsolationMode = a.IsolationMode
}
}
},
ImpersonatingUserId = s.ImpersonatingUserId != null ? new EntityReference(SystemUser.EntityLogicalName, s.ImpersonatingUserId.Id) { Name = iu.FullName }: null
}
).ToList();
}
Expand Down
2 changes: 1 addition & 1 deletion spkl/SparkleXrm.Tasks/spkl.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"earlyboundtypes": [
{
"entities": "pluginassembly,plugintype,solution,webresource,solutioncomponent,sdkmessage,sdkmessagefilter,sdkmessagepair,sdkmessageprocessingstep,sdkmessageprocessingstepimage,sdkmessageprocessingstepsecureconfig,serviceendpoint,customapi",
"entities": "pluginassembly,plugintype,solution,webresource,solutioncomponent,sdkmessage,sdkmessagefilter,sdkmessagepair,sdkmessageprocessingstep,sdkmessageprocessingstepimage,sdkmessageprocessingstepsecureconfig,serviceendpoint,customapi,systemuser",
"generateOptionsetEnums": "true",
"generateStateEnums": "true",
"generateGlobalOptionsets": false,
Expand Down
14 changes: 14 additions & 0 deletions spkl/TestPlugin/PreValidateaccountUpdate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,19 @@ namespace TestPlugin.Plugins
,Image2Attributes = "name,address1_line1"
,Id = "b0a10b53-3788-e711-96d0-00155d380101"
)]
[CrmPluginRegistration("Update",
"account", StageEnum.PostOperation, ExecutionModeEnum.Synchronous,
"name,address1_line1", "Post-Update of account", 1,
IsolationModeEnum.Sandbox
, Image1Type = ImageTypeEnum.PreImage
, Image1Name = "PreImage"
, Image1Attributes = "name,address1_line1"
, Image2Type = ImageTypeEnum.PostImage
, Image2Name = "PostImage"
, Image2Attributes = "name,address1_line1"
, Id = "3d07607c-0dc3-4ddb-b5bb-18e1d659c5b0"
, ImpersonationUserName = ImpersonationUserName.SYSTEM
)]
[CrmPluginRegistration("Create",
"account", StageEnum.PreValidation, ExecutionModeEnum.Synchronous,
"name,address1_line1","Create Step", 1,
Expand All @@ -49,6 +62,7 @@ namespace TestPlugin.Plugins
,Id = "b5a10b53-3788-e711-96d0-00155d380101"
,UnSecureConfiguration = "Some config"
)]

[CrmPluginRegistration("Delete",
"account", StageEnum.PostOperation, ExecutionModeEnum.Synchronous,
"","Delete Step", 1,
Expand Down