Exemplo n.º 1
0
        //Get Comment Reports Ajax

        public ActionResult GetCommentReportsAjax(int commentId)
        {
            if (!_workContext.CurrentCustomer.IsRegistered())
            {
                return(Unauthorized());
            }

            if (!_workContext.CurrentCustomer.IsInCustomerRole(RolesType.Administrators, true) && !_workContext.CurrentCustomer.IsInCustomerRole(RolesType.HaragAdmin, true))
            {
                return(Forbid());
            }

            if (commentId == null || commentId == 0)
            {
                return(NotFound());
            }
            var reportInDb = _commentService.GetCommentReports(commentId);
            var messages   = new ReportOutputModel
            {
                Items = reportInDb.Select(m => new ReportModel
                {
                    Id                = m.Id,
                    Category          = m.ReportCategory,
                    ReportDescription = m.ReportDescription,
                    CustomerName      = m.Z_Harag_Customer?.Username,
                    Comment           = m.Z_Harag_Comment?.Text,
                    CommentId         = m.CommentId,
                    ReportTitle       = m.ReportTitle
                }).ToList()
            };

            return(Json(new { data = messages.Items, CommentId = commentId }));
        }
Exemplo n.º 2
0
        //Get Post Reports
        public ActionResult GetPostReports(int postId)
        {
            if (!_workContext.CurrentCustomer.IsRegistered())
            {
                return(Unauthorized());
            }

            if (!_workContext.CurrentCustomer.IsInCustomerRole(RolesType.Administrators, true) && !_workContext.CurrentCustomer.IsInCustomerRole(RolesType.HaragAdmin, true))
            {
                return(Forbid());
            }

            if (postId == null || postId == 0)
            {
                return(NotFound());
            }
            var messagesInDb = _postService.GetPostReports(postId);
            var messages     = new ReportOutputModel
            {
                Items = messagesInDb.Select(m => new ReportModel
                {
                    Id = m.Id,
                    ReportDescription = m.ReportDescription,
                    CustomerName      = m.Customer?.Username,
                    PostTitle         = m.Z_Harag_Post?.Title,
                    ReportTitle       = m.ReportTitle
                }).ToList()
            };

            return(Json(new { data = messages.Items }));
        }
Exemplo n.º 3
0
        /// <summary>
        /// Checks submitted code for vunrabilities and keeps track of any found
        /// </summary>
        /// <param name="file">Viewmodel containg a iformfile or string from textarea</param>
        /// <returns>ReportOutputModel detailing all lines of code with a vunrability, the number of them and a description of vunrabilities</returns>
        private ReportOutputModel CodeReview(Upload file)
        {
            ReportOutputModel           Model         = new ReportOutputModel();
            Dictionary <string, string> Vunrabilities = SetUpVunrabilities();
            List <string> result;

            //Calls the specific method to handle input parsing
            if (file.codeFile != null)
            {
                result = FileRead(file.codeFile);
            }
            else //if one is null then must be the other
            {
                result = SnippetRead(file.codeSnippet);
            }


            foreach (string Code in result)                                           //Outer loop tracks each specific line of code
            {
                foreach (KeyValuePair <string, string> Vunrabilitie in Vunrabilities) //inner loop checks current line of code for each specific vunrability
                {
                    Regex regexName = new Regex((@"^(.*?(" + Vunrabilitie.Key + @"\b)[^$]*)$"), RegexOptions.IgnoreCase);

                    if ((regexName.Match(Code)).Success)
                    {
                        Model.OutputDictionary.Add(Code + new string(' ', Model.Counter), Vunrabilitie.Value); //adds to model, new string function used to allow duplicate lines with multiple errors
                        Model.Counter++;
                    }
                }
            }

            return(Model);
        }
Exemplo n.º 4
0
 public IActionResult Retreive(Upload file)
 {
     if (ModelState.IsValid && CheckModelStateCustom(file)) //checking model state as well as our custom checks
     {
         ReportOutputModel Model = CodeReview(file);
         return(View("Report", Model));
     }
     else
     {
         return(View("Index", file));
     }
 }
Exemplo n.º 5
0
        public IActionResult GetPostReportsAjax()
        {
            if (!_workContext.CurrentCustomer.IsRegistered())
            {
                return(Unauthorized());
            }

            if (!_workContext.CurrentCustomer.IsInCustomerRole(RolesType.Administrators, true) && !_workContext.CurrentCustomer.IsInCustomerRole(RolesType.HaragAdmin, true))
            {
                return(Forbid());
            }


            //Server Side Parameters
            var start = Convert.ToInt32(Request.Form["start"].FirstOrDefault());
            //int startRec = Request.Form.GetValues("start").First;
            //int start = Convert.ToInt32(Request.Form.GetValues("start")[0]);
            int    length         = Convert.ToInt32(Request.Form["length"]);
            string searchValue    = Request.Form["search[value]"];
            string sortColumnName = Request.Form["columns[" + Request.Form["order[0][column]"] + "][name]"];
            string sortDirection  = Request.Form["order[0][dir]"];


            var postReportInDb = _reportService.GetPostReports(start, length, searchValue, sortColumnName, sortDirection);


            var postReport = new ReportOutputModel
            {
                Items = postReportInDb.Select(r => new ReportModel
                {
                    Id                = r.Id,
                    PostId            = r.Z_Harag_Post?.Id,
                    ReportTitle       = r.ReportTitle,
                    ReportDescription = r.ReportDescription,
                    IsIllegal         = r.IsIllegal
                }).ToList()
            };

            return(Json(new { data = postReport.Items }));
        }