Exemplo n.º 1
0
        protected override void Users_RowSelected(PXCache sender, PXRowSelectedEventArgs e)
        {
            Users user = (Users)e.Row;

            if (user == null)
            {
                return;
            }

            base.Users_RowSelected(sender, e);
            GenerateOneTimeCodes.SetVisible(user.MultiFactorType > 0);
            AllowedRoles.Cache.AllowInsert = false;
            PXDefaultAttribute.SetPersistingCheck <Users.contactID>(sender, user, (user.Guest == true && !Common.Anonymous.IsAnonymous(user.Username)) ? PXPersistingCheck.Null : PXPersistingCheck.Nothing);

            if (user.Source == PXUsersSourceListAttribute.ActiveDirectory)
            {
                string warning = null;
                if (user.OverrideADRoles == true)
                {
                    warning = Messages.IgnoredADRoles;
                }
                else
                {
                    var roles = PXUsersSelectorAttribute.GetADMappedRolesBySID(user.ExtRef);
                    if (roles == null || roles.Count() == 0)
                    {
                        warning = Messages.NoMappedADRoles;
                    }
                }
                PXUIFieldAttribute.SetWarning <Users.overrideADRoles>(sender, user, warning);
            }
            PXUIFieldAttribute.SetEnabled <Users.multiFactorType>(sender, user, user.MultiFactorOverride == true);

            if (user.ContactID == null)
            {
                user.ContactID = PXSelect <Contact, Where <Contact.userID, Equal <Required <Contact.userID> > > >
                                 .SelectSingleBound(this, null, user.PKID)
                                 .RowCast <Contact>()
                                 .FirstOrDefault()?.ContactID;
            }
        }
Exemplo n.º 2
0
        public IEnumerable addADUserOK(PXAdapter adapter)
        {
            ADUser.VerifyRequired();
            ADUserFilter filter = ADUser.Current;
            Users        aduser = PXUsersSelectorAttribute.GetADUserByName(UserList.Cache, filter.Username);

            if (aduser != null)
            {
                PXActiveDirectorySyncMembershipProvider.CheckAndRenameDeletedADUser(aduser.Username, aduser.ExtRef);
                if (adapter.ImportFlag)
                {
                    UserList.Insert(aduser);
                }
                else
                {
                    AccessUsers graph = CreateInstance <AccessUsers>();
                    graph.UserList.Insert(aduser);
                    throw new PXRedirectRequiredException(graph, "New AD User");
                }
            }
            return(adapter.Get());
        }
Exemplo n.º 3
0
        protected virtual IEnumerable ViewDelegate()
        {
            PXCache userCache = _Graph.Caches[typeof(Users)];
            Users   user      = (Users)userCache.Current;

            if (user == null || user.Username == null)
            {
                yield break;
            }

            if (user.Source != PXUsersSourceListAttribute.ActiveDirectory || user.OverrideADRoles == true)             // editable roles for native users
            {
                bool IsUserInserted = userCache.GetStatus(user) == PXEntryStatus.Inserted;

                Dictionary <string, UsersInRoles> assigned = PXSelect <UsersInRoles, Where <UsersInRoles.username, Equal <Current <Users.username> > > > .Select(_Graph).RowCast <UsersInRoles>().ToDictionary(ur => ur.Rolename);

                Dictionary <string, EPLoginTypeAllowsRole> allowed = new Dictionary <string, EPLoginTypeAllowsRole>();
                if (user.LoginTypeID == null)                 // all roles
                {
                    foreach (EPLoginTypeAllowsRole arole in
                             PXSelect <Roles, Where <Roles.guest, Equal <Current <Users.guest> >, Or <Current <Users.guest>, Equal <False> > > > .Select(_Graph).RowCast <Roles>()
                             .Select(r => new EPLoginTypeAllowsRole {
                        Rolename = r.Rolename, IsDefault = false
                    }))
                    {
                        allowed.Add(arole.Rolename, arole);
                        Insert(arole);
                        Cache.IsDirty = false;
                    }
                }
                else                 // from appropriate EPLoginTypeAllowsRole
                {
                    allowed = PXSelectJoin <EPLoginTypeAllowsRole, InnerJoin <Roles, On <EPLoginTypeAllowsRole.rolename, Equal <Roles.rolename> > >,
                                            Where <EPLoginTypeAllowsRole.loginTypeID, Equal <Current <Users.loginTypeID> > > > .Select(_Graph).RowCast <EPLoginTypeAllowsRole>().ToDictionary(ar => ar.Rolename);
                }

                HashSet <string> all = new HashSet <string>(assigned.Keys);
                all.UnionWith(allowed.Keys);

                IUserService         userService  = ServiceLocator.Current.GetInstance <IUserService>();
                IEnumerable <string> allowedRoles = userService.FilterRoles(all);

                foreach (string rolename in allowedRoles.Where(PXAccess.IsRoleEnabled))
                {
                    EPLoginTypeAllowsRole role;
                    allowed.TryGetValue(rolename, out role);

                    UsersInRoles urole;
                    assigned.TryGetValue(rolename, out urole);

                    if (urole != null && role != null)
                    {
                        role.Selected = true;
                        yield return(role);
                    }
                    else if (urole == null && role != null && role.IsDefault == true && (isLoginTypeUpdated || IsUserInserted))                     // add user role
                    {
                        _Graph.Caches[typeof(UsersInRoles)].Insert(new UsersInRoles {
                            Rolename = role.Rolename
                        });
                        role.Selected = true;
                        yield return(role);
                    }
                    else if (urole != null)                     // delete user role
                    {
                        _Graph.Caches[typeof(UsersInRoles)].Delete(urole);
                    }
                    else if (role != null)
                    {
                        role.Selected = false;
                        yield return(role);
                    }
                }
            }
            else             // readonly mapped roles for AD users
            {
                foreach (string role in (PXUsersSelectorAttribute.GetADMappedRolesBySID(user.ExtRef) ?? new string[0]))
                {
                    yield return(new EPLoginTypeAllowsRole {
                        Rolename = role, Selected = true
                    });
                }
            }
        }