public JsonResult Valdate(string justification, string ports, SimplePortDirectionTypeConstant?direction, PortTypeConstant?portType)
        {
            var errors = new Dictionary <string, string>();
            var ret    = _portFactory.Validate(ports);

            if (!ret.IsValid)
            {
                errors.Add("ports", $"The ports entered were not valid.  The valid configuration is {ret.Ports.ToPortString()}");
            }
            if (!_justificationFactory.IsValidText(justification))
            {
                errors.Add("justification", "The Justifcation cannot be empty whitespace.");
            }

            if (!direction.HasValue)
            {
                errors.Add("direction", "You must choose a direction");
            }

            if (!portType.HasValue)
            {
                errors.Add("portType", "You must choose a type");
            }

            if (errors.Count == 0)
            {
                return(Json(JsonEnvelope.Success()));
            }

            return(Json(JsonEnvelope.Error(errors)));
        }
Beispiel #2
0
        public JsonResult Save(Guid?id, Guid?assignedToId, ActionItemPriorityConstants?priority, DateTime?due, string text)
        {
            var errors = new Dictionary <string, string>();

            if (due == null)
            {
                errors.Add("due", "Due Date is required");
            }

            if (string.IsNullOrWhiteSpace(text))
            {
                errors.Add("text", "Test is required");
            }

            if (assignedToId == null)
            {
                errors.Add("assignedToName", "Assigned to is required");
            }

            if (errors.Count > 0)
            {
                return(Json(JsonEnvelope.Error(errors)));
            }

            _todoService.Save(id, assignedToId.GetValueOrDefault(), priority.GetValueOrDefault(ActionItemPriorityConstants.Normal), due.GetValueOrDefault(), text);
            return(Json(JsonEnvelope.Success()));
        }
        public async Task <JsonResult> Save(PlatformConstant id, long specId, long?justificationId, SimplePortDirectionTypeConstant direction, PortTypeConstant portType,
                                            string justification, string ports)
        {
            if (!_justificationFactory.IsValidText(justification))
            {
                return(Json(JsonEnvelope.Error("The Justifcation cannot be empty whitespace.")));
            }

            if (!justificationId.HasValue)
            {
                Logger.LogInformation($"{UserSecurity.SamAccountName} added a new justification for ports: {justification}");
                justificationId =
                    await _justificationFactory.AddJustification(JustificationTypeConstant.Port, specId, justification);
            }
            else
            {
                Logger.LogInformation($"{UserSecurity.SamAccountName} updated justification {justificationId} for ports: {justification}");
                await _justificationFactory.UpdateJustification(justificationId.Value, justification);
            }

            await _portFactory.AddOrUpdatePorts(specId, justificationId.Value, direction == SimplePortDirectionTypeConstant.PortListeningToOutsideTraffic, direction == SimplePortDirectionTypeConstant.SendingTrafficToOusidePort, portType, ports);

            Logger.LogInformation($"{UserSecurity.SamAccountName} added or updated ports for spec {specId} ports are: {ports}");
            return(Json(JsonEnvelope.Success(new { url = Url.PartialOnePort(id, specId, justificationId.Value) })));
        }
Beispiel #4
0
        public async Task <JsonResult> Save(TInfo info)
        {
            if (info == null)
            {
                return(Json(JsonEnvelope.Error("No data passed in to save.")));
            }

            var errors = info.Validate();

            if (errors.Count > 0)
            {
                return(Json(JsonEnvelope.Error(errors)));
            }

            if (!await SpecFactory.IsUnique(info))
            {
                errors.Add("name", "The Specification Name has already been used.  Please change the name and try again.");
                return(Json(JsonEnvelope.Error(errors)));
            }

            await SpecFactory.AddOrUpdate(info);

            LogSave(info);
            return(Json(JsonEnvelope.Success(new { id = info.Id })));
        }
