public async Task <ActionResult> CreatePolicy([Bind(Include = "role, group")] CreatePolicyModel model) { ActionResult result = null; await Policies.CreatePolicy(model.Role, model.Group, model.Effect); result = Redirect(Request.UrlReferrer.ToString()); return(result); }
public static async Task <Uri> CreateAsync(string domainName, string parentPolicyName, string policyName, List <policySecurity> groups, List <policySecurity> roles) { CreatePolicyModel fromBodyPolicy = new CreatePolicyModel(); fromBodyPolicy.domainName = domainName; fromBodyPolicy.parentPolicyName = parentPolicyName; fromBodyPolicy.policyName = policyName; fromBodyPolicy.groups = groups; fromBodyPolicy.roles = roles; HttpResponseMessage response = await MyClient.client.PostAsJsonAsync("security/policy", fromBodyPolicy); response.EnsureSuccessStatusCode(); return(response.Headers.Location); }
public ActionResult Create(CreatePolicyModel model) { try { var exists = this.AmiClient.GetPolicies(c => c.Oid == model.Oid).CollectionItem.Any(); if (exists) { ModelState.AddModelError("Oid", Locale.OidMustBeUnique); } if (this.ModelState.IsValid) { var policy = this.AmiClient.CreatePolicy(model.ToSecurityPolicyInfo()); TempData["success"] = Locale.PolicyCreatedSuccessfully; return(RedirectToAction("ViewPolicy", new { id = policy.Policy.Key.ToString() })); } } catch (Exception e) { Trace.TraceError($"Unable to create policy: {e}"); } model.GrantsList.Add(new SelectListItem { Text = Locale.Select, Value = "" }); model.GrantsList.Add(new SelectListItem { Text = Locale.Deny, Value = "0" }); model.GrantsList.Add(new SelectListItem { Text = Locale.Elevate, Value = "1" }); model.GrantsList.Add(new SelectListItem { Text = Locale.Grant, Value = "2" }); if (!string.IsNullOrEmpty(model.Grant) && !string.IsNullOrWhiteSpace(model.Grant)) { model.GrantsList = model.GrantsList.Select(g => new SelectListItem { Selected = model.Grant == g.Value, Text = g.Text, Value = g.Value }).ToList(); } TempData["error"] = Locale.UnableToCreatePolicy; return(View(model)); }
public async Task <IActionResult> OnPostAsync(string specificationId) { Guard.IsNullOrWhiteSpace(specificationId, nameof(specificationId)); SpecificationSummary specification = await GetSpecification(specificationId); IsAuthorizedToEdit = await _authorizationHelper.DoesUserHavePermission(User, specification, SpecificationActionTypes.CanEditSpecification); if (!IsAuthorizedToEdit) { return(new ForbidResult()); } if (!string.IsNullOrWhiteSpace(CreatePolicyViewModel.Name)) { ApiResponse <Policy> existingPolicyResponse = await _specsClient.GetPolicyBySpecificationIdAndPolicyName(specificationId, CreatePolicyViewModel.Name); if (existingPolicyResponse.StatusCode != HttpStatusCode.NotFound) { this.ModelState.AddModelError($"{nameof(CreatePolicyViewModel)}.{nameof(CreatePolicyViewModel.Name)}", ValidationMessages.PolicyNameAlreadyExists); } } if (!ModelState.IsValid) { SpecificationName = specification.Name; SpecificationId = specificationId; FundingPeriodName = specification.FundingPeriod.Name; FundingPeriodId = specification.FundingPeriod.Id; return(Page()); } CreatePolicyModel policy = _mapper.Map <CreatePolicyModel>(CreatePolicyViewModel); policy.SpecificationId = specificationId; ApiResponse <Policy> newPolicyResponse = await _specsClient.CreatePolicy(policy); Policy newPolicy = newPolicyResponse.Content; return(Redirect($"/specs/policies/{specificationId}?operationType=PolicyCreated&operationId={newPolicy.Id}")); }
public IHttpActionResult CreatePolicy([FromBody] CreatePolicyModel policy) { if (policy.domainName.Equals(null) || policy.domainName == string.Empty) { return(BadRequest("enter a value for domain name")); } if (policy.policyName.Equals(null) || policy.policyName == string.Empty) { return(BadRequest("enter a value for domain name")); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } long policyId = Storage.createPolicy(policy.domainName, policy.parentPolicyName, policy.policyName, policy.groups, policy.roles); ObjectModel pol = Storage.getObject(policyId); return(CreatedAtRoute("GetPolicy", new { policyId = policyId }, pol)); } //CreatePolicy
public ActionResult Create() { var model = new CreatePolicyModel(); model.GrantsList.Add(new SelectListItem { Text = Locale.Select, Value = "" }); model.GrantsList.Add(new SelectListItem { Text = Locale.Deny, Value = "0" }); model.GrantsList.Add(new SelectListItem { Text = Locale.Elevate, Value = "1" }); model.GrantsList.Add(new SelectListItem { Text = Locale.Grant, Value = "2" }); return(View(model)); }
// Ticket Policies public virtual async Task <TicketOrderModel> PostTicketPolicy(CreatePolicyModel policy) { var url = $"{Urls.ApiUrl(_settings.SandboxEnabled)}/{_settings.ClientId}/ticket-policies/"; var request = new HttpRequestMessage() { RequestUri = new Uri(url), Method = HttpMethod.Post, Content = JsonContent(policy) }; request.Headers.Add("Authorization", GetAuthHeaders()); var response = await _httpClient.SendAsync(request); if (response.IsSuccessStatusCode) { return(JsonConvert.DeserializeObject <TicketOrderModel>(await response.Content.ReadAsStringAsync())); } throw BuildException(response.StatusCode, url, await response.Content.ReadAsStringAsync()); }
private async Task GeneratePolicies(SpecGeneratorConfiguration configuration, Specification specification) { int totalPolices = 1; if (configuration.NumberOfPolices.HasValue && configuration.NumberOfPolices.Value > 0) { totalPolices = configuration.NumberOfPolices.Value; } _logger.Information("Creating {totalPolices} policies for specification", totalPolices); for (int i = 0; i < totalPolices; i++) { int policyNumber = i + 1; CreatePolicyModel policyCreateModel = new CreatePolicyModel() { SpecificationId = specification.Id, Name = $"Policy {policyNumber}", Description = "SpecGenerator", }; await _specsClient.CreatePolicy(policyCreateModel); } }
public async Task <IHttpActionResult> Create([FromBody] CreatePolicyModel model) { if (model.FileIds != null && model.FileIds.Count == 0) { ModelState.AddModelError("fileIds", "files is required"); } if (ModelState.IsValid) { using (IUnitOfWork unitOfWork = UnitOfWork.Create()) { var userId = User.Identity.GetUserId(); var user = unitOfWork.UserRepository.GetAll().FirstOrDefault(u => u.Id == userId); var files = unitOfWork.FileRepository.GetAll().Where(f => model.FileIds.Contains(f.Id)).ToList(); if (files.Count != model.FileIds.Count) { ModelState.AddModelError("fileIds", "files contains wrong file id"); return(JsonError(HttpStatusCode.BadRequest, 10, "Warning", ModelState)); } unitOfWork.BeginTransaction(); foreach (var file in files) { file.IsTemp = false; unitOfWork.FileRepository.Edit(file); } Policy policy = new Policy(); policy.PrePolicyType = model.PrePolicyType; policy.CreatedDate = DateTime.Now; policy.CreatedById = userId; policy.Status = PolicyStatus.Unconfirmed; unitOfWork.PolicyRepository.Insert(policy); await unitOfWork.SaveAsync(); ISchedulerFactory factory = new StdSchedulerFactory(); IScheduler scheduler = factory.GetScheduler(); JobDataMap dataMap = new JobDataMap(); if (!string.IsNullOrEmpty(user.AutopilotContactId)) { dataMap["autopilotContactId"] = user.AutopilotContactId; dataMap["policyauthorId"] = userId; dataMap["OperationType"] = "PolicyLoad"; var job = JobBuilder.Create <UpdateContactJob>() .WithIdentity("UpdateContactJob").UsingJobData(dataMap) .Build(); var jobKey = new JobKey("UpdateContactJob"); ITrigger trigger = TriggerBuilder.Create() .WithIdentity("trigger1") .StartAt(DateTime.Now) .ForJob(jobKey) .Build(); if (!scheduler.CheckExists(jobKey)) { scheduler.ScheduleJob(job, trigger); } scheduler.Start(); } var policyFiles = files.Select(file => new PolicyFile { PolicyId = policy.Id, FileId = file.Id }).ToList(); unitOfWork.PolicyFileRepository.InsertRange(policyFiles); await unitOfWork.SaveAsync(); unitOfWork.CommitTransaction(); var result = new { id = policy.Id }; return(Json(result)); } } else { return(JsonError(HttpStatusCode.BadRequest, 10, "Warning", ModelState)); } }
public Task <ApiResponse <Policy> > CreatePolicy(CreatePolicyModel policy) { Guard.ArgumentNotNull(policy, nameof(policy)); return(PostAsync <Policy, CreatePolicyModel>("policies", policy)); }