When working with data and layers from ArcGIS Portal, users must be signed in to create new versions, perform edits, and post new changes. Given that each user has a specific role within the organization, it is crucial to ensure the correct user is signed in before any operations are performed. Currently, there is no straightforward Pythonic method for this validation. Implementing such a validation method would allow developers to ensure that the correct user is signed in and has the necessary permissions to edit the data even before starting an editing session.
This idea came to me after reading a community question. In response, I suggested a workaround using the role value returned from the arcpy.GetPortalInfo function.
My suggested idea is to add the username as a key in the output dictionary of GetPortalInfo. This way, developers can build tools that works only if a user is signed-in.
Another suggested method is to retrieve the user information from the ArcGISProject object in the arcpy.mp module. For example:
from arcpy.mp import ArcGISProject
my_project = ArcGISProject('current')
#option1
current_user:str = my_project.loggedUser
#option2
condition: bool = my_project.isUserLogged