Beispiel #5
0
        public async Task <JsonResult> Delete(long id)
        {
            string reason = await SpecFactory.Delete(id, UserSecurity);

            if (reason == null)
            {
                LogDelete(id);
                return(Json(JsonEnvelope.Success()));
            }
            return(Json(JsonEnvelope.Error(reason)));
        }
        public async Task <JsonResult> Save(long id, string name, string description, bool?nonCore, PciScopeConstant[] pciScope, int[] environmentIds)
        {
            if (!_packageFactory.IsValidName(name))
            {
                return(Json(JsonEnvelope.Error("The Name cannot be empty whitespace.")));
            }

            await _packageFactory.SaveSoftwareComponent(id, name?.Trim(), description?.Trim(), nonCore.GetValueOrDefault(), pciScope, environmentIds);

            Logger.LogInformation($"Software Component {id} updated by {UserSecurity.SamAccountName} with name {name}");
            return(Json(JsonEnvelope.Success(new { url = Url.PartialGetPackage(id) })));
        }
        public async Task <JsonResult> Add(JustificationTypeConstant id, long specId, string text)
        {
            if (!_justificationFactory.IsValidText(text))
            {
                return(Json(JsonEnvelope.Error("The Justifcation cannot be empty whitespace.")));
            }

            var newid = await _justificationFactory.AddJustification(id, specId, text);

            Logger.LogInformation($"Justification {newid} added by {UserSecurity.SamAccountName} with text: {text}");

            return(Json(JsonEnvelope.Success(new { url = Url.PartialGetJustification(newid) })));
        }
        public async Task <JsonResult> Update(long id, string text)
        {
            if (!_justificationFactory.IsValidText(text))
            {
                return(Json(JsonEnvelope.Error("The Justifcation cannot be empty whitespace.")));
            }

            await _justificationFactory.UpdateJustification(id, text);

            Logger.LogInformation($"Justification {id} updated by {UserSecurity.SamAccountName} with new text: {text}");

            return(Json(JsonEnvelope.Success()));
        }
        /// <summary>
        /// 404 Not Found
        /// </summary>
        public ActionResult NotFound(Exception error)
        {
            Response.StatusCode = (int)HttpStatusCode.NotFound;

            if (Request.IsAjaxRequest())
            {
                Response.ContentType = "application/json";
                return(JsonEnvelope.Error("Resource not found."));
            }
            else
            {
                Response.ContentType = "text/html";
                return(View());
            }
        }
        /// <summary>
        /// 500 Internal Server Error
        /// </summary>
        public ActionResult InternalServerError(Exception error)
        {
            Response.StatusCode = (int)HttpStatusCode.InternalServerError;

            if (Request.IsAjaxRequest())
            {
                Response.ContentType = "application/json";
                return(JsonEnvelope.Error("An unknown error has occurred."));
            }
            else
            {
                Response.ContentType = "text/html";
                return(View());
            }
        }
        /// <summary>
        /// 403 Forbidden
        /// </summary>
        public ActionResult Forbidden(Exception error)
        {
            Response.StatusCode  = (int)HttpStatusCode.Forbidden;
            Response.ContentType = "text/html";

            if (Request.IsAjaxRequest())
            {
                Response.ContentType = "application/json";
                return(JsonEnvelope.Error("Not enough privileges."));
            }
            else
            {
                Response.ContentType = "text/html";
                return(View());
            }
        }
        public async Task <JsonResult> Add(JustificationTypeConstant id, long specId, string name, string description, bool?nonCore, PciScopeConstant[] pciScope, int[] environmentIds)
        {
            if (!_packageFactory.IsValidName(name))
            {
                return(Json(JsonEnvelope.Error($"The {id} cannot be empty whitespace.")));
            }

            var newid = await _packageFactory.AddSoftwareComponent(id, specId, name?.Trim(), description?.Trim(), nonCore.GetValueOrDefault(), pciScope, environmentIds);

            if (newid.HasValue)
            {
                Logger.LogInformation($"{id} {newid} added by {UserSecurity.SamAccountName} for spec {specId} with name {name}");
                return(Json(JsonEnvelope.Success(new { url = Url.PartialGetPackage(newid.Value) })));
            }
            return(Json(JsonEnvelope.Error($"The {id} named {name} was already found in this spec or its parent.")));
        }
