Exemplo n.º 1
0
        public async Task <IActionResult> AddIssue(AddNewIssueViewModel model)
        {
            if (ModelState.IsValid)
            {
                Console.WriteLine("Testing");
                var userId      = userManager.GetUserId(User);
                var currentUser = await userManager.FindByIdAsync(userId);

                var userClaims = await userManager.GetClaimsAsync(currentUser);

                Global.globalCurrentUserClaims = userClaims.ToList();

                var IsUserManagerLevel = ClaimsLevel.IsManager(userClaims.ToList(), model.NewIssue.AssociatedProject);

                if (IsUserManagerLevel && model.NewIssue.AssigneeUserId != null)
                {
                    var assignedUser = await userManager.FindByIdAsync(model.NewIssue.AssigneeUserId);

                    model.NewIssue.AssigneeUserName = assignedUser.UserName;
                }

                model.NewIssue.SubmitterId       = userManager.GetUserId(User);
                model.NewIssue.SubmitterUserName = userManager.GetUserName(User);
                model.NewIssue.CreatedTime       = DateTime.Now;

                var issue = _issueRepository.AddIssue(model.NewIssue);

                if (issue.Title == null)
                {
                    issue.Title = $"issue {issue.IssueId}";
                    _issueRepository.Update(issue);
                }

                var projectIssue = new ProjectIssue
                {
                    ProjectId = issue.AssociatedProject,
                    IssueId   = issue.IssueId
                };
                _projectRepository.AddProjectIssues(projectIssue);
                Console.WriteLine("HERERERER");

                var fileNames = new List <ScreenShots>();

                if (Global.globalInitialScreenShots == true)
                {
                    Console.WriteLine("Globally");
                    fileNames = await UploadScreenShotsToStorage(issue.IssueId);
                }

                Global.InitialScreenShots = false;
                _issueRepository.AddScreenShots(fileNames);

                Console.WriteLine(_issueRepository.ScreenShots(issue.IssueId));



                return(RedirectToAction("projectissues", "Project", new { projectId = model.NewIssue.AssociatedProject }));
            }
            return(View());
        }
