示例#1
0
        /// <summary>
        /// Use this to get a user context for the system user, useful
        /// if you need to impersonate the user to perform an action with elevated
        /// privileges
        /// </summary>
        public async Task <IUserContext> GetSystemUserContextAsync()
        {
            // Grab the first super admin user.
            var dbUser = await QuerySystemUser().FirstOrDefaultAsync();

            EntityNotFoundException.ThrowIfNull(dbUser, SpecialistRoleTypeCodes.SuperAdministrator);
            var impersonatedUserContext = _userContextMapper.Map(dbUser);

            return(impersonatedUserContext);
        }
示例#2
0
        /// <summary>
        /// Use this to get a user context for the system user, useful
        /// if you need to impersonate the user to perform an action with elevated
        /// privileges.
        /// </summary>
        public async Task <IUserContext> GetSystemUserContextAsync()
        {
            // BUG: Got a managed debugging assistant exception? Try this:
            // https://developercommunity.visualstudio.com/content/problem/29782/managed-debugging-assistant-fatalexecutionengineer.html

            // Grab the first super admin user.
            var dbUser = await QuerySystemUser().FirstOrDefaultAsync();

            EntityNotFoundException.ThrowIfNull(dbUser, SuperAdminRole.SuperAdminRoleCode);
            var impersonatedUserContext = _userContextMapper.Map(dbUser);

            return(impersonatedUserContext);
        }
        private async Task <ExecutionContext> GetImpersonatedUserContext(IExecutionContext executionContext, int userId)
        {
            var dbUser = await _dbContext
                         .Users
                         .FilterByUserArea(CofoundryAdminUserArea.AreaCode)
                         .FilterById(userId)
                         .SingleOrDefaultAsync();

            EntityNotFoundException.ThrowIfNull(dbUser, userId);
            var impersonatedUserContext = _userContextMapper.Map(dbUser);

            var impersonatedExecutionContext = new ExecutionContext()
            {
                ExecutionDate = executionContext.ExecutionDate,
                UserContext   = impersonatedUserContext
            };

            return(impersonatedExecutionContext);
        }