Exemplo n.º 1
0
        public async Task SetUserProjectRole([FromBody] ProjectUserWithRole foo)
        {
            _logger.LogInformation($"{foo.Project} {foo.User} {foo.Role}");

            if (!(await _authService.AuthorizeProjectRole(eProjectRoles.Manager, foo.Project)))
            {
                return;
            }

            await _projectRolesService.SetProjectRole(foo.Project, foo.User, foo.Role);
        }
Exemplo n.º 2
0
        public async Task <IActionResult> ProjectDelete([FromRoute] string projectName)
        {
            var keyAuthResult = await _authService.AuthByApiKey();

            if (keyAuthResult.User == null)
            {
                return(BadRequest(ErrorResponse.GetErrorList(keyAuthResult.ErrorText)));
            }

            var project = _ticketService.GetProject(projectName);

            if (project == null)
            {
                return(NotFound(ErrorResponse.GetErrorList($"Project {projectName} was not found!")));
            }

            if (!await _authService.AuthorizeProjectRole(eProjectRoles.Manager, project.Id, user: keyAuthResult.User))
            {
                return(Unauthorized(ErrorResponse.GetUnauthorizedErrorList(keyAuthResult.User.Identity.Name, project.Name, eProjectRoles.Manager)));
            }

            if (_ticketService.DeleteProject(project.Id))
            {
                return(NoContent());
            }

            return(NotFound(ErrorResponse.GetErrorList($"Project {projectName} was not found!")));
        }
Exemplo n.º 3
0
        public async Task <IActionResult> SetUserProjectRole([FromBody] PutUserRoleRequest request)
        {
            var keyAuthResult = await _authService.AuthByApiKey();

            if (keyAuthResult.User == null)
            {
                return(BadRequest(ErrorResponse.GetErrorList(keyAuthResult.ErrorText)));
            }

            var project = _ticketService.GetProject(request.Project);

            if (project == null)
            {
                return(BadRequest(ErrorResponse.GetErrorList($"Project: {request.Project} does not exist!")));
            }

            if (!await _authService.AuthorizeProjectRole(eProjectRoles.Manager, project.Id, user: keyAuthResult.User))
            {
                return(Unauthorized(ErrorResponse.GetUnauthorizedErrorList(keyAuthResult.User.Identity.Name, project.Name, eProjectRoles.Manager)));
            }

            await _projectRoleService.SetProjectRole(request.Project, request.User, request.Role);

            var baseUrl     = $"{HttpContext.Request.Scheme}://{HttpContext.Request.Host.ToUriComponent()}";
            var locationUrl = baseUrl + "/" + ApiRoutes.UserRoles.GetAllByUser.Replace("{userName}", request.User);

            var response = _mapper.Map <UserRoleResponse>(request);

            return(Created(locationUrl, response));
        }
Exemplo n.º 4
0
        public async Task <IActionResult> TicketCreate([FromBody] CreateTicketRequest request)
        {
            var keyAuthResult = await _authService.AuthByApiKey();

            if (keyAuthResult.User == null)
            {
                return(BadRequest(ErrorResponse.GetErrorList(keyAuthResult.ErrorText)));
            }

            var project = _ticketService.GetProject(request.ProjectName);

            if (project == null)
            {
                return(BadRequest(ErrorResponse.GetErrorList($"Project: {request.ProjectName} does not exist!")));
            }

            if (!await _authService.AuthorizeProjectRole(eProjectRoles.Reporter, project.Id, user: keyAuthResult.User))
            {
                return(Unauthorized(ErrorResponse.GetUnauthorizedErrorList(keyAuthResult.User.Identity.Name, project.Name, eProjectRoles.Reporter)));
            }

            var ticket = _mapper.Map <Ticket>(request);

            ticket.ProjectId = project.Id;
            if (string.IsNullOrEmpty(ticket.AssignedTo))
            {
                ticket.AssignedTo = "--";
            }
            ticket.Reporter = keyAuthResult.User.Identity.Name;

            if (!_ticketService.AddTicket(ticket))
            {
                return(BadRequest(ErrorResponse.GetErrorList("validation error")));
            }

            await _ticketService.MarkTicketAsSeen(ticket.Id, keyAuthResult.User.Identity.Name);

            var baseUrl     = $"{HttpContext.Request.Scheme}://{HttpContext.Request.Host.ToUriComponent()}";
            var locationUrl = baseUrl + "/" + ApiRoutes.Tickets.Get.Replace("{id}", ticket.Id.ToString());

            var response = _mapper.Map <TicketResponse>(ticket);

            return(Created(locationUrl, response));
        }
Exemplo n.º 5
0
        public async Task <IActionResult> TicketAdd([FromForm] TicketAddViewModel viewTicket)
        {
            if (!(await _authService.AuthorizeProjectRole(eProjectRoles.Reporter, viewTicket.ProjectId)))
            {
                return(RedirectToAction("AccessDenied", "Account"));
            }

            Ticket ticket = new Ticket();

            viewTicket.copyValsTo(ticket);
            ticket.Reporter  = User.Identity.Name;
            ticket.CreatedTs = DateTime.Now;

            _ticketService.AddTicket(ticket);
            await _ticketService.MarkTicketAsSeen(ticket.Id, User.Identity.Name);

            return(RedirectToAction("tickets", "ticket", new { projectId = viewTicket.ProjectId, type = (int)viewTicket.Type, state = (int)viewTicket.State }));
        }