Exemplo n.º 2
0
        public async Task <IActionResult> IssueDetails(IssueDetailsViewModel model)
        {
            var userId      = userManager.GetUserId(User);
            var currentUser = await userManager.FindByIdAsync(userId);

            var userClaims = await userManager.GetClaimsAsync(currentUser);

            Global.globalCurrentUserClaims = userClaims.ToList();

            var IsManagerLevel = ClaimsLevel.IsManager(userClaims.ToList(), model.Issue.AssociatedProject);

            if (IsManagerLevel && model.Issue.AssigneeUserId != null)
            {
                var assignedUser = await userManager.FindByIdAsync(model.Issue.AssigneeUserId);

                model.Issue.AssigneeUserName = assignedUser.UserName;
            }

            var uniqueFileNames = new List <ScreenShots>();

            if (Global.InitialScreenShots == true)
            {
                uniqueFileNames = await UploadScreenShotsToStorage(model.Issue.IssueId);
            }

            Global.InitialScreenShots = false;
            _issueRepository.AddScreenShots(uniqueFileNames);


            var originalIssue = _issueRepository.GetIssue(model.Issue.IssueId);

            if (model.Issue.Title == null)
            {
                model.Issue.Title = originalIssue.Title;
            }

            var IsDeveloperLevel = ClaimsLevel.IsDeveloper(userClaims.ToList(), model.Issue.AssociatedProject);

            if (IsDeveloperLevel)
            {
                foreach (var property in originalIssue.GetType().GetProperties())
                {
                    if (property.Name == "AssigneeUserId")
                    {
                        continue;
                    }

                    var oldValue = "";
                    var newValue = "";

                    if (property.GetValue(model.Issue) != null)
                    {
                        newValue = property.GetValue(model.Issue).ToString();
                    }

                    if (property.GetValue(originalIssue) != null)
                    {
                        oldValue = property.GetValue(originalIssue).ToString();
                    }

                    if (newValue != oldValue)
                    {
                        var changes = new IssueHistory
                        {
                            AssociatedIssueId = originalIssue.IssueId,
                            DateModified      = DateTime.Now,
                            NewValue          = newValue,
                            OldValue          = oldValue,
                            Property          = property.Name
                        };

                        _issueRepository.AddIssueHistory(changes);
                    }
                }
            }

            var issue = new Issue();

            if (IsDeveloperLevel)
            {
                model.Issue.ScreenShots = uniqueFileNames;
                model.Issue.ScreenShots.AddRange(_issueRepository.ScreenShots(model.Issue.IssueId));
                issue = _issueRepository.Update(model.Issue);
            }
            else
            {
                issue             = originalIssue;
                issue.ScreenShots = uniqueFileNames;
                issue.ScreenShots.AddRange(_issueRepository.ScreenShots(model.Issue.IssueId));
            }
            Console.WriteLine(issue.IssueId);
            var project     = _projectRepository.GetProject(issue.AssociatedProject);
            var projectName = project.ProjectName;

            issue.Comments = _issueRepository.Comments(issue.IssueId);
            var issueHistory = _issueRepository.GetIssueHistories(issue.IssueId);

            var users        = new List <IdentityUser>();
            var projectUsers = new List <string>();

            projectUsers.Add(project.OwnerId);

            if (project.UsersAssigned != null)
            {
                projectUsers.AddRange(project.UsersAssigned.Split(" ").ToList());
            }

            foreach (var uId in projectUsers)
            {
                var user = await userManager.FindByIdAsync(uId);

                if (user != null && !users.Contains(user))
                {
                    users.Add(user);
                }
            }

            var screenshots = _issueRepository.ScreenShots(model.Issue.IssueId);


            var viewModel = new IssueDetailsViewModel
            {
                Issue          = issue,
                IssueHistories = issueHistory,
                Updated        = 1,
                ProjectId      = issue.AssociatedProject,
                Source         = screenshots,
                ProjectUsers   = users,
                ProjectName    = projectName
            };

            return(View(viewModel));
        }
        public async Task <IActionResult> ManageUserClaims(string userId, int projectId)
        {
            Global.ProjectId = projectId;
            var project = _projectRepository.GetProject(projectId);

            Global.Project = project;

            var uId         = userManager.GetUserId(User);
            var currentUser = await userManager.FindByIdAsync(uId);

            var uClaims = await userManager.GetClaimsAsync(currentUser);

            Global.globalCurrentUserClaims = uClaims.ToList();

            var user = await userManager.FindByIdAsync(userId);

            var IsManagerLevel = ClaimsLevel.IsManager(User.Claims.ToList(), projectId);

            if (IsManagerLevel == false)
            {
                return(RedirectToAction("AccessDenied", "Account"));
            }
            else if (userId == userManager.GetUserId(User) || userId == project.OwnerId)
            {
                return(RedirectToAction("AccessDenied", "Account"));
            }

            if (user == null)
            {
                ViewBag.ErrorMessage = $"User with id {userId} doesn't exist";
                return(View("NotFound"));
            }

            var existingUserClaims = await userManager.GetClaimsAsync(user);

            //foreach(var claim in existingUserClaims)
            //{
            //    Console.WriteLine("------");
            //    Console.WriteLine(claim.Type);
            //    Console.WriteLine(claim.Value);
            //}

            var viewModel = new ClaimsViewModel
            {
                UserId    = userId,
                ProjectId = projectId
            };


            for (var i = 0; i < ClaimsPile.AllClaims.Count; i++)
            {
                UserClaim userClaim = new UserClaim
                {
                    ClaimType = ClaimsPile.AllClaims[i].Type
                };

                var projectList = new List <string>();

                if (existingUserClaims.Count == 4)
                {
                    projectList = existingUserClaims[i].Value.Split(" ").ToList();
                }

                for (int j = 0; j < projectList.Count; j++)
                {
                    if (projectList[j] == projectId.ToString())
                    {
                        userClaim.IsSelected = true;
                        break;
                    }
                }
                viewModel.Claims.Add(userClaim);
            }

            foreach (var claim in viewModel.Claims)
            {
                Console.WriteLine(claim.ClaimType);
                Console.WriteLine(claim.IsSelected);
            }

            return(View(viewModel));
        }
        public async Task <IActionResult> EditUser(string userId, int projectId)
        {
            Global.ProjectId = projectId;

            var project = _projectRepository.GetProject(projectId);

            Global.Project = project;

            var uId         = userManager.GetUserId(User);
            var currentUser = await userManager.FindByIdAsync(uId);

            var userClaims = await userManager.GetClaimsAsync(currentUser);

            Global.globalCurrentUserClaims = userClaims.ToList();

            var IsManagerLevel = ClaimsLevel.IsManager(userClaims.ToList(), projectId);

            if (IsManagerLevel == false)
            {
                return(RedirectToAction("AccessDenied", "Account"));
            }

            var user = await userManager.FindByIdAsync(userId);

            if (user == null)
            {
                ViewBag.ErrorMessage = $"User with id {userId} doesn't exist";
                return(View("NotFound"));
            }

            var viewModel = new EditUserViewModel
            {
                UserId    = user.Id,
                Email     = user.Email,
                UserName  = user.UserName,
                ProjectId = projectId
            };

            var allUserClaims = await userManager.GetClaimsAsync(user);

            foreach (var claim in allUserClaims)
            {
                var projectList = claim.Value.Split(" ").ToList();
                var claimString = "";

                for (var i = 0; i < projectList.Count; i++)
                {
                    if (projectList[i] == projectId.ToString())
                    {
                        claimString = claim.Type + " : true";
                        viewModel.Claims.Add(claimString + " --> " + project.ProjectName);
                        break;
                    }
                }
                if (claimString == "")
                {
                    claimString = claim.Type + " : false";
                    viewModel.Claims.Add(claimString);
                }
            }



            return(View(viewModel));
        }