Пример #1
0
        public async Task Delete(IOwinContext context)
        {
            Trace.TraceInformation("DeleteImpl.Upload");

            if (!_registrationOwnership.IsAuthenticated)
            {
                await ServiceHelpers.WriteErrorResponse(context, "user does not have access to the service", HttpStatusCode.Forbidden);

                return;
            }

            if (!await _registrationOwnership.HasTenantEnabled())
            {
                await ServiceHelpers.WriteErrorResponse(context, "package publication has not been enabled in this tenant", HttpStatusCode.Forbidden);

                return;
            }

            PublicationVisibility publicationVisibility;

            if (!PublicationVisibility.TryCreate(context, out publicationVisibility))
            {
                await ServiceHelpers.WriteErrorResponse(context, "specify either organization OR subscription NOT BOTH", HttpStatusCode.BadRequest);

                return;
            }

            Stream packageStream = context.Request.Body;

            //  validation

            ValidationResult validationResult = await Validate(packageStream);

            if (validationResult.HasErrors)
            {
                await ServiceHelpers.WriteErrorResponse(context, validationResult.Errors, HttpStatusCode.BadRequest);

                return;
            }

            //  registration authorization

            IList <string> authorizationErrors = await OwnershipHelpers.CheckRegistrationAuthorizationForEdit(_registrationOwnership, validationResult.PackageIdentity);

            if (authorizationErrors.Count > 0)
            {
                await ServiceHelpers.WriteErrorResponse(context, authorizationErrors, HttpStatusCode.Forbidden);

                return;
            }

            Trace.TraceInformation("DELETE Processing package {0}/{1}/{2}", validationResult.PackageIdentity.Namespace, validationResult.PackageIdentity.Id, validationResult.PackageIdentity.Version);

            //  process delete

            //  (1) gather all the publication details

            PublicationDetails publicationDetails = await OwnershipHelpers.CreatePublicationDetails(_registrationOwnership, publicationVisibility);

            Trace.TraceInformation("CreatePublicationDetails");

            //  (2) add the new item to the catalog

            Uri catalogAddress = await AddToCatalog(validationResult.PackageIdentity, publicationDetails);

            Trace.TraceInformation("AddToCatalog");

            //  (3) update the registration ownership record

            await UpdateRegistrationOwnership(validationResult.PackageIdentity);

            Trace.TraceInformation("UpdateRegistrationOwnership");

            //  (4) create response

            JToken response = new JObject
            {
                { "catalog", catalogAddress.ToString() }
            };

            await ServiceHelpers.WriteResponse(context, response, HttpStatusCode.OK);
        }