Exemplo n.º 1
0
        public Task <JsonResult> DeleteUser(
            [HttpTrigger(AuthorizationLevel.Anonymous, "delete", Route = "user")] HttpRequest req,
            [HttpHeader(Name = "Authorization")] HttpParam <string> authorization,
            [DurableClient] IDurableOrchestrationClient jobClient,
            CancellationToken cancellationToken)
        {
            return(exceptionFilter.FilterExceptions(async() =>
            {
                var(userId, _, _) = await auth.ValidateUser(authorization, cancellationToken);

                var jobId = await jobClient.RunSingleton(
                    userId,
                    workflow: nameof(AccountDeletionJob.AccountDeletionWorkflow),
                    jobArguments: new StartAccountDeletionMessage
                {
                    UserId = userId,
                },
                    log,
                    guidFactory);

                return new JsonResult(new UserDeletion
                {
                    JobId = jobId,
                })
                {
                    StatusCode = (int?)HttpStatusCode.Accepted,
                };
            }));
        }
Exemplo n.º 2
0
        public async Task WithingsDeviceNotificationMessage(
            [ServiceBusTrigger(NotificationQueueName, Connection = "SB_CONNECTION_STRING")] string queueItem,
            [DurableClient] IDurableOrchestrationClient jobClient,
            CancellationToken cancellationToken)
        {
            var message = json.Load <CallbackReceivedMessage>(queueItem);

            var consent = await consentStore.FetchConsentByExternalId(converter.System, message.WithingsUserId.ToString(), cancellationToken);

            if (consent == null)
            {
                log.LogWarning("Skipping Withings notification for unknown user: withingsUserId={withingsUserId}", message.WithingsUserId);
                return;
            }

            await jobClient.RunSingleton(
                consent.UserId,
                workflow : nameof(WithingsDeviceNotificationWorkflow),
                jobArguments : new StartNotificationIngestionMessage
            {
                UserId         = consent.UserId,
                StartDateEpoch = message.StartDateEpoch,
                EndDateEpoch   = message.EndDateEpoch,
            },
                log,
                guidFactory,
                blocking : true);
        }
Exemplo n.º 3
0
        public Task <JsonResult> CreateOrUpdateUser(
            [HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = "user")] HttpRequest req,
            [HttpBody(Required = true)] HttpParam <UserDto> userDto,
            [HttpHeader(Name = "Authorization")] HttpParam <string> authorization,
            [DurableClient] IDurableOrchestrationClient jobClient,
            CancellationToken cancellationToken)
        {
            return(exceptionFilter.FilterExceptions(async() =>
            {
                var connectedDevices = userDto.Value.ConnectedDevices ?? Array.Empty <Identifier>();
                var disconnectedDevices = userDto.Value.DisconnectedDevices ?? Array.Empty <Identifier>();
                var mobileDevice = userDto.Value.MobileDevice;

                var(userId, givenName, familyName) = await auth.ValidateUser(authorization, cancellationToken);
                var consent = await consentStore.FetchConsent(userId, cancellationToken);
                consent ??= ConsentFactory.WithId(userId);

                var statusCode = HttpStatusCode.NoContent;
                var jobId = (string?)null;

                if (consent.FhirId == null)
                {
                    var patient = await fhirClient.CreatePatient(userId, familyName, givenName, cancellationToken);
                    consent.FhirId = patient.Id;
                    statusCode = HttpStatusCode.OK;
                }

                if (mobileDevice != null)
                {
                    consent.MobileDevices.Add(mobileDevice);
                    statusCode = HttpStatusCode.OK;
                }

                if (connectedDevices.Length > 0 || disconnectedDevices.Length > 0)
                {
                    consent.Devices.RemoveAll(disconnectedDevices.Contains);
                    consent.Devices.AddRange(connectedDevices);
                    statusCode = HttpStatusCode.Accepted;
                }

                if (statusCode != HttpStatusCode.NoContent)
                {
                    await consentStore.WriteConsent(consent, cancellationToken);
                }

                if (connectedDevices.Length > 0 || disconnectedDevices.Length > 0)
                {
                    jobId = await jobClient.RunSingleton(
                        userId,
                        workflow: nameof(DeviceImportJob.DeviceImportWorkflow),
                        jobArguments: new StartDeviceManagementMessage
                    {
                        UserId = userId,
                        ConnectedDevices = connectedDevices,
                        DisconnectedDevices = disconnectedDevices,
                    },
                        log,
                        guidFactory);
                }

                return new JsonResult(await userFactory.CreateUser(consent, jobId, cancellationToken))
                {
                    StatusCode = (int?)statusCode,
                };
            }));
        }