[Api.HttpPatch] //(MatchAllBodyParameters = false)] public async static Task <IHttpResponse> UpdateAsync( [Property(Name = IntegrationIdPropertyName)] IRef <XIntegration> integrationRef, [Property(Name = AuthorizationPropertyName)] IRef <Authorization> authorizationRef, Api.Azure.AzureApplication application, EastFive.Api.SessionToken security, ContentTypeResponse <XIntegration> onUpdated, NotFoundResponse onNotFound, ForbiddenResponse onForbidden, ReferencedDocumentDoesNotExistsResponse <Authorization> onAuthorizationDoesNotExist, UnauthorizedResponse onUnauthorized) { return(await integrationRef.StorageUpdateAsync( async (integration, saveAsync) => { var accountId = integration.accountId; if (!await application.CanAdministerCredentialAsync(accountId, security)) { return onUnauthorized(); } return await await authorizationRef.StorageGetAsync( async authorization => { if (!await application.ShouldAuthorizeIntegrationAsync(integration, authorization)) { return onForbidden().AddReason("Authorization is not accessable to this account."); } integration.Method = authorization.Method; // method is used in the .mappingId integration.authorization = authorizationRef.Optional(); integration.methodName = await Auth.Method.ById(authorization.Method, application, method => method.name, () => string.Empty); await saveAsync(integration); return onUpdated(integration); }, () => onAuthorizationDoesNotExist().AsTask()); }, () => onNotFound(), onModificationFailures: StorageConstraintUniqueAttribute.ModificationFailure( (XIntegration x) => x.authorization, () => { // TODO: Check if mapping is to this integration and reply already created. return onForbidden().AddReason("Authorization is already in use."); }).AsArray())); }
public async static Task <HttpResponseMessage> CreateAsync( [Property(Name = AccountPropertyName)] Guid accountId, [PropertyOptional(Name = AuthorizationPropertyName)] IRefOptional <Authorization> authorizationRefMaybe, [Resource] XIntegration integration, Api.Azure.AzureApplication application, EastFive.Api.SessionToken security, CreatedResponse onCreated, AlreadyExistsResponse onAlreadyExists, ForbiddenResponse onForbidden, ReferencedDocumentDoesNotExistsResponse <Authorization> onAuthorizationDoesNotExist, GeneralConflictResponse onFailure) { if (!await application.CanAdministerCredentialAsync(accountId, security)) { return(onForbidden()); } return(await await authorizationRefMaybe.StorageGetAsync( async authorization => { if (!await application.ShouldAuthorizeIntegrationAsync(integration, authorization)) { return onFailure("Authorization is not accessable to this account."); } return await CreateWithAuthorization(integration, authorization, () => onCreated(), () => onAlreadyExists(), (why) => onFailure(why)); }, async() => { if (authorizationRefMaybe.HasValue) { return onAuthorizationDoesNotExist(); } return await integration.StorageCreateAsync( (discard) => onCreated(), () => onAlreadyExists()); })); }