Beispiel #13
0
        public JsonResult TypeAhead(string q)
        {
            if (q?.Length < 2)
            {
                return(Json(JsonEnvelope.Error("Waiting for input...")));
            }

            var data = _todoService.AssigneeSearch(q);

            if (data.Length > 0)
            {
                return(Json(JsonEnvelope.Success(data)));
            }

            return(Json(JsonEnvelope.Error("No results found")));
        }
Beispiel #14
0
        public async Task <JsonResult> TypeAheadSearch(string q)
        {
            if (q?.Length < 2)
            {
                return(Json(JsonEnvelope.Error("Waiting for input...")));
            }

            var data = await SpecFactory.TypeAheadSearch(q);

            if (data.Length > 0)
            {
                return(Json(JsonEnvelope.Success(data)));
            }

            return(Json(JsonEnvelope.Error("No results found")));
        }
        public async Task <JsonResult> BulkAdd(JustificationTypeConstant id, long specId, BulkAddTypeConstant?addType, string[] names, string [] others)
        {
            if (names == null)
            {
                return(Json(JsonEnvelope.Error("Nothing was passed in to save.")));
            }

            var toAdd = names.Where(p => _packageFactory.IsValidName(p)).Select(p => p.Trim()).Distinct().ToArray();

            if (toAdd.Length == 0)
            {
                return(Json(JsonEnvelope.Error("Nothing was passed in to save.")));
            }

            if (addType.GetValueOrDefault(BulkAddTypeConstant.NamesOnly) != BulkAddTypeConstant.NamesOnly &&
                (others == null || others.Length != toAdd.Length || others.All(string.IsNullOrWhiteSpace)))
            {
                return(Json(JsonEnvelope.Error("There is a mismatch between distinct names and the second column in excel.  Ensure there are not duplicates and the second column has data for all values in the first column. ")));
            }

            string[] skipped;
            switch (addType.GetValueOrDefault(BulkAddTypeConstant.NamesOnly))
            {
            case BulkAddTypeConstant.NamesOnly:
                skipped = await _packageFactory.BulkAddSoftwareComponents(id, specId, toAdd, null);

                break;

            case BulkAddTypeConstant.WithDescriptions:
                skipped = await _packageFactory.BulkAddSoftwareComponents(id, specId, toAdd, others.Select(p => p?.Trim()).ToArray());

                break;

            case BulkAddTypeConstant.WithJustifications:

                skipped = await _packageFactory.BulkAddSoftwareComponentsWithJustifications(id, specId, toAdd, others.Select(p => p?.Trim()).ToArray());

                break;

            default:
                throw new ArgumentException($@"Type {addType} not handled.", nameof(addType));
            }

            Logger.LogInformation($"{id} bulk added by {UserSecurity.SamAccountName} for specId {specId} with data: { string.Join(", ", toAdd.Except(skipped))}");
            return(Json(JsonEnvelope.Success(new { url = Url.PartialGetPackages(id, specId), skipped, type = id.ToString(), justifications = BulkAddTypeConstant.WithJustifications == addType })));
        }
Beispiel #16
0
        public async Task <JsonResult> Assign(long id, long?specId)
        {
            try
            {
                await _nodeFactory.AssignBuildSpecification(id, specId, UserSecurity.SamAccountName);

                Logger.LogInformation($"Node with Inventory ID {id} was assigned to build spec {specId.GetValueOrDefault()} by {UserSecurity.SamAccountName}");
                if (specId.HasValue)
                {
                    return(Json(JsonEnvelope.Success(new
                    {
                        specUrl = Url.BuildSpecReport(specId.Value),
                        portUrl = Url.PortReport(specId.Value),
                        complianceUrl = Url.Review(specId.Value)
                    })));
                }
                return(Json(JsonEnvelope.Success()));
            }
            catch (ArgumentException)
            {
                return(Json(JsonEnvelope.Error($"A node with the id {id} was not found.")));
            }
        }
        public JsonResult ChefConvergeReportUrlGet(int id, Guid nodeGuid)
        {
            var url = Url.ChefAutomateConvergeReport(id, nodeGuid);

            return(Json(data: string.IsNullOrEmpty(url)? JsonEnvelope.Error("Node Converge report not Available ") : JsonEnvelope.Success(new { url })));
        }