public ActionResult Edit(string uuid, string action, SimpleMetadataViewModel model, string ignoreValidationError) { ViewBag.IsAdmin = "0"; string role = GetSecurityClaim("role"); if (!string.IsNullOrWhiteSpace(role) && role.Equals("nd.metadata_admin")) { ViewBag.IsAdmin = "1"; } if (ModelState.IsValid) { SaveMetadataToCswServer(model); if (action.Equals(UI.Button_Validate)) { ValidateMetadata(uuid); } return(RedirectToAction("Edit", new { uuid = model.Uuid })); } else { string messages = string.Join("; ", ModelState.Values .SelectMany(x => x.Errors) .Select(x => x.ErrorMessage)); Log.Debug("Model for " + uuid + " is not valid: " + messages); } PrepareViewBagForEditing(model); return(View(model)); }
public ActionResult Edit(string uuid) { if (string.IsNullOrWhiteSpace(uuid)) { return(HttpNotFound()); } try { SimpleMetadataViewModel model = _metadataService.GetMetadataModel(uuid); string role = GetSecurityClaim("role"); if (HasAccessToMetadata(model)) { PrepareViewBagForEditing(model); return(View(model)); } else { TempData["failure"] = "Du har ikke tilgang til å redigere disse metadataene"; return(View("Error")); } } catch (Exception e) { //Log.Error("Error while getting metadata with uuid = " + uuid, e); throw new Exception("Error while getting metadata with uuid = " + uuid, e); //TempData["failure"] = "Feilmelding: " + e.Message; //return View("Error"); } }
private void PrepareViewBagForEditing(SimpleMetadataViewModel model) { ViewBag.MaintenanceFrequencyValues = new SelectList(GetListOfMaintenanceFrequencyValues(), "Key", "Value", model.MaintenanceFrequency); ViewBag.CreateProductSheetUrl = System.Web.Configuration.WebConfigurationManager.AppSettings["ProductSheetGeneratorUrl"] + model.Uuid; ViewBag.DatasetUrl = System.Web.Configuration.WebConfigurationManager.AppSettings["DownloadDatasetUrl"]; ViewBag.GeoNetworkViewUrl = GeoNetworkUtil.GetViewUrl(model.Uuid); ViewBag.GeoNetworkXmlDownloadUrl = GeoNetworkUtil.GetXmlDownloadUrl(model.Uuid); var seoUrl = new SeoUrl("", model.Title); ViewBag.KartkatalogViewUrl = System.Web.Configuration.WebConfigurationManager.AppSettings["KartkatalogUrl"] + "Metadata/" + seoUrl.Title + "/" + model.Uuid; ViewBag.predefinedDistributionProtocols = new SelectList(GetListOfpredefinedDistributionProtocols(), "Key", "Value"); Dictionary <string, string> OrganizationList = GetListOfOrganizations(); if (string.IsNullOrEmpty(model.ContactMetadata.Organization)) { if (Request.Form["ContactMetadata.Organization.Old"] != null || !string.IsNullOrWhiteSpace(Request.Form["ContactMetadata.Organization.Old"])) { model.ContactMetadata.Organization = Request.Form["ContactMetadata.Organization.Old"].ToString(); } } if (string.IsNullOrEmpty(model.ContactPublisher.Organization)) { if (Request.Form["ContactPublisher.Organization.Old"] != null || !string.IsNullOrWhiteSpace(Request.Form["ContactPublisher.Organization.Old"])) { model.ContactPublisher.Organization = Request["ContactPublisher.Organization.Old"].ToString(); } } if (string.IsNullOrEmpty(model.ContactOwner.Organization)) { if (Request.Form["ContactOwner.Organization.Old"] != null || !string.IsNullOrWhiteSpace(Request.Form["ContactOwner.Organization.Old"])) { model.ContactOwner.Organization = Request["ContactOwner.Organization.Old"].ToString(); } } ViewBag.OrganizationContactMetadataValues = new SelectList(OrganizationList, "Key", "Value", model.ContactMetadata.Organization); ViewBag.OrganizationContactPublisherValues = new SelectList(OrganizationList, "Key", "Value", model.ContactPublisher.Organization); ViewBag.OrganizationContactOwnerValues = new SelectList(OrganizationList, "Key", "Value", model.ContactOwner.Organization); ViewBag.NationalThemeValues = new SelectList(GetListOfNationalTheme(), "Key", "Value"); ViewBag.NationalInitiativeValues = new SelectList(GetListOfNationalInitiative(), "Key", "Value"); ViewBag.InspireValues = new SelectList(GetListOfInspire(), "Key", "Value"); ViewBag.UseConstraintValues = new SelectList(GetListOfRestrictionValues(), "Key", "Value", model.UseConstraints); ViewBag.LicenseTypesValues = new SelectList(GetListOfLicenseTypes(), "Key", "Value", model.OtherConstraintsLink); ViewBag.ValideringUrl = System.Web.Configuration.WebConfigurationManager.AppSettings["ValideringUrl"] + "api/metadata/" + model.Uuid; ViewBag.Municipalities = new KomDataService().GetListOfMunicipalityOrganizations(); }
private bool HasAccessToMetadata(SimpleMetadataViewModel model) { string organization = GetSecurityClaim("organization"); string role = GetSecurityClaim("role"); bool isAdmin = !string.IsNullOrWhiteSpace(role) && role.Equals("nd.metadata_admin"); return(isAdmin || model.HasAccess(organization)); }
private void SaveMetadataToCswServer(SimpleMetadataViewModel model) { try { _metadataService.SaveMetadataModel(model, GetUsername()); TempData["success"] = UI.Metadata_Edit_Saved_Success; } catch (Exception e) { Log.Error("Error while editing metadata with uuid = " + model.Uuid, e); TempData["failure"] = String.Format(UI.Metadata_Edit_Saved_Failure, e.Message); } }
public ActionResult Delete(string uuid) { SimpleMetadataViewModel model = _metadataService.GetMetadataModel(uuid); string role = GetSecurityClaim("role"); if (HasAccessToMetadata(model)) { _metadataService.DeleteMetadata(uuid, GetUsername()); TempData["Message"] = "Metadata med uuid " + uuid + " ble slettet."; return(RedirectToAction("Index")); } else { return(new HttpUnauthorizedResult()); } }
public ActionResult ConfirmDelete(string uuid) { if (string.IsNullOrWhiteSpace(uuid)) { return(HttpNotFound()); } SimpleMetadataViewModel model = _metadataService.GetMetadataModel(uuid); string role = GetSecurityClaim("role"); if (HasAccessToMetadata(model)) { return(View(model)); } else { return(new HttpUnauthorizedResult()); } }
private void SendNotification(string uuid) { SimpleMetadataViewModel meta = _metadataService.GetMetadataModel(uuid); var environment = System.Web.Configuration.WebConfigurationManager.AppSettings["EnvironmentName"]; if (!string.IsNullOrEmpty(environment)) { environment = "." + environment; } var url = "https://editor" + environment + ".geonorge.no/Metadata/Edit?uuid=" + meta.Uuid; var message = new MailMessage(); message.To.Add(new MailAddress(System.Web.Configuration.WebConfigurationManager.AppSettings["WebmasterEmail"])); message.From = new MailAddress(System.Web.Configuration.WebConfigurationManager.AppSettings["WebmasterEmail"]); message.Subject = "Enkle metadata - opplastet dataset"; StringBuilder b = new StringBuilder(); b.Append(meta.Title + " er lastet opp.<br/>\r\n"); b.Append("<a href=\"" + url + "\">" + url + "</a>."); message.Body = b.ToString(); message.IsBodyHtml = true; using (var smtp = new SmtpClient()) { smtp.Host = System.Web.Configuration.WebConfigurationManager.AppSettings["SmtpHost"]; try { smtp.Send(message); Log.Info("Send email to:" + message.To.ToString()); Log.Info("Subject:" + message.Subject); Log.Info("Body:" + message.Body); } catch (Exception excep) { Log.Error(excep.Message); Log.Error(excep.InnerException); } } }