Skip to main content
Answer

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

  • August 5, 2022
  • 2 replies
  • 114 views

Joe Schmucker
Captain II
Forum|alt.badge.img+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

Best answer by Joe Schmucker

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;
}
}
}

 

2 replies

Joe Schmucker
Captain II
Forum|alt.badge.img+3
  • Author
  • Captain II
  • Answer
  • August 5, 2022

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;
}
}
}

 


Forum|alt.badge.img+2
  • Acumatica Moderator
  • August 8, 2022

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