コード例 #1
0
        public async Task Execute(int serviceId, UserClaims userClaims)
        {
            if (userClaims.UserRole == "Admin")
            {
                LambdaLogger.Log($"User role is admin, delete serviceId {serviceId}");
                await _servicesGateway.DeleteService(serviceId).ConfigureAwait(false);
            }
            else
            {
                var service = await _servicesGateway.GetServiceAsync(serviceId).ConfigureAwait(false);

                var user = await _usersGateway.GetUserByIdAsync(userClaims.UserId).ConfigureAwait(false);

                var orgs = user.UserOrganisations.Where(x => x.OrganisationId == service.OrganisationId).ToList();
                if (orgs.Count == 0)
                {
                    LambdaLogger.Log($"UserId {userClaims.UserId} is not in Organisation {service.OrganisationId} for serviceId {serviceId}");
                    throw new UseCaseException
                          {
                              UserErrorMessage = $"Could not delete service with an ID of '{serviceId}'",
                          };
                }
                else
                {
                    LambdaLogger.Log($"UserId {userClaims.UserId} is in Organisation {service.OrganisationId} for serviceId {serviceId} so service can be deleted");
                    await _servicesGateway.DeleteService(serviceId).ConfigureAwait(false);
                }
            }
        }
コード例 #2
0
        public async Task <UserResponse> Execute(int userId)
        {
            var userDomain = await _usersGateway.GetUserByIdAsync(userId).ConfigureAwait(false);

            if (userDomain == null)
            {
                throw new UseCaseException()
                      {
                          UserErrorMessage = $"Could not retrieve a user with an ID of '{userId}'",
                      }
            }
            ;
            var userStatus   = _authenticateGateway.GetUserStatus(userDomain.Email);
            var userResponse = userDomain.ToResponse();

            userResponse.SetPasswordRequired = userStatus == null || userStatus == "FORCE_CHANGE_PASSWORD";
            return(userResponse);
        }