Thursday, October 12, 2023

App Migration - Automated response to share requests for redirected URLs

If anyone has had their IT team decide to start putting the CoE Tookit in place and start dumping your applications into quarantine, then you might benefit from few patterns/tools for migrating applications in a more friendly manner.

When this started in our organization, one of the first things I did was to figure out the best way to communicate with thousands of users on how to point at a new URL.  At least, until "somebody" bothers to follow the process on how to migrate applications across environments and retain the URL.

NOTE: This pattern also works if you just want to move to a new app and deprecate your old one for any reason at all.

The first thing to know is that when applications are "quarantined" (a terrible word btw), this doesn't stop applications from being shared/unshared.  Which is how you can "fix" this problem quickly and w/ minimal trouble for your end-users.

Step 1) Unshare your app

For whatever application you have that is about to be or has been quarantined, simply stop sharing it.

End users will still be able to request access to the application even if the app is quarantined.  This is the key to making this a very automated process.  When they click on the button to have the app shared w/ them, it will send you (the creator) an email.

Step 2) Create a Power Automate to give them the new URL

Create a Power Automate script w/ the When a new Email Arrives (V2) trigger and set the Subject line to be equal to the exact subject you receive when your end users request access.  It should be something along the lines of:  Share request for Power Apps app Disabled - Extra Shift.

The orange highlighted section above will be the name of your application.

This will set up your flow to ONLY fire when you receive an email w/ this exact subject line.


Next, you'll need to parse out the email address from this email.  The email is standard and doesn't vary, so you could do some more direct mappings, but I've done a bit of step-by-step below just to make it more educational.

What we're going to do is split the email body at a location on a string that we know the location of in relation to the email address we need to pull out. Then to do some trim work to pull the email out of the remaining front-half of the Email body.

At a high-level, this is the more readable version of the flow:

Less efficient CPU-wise, more efficient legibility-wise


Step 3) Find the Email Address

The basic trick is to find some unique text to start with that is close to what we want.  In the case of the default emails, ours always have the phrase ") is requesting access to the Power Apps" right after the email address of the individual requesting it.  If we find the location where this phrase starts, then we know where to cut off the Body.



The output from this step will be an integer that represents where this phrase starts in the Email Body.

Next, using the Text - Substring step, get everything before that text:




Again, we are referencing the outputs from the prior step for the Length value.  This cuts the value returned from this step off right at the end of the email address.

For the final string trimming, we're going to find where the open parenthesis exists right before the email address.  Because our string now ends w/ the email address, the lastIndexOf() function can be used to find the last occurrence of an open parenthesis in our string.

Using another Text - Substring step, we'll do some moderately annoying expressions to get what we want.


The code for the Starting Position is:

add(lastIndexOf(outputs('Substring_-_Trimmed_Body')?['body'],'('),1)

This is adding 1 to the location of where the last "(" exists in the string before (because we want everything to start right after that parenthesis).  Note that orange highlighted text should reflect the name of your previous step and might differ from mine.

The code for the Length is:

sub(length(outputs('Substring_-_Trimmed_Body')?['body']),add(lastIndexOf(outputs('Substring_-_Trimmed_Body')?['body'],'('),1))

While this is a big glob of code, you're essentially subtracting the Starting Position code (what we just did in the field above) from the length of the string from the original first Text - Substring step.

It sure would be nice if the Power Automate user interface wasn't a complete dumpster-fire for reading expressions...

Conclusion

This might seem a little convoluted, but it works very well when you have a large # of staff who may not have been notified (or just didn't pay attention) to an app being migrated/moved.  The "quarantine" process by default doesn't include this much more friendly process.  It also doesn't really allow you to capture impacted users.  

If you're wondering how many users' lives have been ruined because somebody decided to play at governance, then you could easily add these to a running SharePoint list and Power BI report of people who were annoyed because of this process change.

As I noted at the start, nothing is stopping you from also using this process anytime you are deprecating an app and/or moving it to a new location.

Any time the staff member requests access to the old deprecated app/link, they'll get an email telling them where to go for the new one (or redirect people to even fill out some kind of form or other process to validate why they need access before granting it).

No comments:

Post a Comment

Because some d-bag is throwing 'bot posts at my blog I've turned on full Moderation. If your comment doesn't show up immediately then that's why.