/// <summary>
        /// Maps an EF user record from the db into a UserMicroSummary object. If the
        /// db record is null then null is returned.
        /// </summary>
        /// <param name="dbUser">User record from the database.</param>
        public UserMicroSummary Map(User dbUser)
        {
            if (dbUser == null)
            {
                return(null);
            }

            var user = new UserMicroSummary()
            {
                Email     = dbUser.Email,
                FirstName = dbUser.FirstName,
                LastName  = dbUser.LastName,
                UserId    = dbUser.UserId,
                Username  = dbUser.Username
            };

            var userArea = _userAreaRepository.GetByCode(dbUser.UserAreaCode);

            EntityNotFoundException.ThrowIfNull(userArea, dbUser.UserAreaCode);

            user.UserArea = new UserAreaMicroSummary()
            {
                UserAreaCode = dbUser.UserAreaCode,
                Name         = userArea.Name
            };

            return(user);
        }
Beispiel #2
0
        private void ValidatePermission(GetUserSummaryByIdQuery query, IExecutionContext executionContext, UserMicroSummary user)
        {
            if (user == null)
            {
                return;
            }

            if (user.UserArea.UserAreaCode == CofoundryAdminUserArea.AreaCode)
            {
                _permissionValidationService.EnforceCurrentUserOrHasPermission <CofoundryUserReadPermission>(query.UserId, executionContext.UserContext);
            }
            else
            {
                _permissionValidationService.EnforceCurrentUserOrHasPermission <NonCofoundryUserReadPermission>(query.UserId, executionContext.UserContext);
            }
        }