Solved

Limit updates to the Tasks screen to the Owner and any Administrator

  • 5 August 2022
  • 2 replies
  • 64 views

Userlevel 6
Badge +3

I’ve never done this...so probably a stupid question…

On the Tasks screen, the customer wants to limit modifications to a task to the person who created the task, or someone in the Administrator role.

What I’ve tried so far it is using the RowUpdating event to catch the update and cancel if not the owner or a user in the admin role.

        protected void _(Events.RowUpdating<CRActivity> e)
        {
            var row = (CRActivity)e.Row;
            var currentUser = CommonServiceLocator.ServiceLocator.Current.GetInstance<ICurrentUserInformationProvider>().GetUserId();

            if (currentUser != row.CreatedByID)
            {
                var listOfRoles = ListRoleRight.GetRoleRightIdentifier(Roles.descr.IsEqual<"Administrator">, Base);

                //if not in admin role, cancel update

            }
        }
 

I was going to try to get a list of roles for the current user and see if it is an admin.  Poked around in Acumatica code to find where it might be done somewhere else that I can copy from.

This line does not compile (obviously), but it’s where I’m at in trying to find a way to do this:

 var listOfRoles = ListRoleRight.GetRoleRightIdentifier(Roles.descr.IsEqual<"Administrator">, Base);

I was going to get a list of roles for the current user and cycle through them to see if the user in in the Administrator role.

Any help you can offer is greatly appreciated.

Thanks,

Joe

icon

Best answer by Joe Schmucker 6 August 2022, 00:46

View original

2 replies

Userlevel 6
Badge +3

Here’s what I ended up with and it seems to work.  I don’t want to flag this as an answer in case I broke one of the Ten Commandments and someone tells me I need to do it differently.  😁

		protected void _(Events.RowSelected<CRActivity> e)
{
var row = (CRActivity)e.Row;
Guid? currentUser = CommonServiceLocator.ServiceLocator.Current.GetInstance<ICurrentUserInformationProvider>().GetUserId();

EPEmployee owner = SelectFrom<EPEmployee>.InnerJoin<BAccount>.On<BAccount.bAccountID.IsEqual<EPEmployee.bAccountID>>
.Where<BAccount.defContactID.IsEqual<@P.AsInt>>.View.Select(Base, row.OwnerID);

if (owner == null || owner.UserID != row.CreatedByID)
{
UsersInRoles usersInRoles = SelectFrom<UsersInRoles>.InnerJoin<Users>
.On<Users.username.IsEqual<UsersInRoles.username>>
.Where<Users.pKID.IsEqual<@P.AsGuid>.And<UsersInRoles.rolename.IsEqual<@P.AsString>>>
.View.Select(Base, currentUser.Value, "Administrator");

if (usersInRoles == null)
{
e.Cache.AllowDelete = false;
e.Cache.AllowUpdate = false;
}
}
}

 

Userlevel 4
Badge +2

wrong place to add my answer. Please ignore this reply.

Reply


About Acumatica ERP system
Acumatica Cloud ERP provides the best business management solution for transforming your company to thrive in the new digital economy. Built on a future-proof platform with open architecture for rapid integrations, scalability, and ease of use, Acumatica delivers unparalleled value to small and midmarket organizations. Connected Business. Delivered.
© 2008 — 2024  Acumatica, Inc. All rights reserved