AdhocAdam / smletsexchangeconnector

SMLets PowerShell based Exchange Connector for controlling Microsoft System Center Service Manager 2016+
https://adhocadam.github.io/smletsexchangeconnector/
GNU General Public License v3.0
29 stars 19 forks source link

Improve Manual Activity actions #145

Closed AdhocAdam closed 4 years ago

AdhocAdam commented 5 years ago

The SMLets Exchange Connector has logic to ensure only the Activity Implementer can Complete/Skip a Manual Activity whereas the stock Exchange Connector allows action against a Manual Activity to be performed by anybody.

https://github.com/AdhocAdam/smletsexchangeconnector/blob/55e24b3cd2d5ab0cbb9341d67bd463b248a10b36/smletsExchangeConnector.ps1#L1538-L1583

Per an observation raised in the Cireson Community, there should be a change + enhancement to this process:

  1. Remove the current restriction around the Implementer being the only person being able to control the MA so it aligns with the stock Microsoft Exchange Connector.
  2. Since anyone can perform an action, enhance the process by setting the Activity Implementer to the person who performed the action. In doing so, reporting/auditing against work is more accurately reflected.

This however means the following elseif above would become irrelevant:

 #not from the Activity Implementer, add to the MA Notes 
 elseif (($activityImplementerSMTP.TargetAddress -ne $message.From)) 
 { 
     Set-SCSMObject -SMObject $workItem -PropertyHashtable @{"Notes" = "$($workItem.Notes)$($activityImplementer.Name) @ $(get-date): $commentToAdd `n"} @scsmMGMTParams 
 } 

Thus, all emails sent to an MA that lacked keywords would always be appended to the Parent Work Item as opposed to current functionality, wherein someone who isn't the Implementer has their Notes written into the MA.

AdhocAdam commented 4 years ago

After some review, it looks as though it's possible to preserve current functionality and support this enhancement through an elseif order of operations. To test this, flip which $activityImplementerSMTP variable is used and change the $commentToAdd variable to include (or not include) keywords. All conditions continue to function and only a single condition is ever hit.

#variables
#$activityImplementerSMTP = "tom@test.lcl"
$activityImplementerSMTP = "adam@test.lcl"
$messageFrom = "adam@test.lcl"
$commentToAdd = "i will this"

#keywords
$completedKeyword = "completed"
$skipKeyword = "skipped"
$takeKeyword = "take"
$takeRequiresGroupMembership = $false

#take, distilled version from the connector
switch -Regex ($commentToAdd) 
{ 
    "\[$takeKeyword]" {  
        if ($takeRequiresGroupMembership -eq $false) { 
            write-output "Switch: Taken by someone"
        } 
        else { 
            #TODO: Send an email to let them know it failed? 
        } 
    } 
} 

#manual activity conditions
#completed, implementer
if (($activityImplementerSMTP -eq $messageFrom) -and ($commentToAdd -match "\[$completedKeyword]")) 
{ 
    write-output "Match: Completed. Same"
}
#completed, anyone
elseif (($activityImplementerSMTP -ne $messageFrom) -and ($commentToAdd -match "\[$completedKeyword]")) 
{ 
    write-output "Match: Completed by Someone"
}
#skipped, implementer
elseif (($activityImplementerSMTP -eq $messageFrom) -and ($commentToAdd -match "\[$skipKeyword]")) 
{ 
    write-output "Match: Skip. Same"
}
#skipped, anyone
elseif (($activityImplementerSMTP -ne $messageFrom) -and ($commentToAdd -match "\[$skipKeyword]")) 
{ 
    write-output "Match: Skipped by Someone"
}
#not from the Activity Implementer, add to the MA Notes 
elseif (($activityImplementerSMTP -ne $messageFrom) -and (($commentToAdd -notmatch "\[$completedKeyword]") -and ($commentToAdd -notmatch "\[$skipKeyword]") -and ($commentToAdd -notmatch "\[$takeKeyword]") )) 
{ 
    write-output "Add to MA Notes. Someone."
} 
#no keywords, add to the Parent Work Item 
elseif (($activityImplementerSMTP -eq $messageFrom) -and (($commentToAdd -notmatch "\[$completedKeyword]") -and ($commentToAdd -notmatch "\[$skipKeyword]") -and ($commentToAdd -notmatch "\[$takeKeyword]") )) 
{ 
    write-output "Leave a comment on the Parent Work Item. Same."
}
AdhocAdam commented 4 years ago

Alternatively, instead of if/elseif blocks - this could serve as the opportunity to align the MA portion of Update-WorkItem with that of the Change Request block where a switch is used to test the Sender against Assignee.

AdhocAdam commented 4 years ago

Relating over to #156 and #157

AdhocAdam commented 4 years ago

In the original description seen at the top, point 2:

Since anyone can perform an action, enhance the process by setting the Activity Implementer to the person who performed the action. In doing so, reporting/auditing against work is more accurately reflected.

Upon further thought, this feels more like a genuine change in an internal org process, rather than a pure enhancement for the connector. While I can't think of a reason this isn't advantageous (assuming take regardless of action), I'm not sure others would feel the same way just yet.

However a lesser known feature of the connector since it's very first version has been support for multiple keywords in a single email. So it's actually already and will continue to be possible to do something like...

I'll [take] this for myself and mark it as [completed]

In either case, the next release makes it possible for someone who isn't the Implementer to control an MA just like the stock connector.