示例#1
0
        /// <summary>
        /// if user is external, then inactivate all %IFU% roles, and if internal, inactivate all %EFU% roles.
        ///
        /// This is double check to avoid wrong scenarios on maximo side
        ///
        ///
        /// </summary>
        /// <param name="user"></param>
        /// <returns></returns>
        public InMemoryUser HandleExternalUser(InMemoryUser user)
        {
            var isExternalUser =
                user.PersonGroups.Any(f => f.PersonGroup.Name.Equals(c.HExternalUser));
            var prefixToInactivate = isExternalUser ? c.InternalRolesPrefix : c.ExternalRolesPrefix;

            if (!isEndUserOrITC(user))
            {
                //not external, nor enduser(with roles), nor itc... user is ordinary enduser!
                prefixToInactivate = c.BaseHapagPrefixNoWildcard;
            }

            foreach (var role in user.Roles)
            {
                var module = _hapagModules.FirstOrDefault(m => m.Value.Name.Equals(role.Name));
                if (module.Key != null && module.Key.StartsWith(prefixToInactivate))
                {
                    Log.WarnFormat("marking role {0} as inactive to user {1}", role.Name, user.Login);
                    role.Active = false;
                }
            }

            if (user.IsInRole(FunctionalRole.Offering.ToString()) && !(user.IsInRole(FunctionalRole.Tom.ToString()) || user.IsInRole(FunctionalRole.Itom.ToString())))
            {
                //offering require either tom or itom, as due to thomas email comments
                user.Roles.First(r => r.Name.EqualsIc(FunctionalRole.Offering.ToString())).Active = false;
            }



            return(user);
        }
示例#2
0
        public UserHlagLocation FillUserLocations(InMemoryUser user, Boolean clearUserCache = false)
        {
            while (_runningJob || _starting)
            {
                //waiting for job to complete
            }


            if (clearUserCache)
            {
                user.Genericproperties.Remove(HapagPersonGroupConstants.HlagLocationProperty);
            }

            if (user.Genericproperties.ContainsKey(HapagPersonGroupConstants.HlagLocationProperty))
            {
                return(user.Genericproperties[HapagPersonGroupConstants.HlagLocationProperty] as UserHlagLocation);
            }


            var resultLocations = new List <HlagLocation>();

            foreach (var personGroupAssociation in user.PersonGroups)
            {
                var @group = personGroupAssociation.PersonGroup;
                if (!HlagLocationUtil.IsALocationGroup(@group))
                {
                    continue;
                }
                if (@group.SuperGroup && !user.IsInRole(FunctionalRole.XItc.GetName()))
                {
                    //if not a XITC FR member, we cannot add supergroup roles, like regions and areas
                    continue;
                }
                if (!HlagLocationsCache.ContainsKey(@group))
                {
                    continue;
                }
                var groupLocations = HlagLocationsCache[@group];
                foreach (var groupLocation in groupLocations)
                {
                    resultLocations.Add(groupLocation);
                }
            }
            var groupedLocations             = BuildGroupedLocations(resultLocations);
            var directGroupedLocations       = BuildGroupedLocations(resultLocations.Where(f => !f.FromSuperGroup));
            var groupedLocationsFromParent   = BuildGroupedLocations(resultLocations.Where(f => f.FromSuperGroup));
            var directGroupLocationsNoPrefix = directGroupedLocations.Select(hlagGroupedLocation => new HlagGroupedLocationsNoPrefixDecorator(hlagGroupedLocation));

            var result1 = new UserHlagLocation {
                Locations                      = new HashSet <HlagLocation>(resultLocations),
                GroupedLocations               = groupedLocations,
                DirectGroupedLocations         = directGroupedLocations,
                DirectGroupedLocationsNoPrefix = new HashSet <HlagGroupedLocationsNoPrefixDecorator>(directGroupLocationsNoPrefix),
                GroupedLocationsFromParent     = groupedLocationsFromParent
            };
            var result = result1;

            user.Genericproperties[HapagPersonGroupConstants.HlagLocationProperty] = result;

            if (user.IsInGroup(HapagPersonGroupConstants.XITC) && !user.Genericproperties.ContainsKey(HapagPersonGroupConstants.HlagLocationXITCProperty))
            {
                //HAP-1017 , for XITC we need to fill the list of "sub" locations so that these job plan actions of them become also available
                //TODO: move to a better place...
                var allGroups  = GetLocationsOfUser(user, true);
                var xitcgroups = new HashSet <string>();
                foreach (var hlagGroupedLocation in allGroups)
                {
                    var descriptions = hlagGroupedLocation.GetGroupDescriptions();
                    foreach (var description in descriptions)
                    {
                        xitcgroups.Add(description);
                    }
                }
                user.Genericproperties[HapagPersonGroupConstants.HlagLocationXITCProperty] = xitcgroups;
            }


            return(result);
        }