public static async Task<IList<string>> CheckRegistrationAuthorization(IRegistrationOwnership registrationOwnership, PackageIdentity packageIdentity) { IList<string> errors = new List<string>(); if (!await registrationOwnership.HasNamespace(packageIdentity.Namespace)) { errors.Add("user is not allowed to publish in this namespace"); return errors; } if (await registrationOwnership.HasRegistration(packageIdentity.Namespace, packageIdentity.Id)) { if (!await registrationOwnership.HasOwner(packageIdentity.Namespace, packageIdentity.Id)) { errors.Add("user does not have access to this registration"); return errors; } if (await registrationOwnership.HasVersion(packageIdentity.Namespace, packageIdentity.Id, packageIdentity.Version.ToString())) { errors.Add("this package version already exists for this registration"); return errors; } } return errors; }
async Task ProcessRequest(IOwinContext context, JObject obj) { string ns = obj["namespace"].ToString(); string id = obj["id"].ToString(); string version = obj["version"].ToString(); JObject content; if (await _registrationOwnership.HasRegistration(ns, id)) { if (await _registrationOwnership.HasOwner(ns, id)) { if (await _registrationOwnership.HasVersion(ns, id, version)) { content = new JObject { { "status", false }, { "message", string.Format("The package version {0}/{1}/{2} already exists", ns, id, version) } }; } else { content = new JObject { { "status", true }, { "message", string.Format("The package identification {0}/{1}/{2} is available and access is permitted", ns, id, version) } }; } } else { content = new JObject { { "status", false }, { "message", string.Format("The current user is not an owner of the package registration {0}/{1}", ns, id) } }; } } else { content = new JObject { { "status", true }, { "message", string.Format("The package identification {0}/{1}/{2} is available and access is permitted", ns, id, version) } }; } await ServiceHelpers.WriteResponse(context, content, HttpStatusCode.OK); }
public static async Task <IList <string> > CheckRegistrationAuthorization(IRegistrationOwnership registrationOwnership, PackageIdentity packageIdentity) { IList <string> errors = new List <string>(); if (await registrationOwnership.HasRegistration(packageIdentity.Namespace, packageIdentity.Id)) { if (!await registrationOwnership.HasOwner(packageIdentity.Namespace, packageIdentity.Id)) { errors.Add("user does not have access to this registration"); return(errors); } if (await registrationOwnership.HasVersion(packageIdentity.Namespace, packageIdentity.Id, packageIdentity.Version.ToString())) { errors.Add("this package version already exists for this registration"); return(errors); } } return(errors); }