public async Task <IActionResult> GetRequestByProjectId(int projectId) { if (!HttpContext.User.IsInRole("admin")) { EnumProjectAccessRight projectAccessRight = await _getAccessUser.GetUserAccessRightProject(Convert.ToInt32(HttpContext.User.FindFirstValue(ClaimTypes.NameIdentifier)), projectId); if (projectAccessRight == EnumProjectAccessRight.None) { ProjectIsPublic projectIsPublic = await _projectGateway.ProjectIsPublic(projectId); if (projectIsPublic.IsPublic == 1) { return(StatusCode(403, "Access Denied !")); } } } IEnumerable <RequestByProjectIdData> requestResult = await _requestGateway.GetRequestByProjectId(projectId); if (requestResult == null) { return(BadRequest("No request for this project id exists")); } return(Ok(requestResult)); }
public async Task <IActionResult> GetRequestById(int requestId) { RequestData requestResult = await _requestGateway.GetRequestById(requestId); if (requestResult == null) { return(BadRequest("Request not found")); } if (!HttpContext.User.IsInRole("admin")) { EnumProjectAccessRight projectAccessRight = await _getAccessUser.GetUserAccessRightProject(Convert.ToInt32(HttpContext.User.FindFirstValue(ClaimTypes.NameIdentifier)), requestResult.ProjectId); if (projectAccessRight == EnumProjectAccessRight.None) { ProjectIsPublic projectIsPublic = await _projectGateway.ProjectIsPublic(requestResult.ProjectId); if (projectIsPublic.IsPublic == 1) { return(StatusCode(403, "Access Denied !")); } } } return(Ok(requestResult)); }
public async Task <IActionResult> DeleteRequest(int requestId) { RequestData requestResult = await _requestGateway.GetRequestById(requestId); if (requestResult == null) { return(BadRequest("Request not found")); } if (!HttpContext.User.IsInRole("admin")) { EnumProjectAccessRight projectAccessRight = await _getAccessUser.GetUserAccessRightProject(Convert.ToInt32(HttpContext.User.FindFirstValue(ClaimTypes.NameIdentifier)), requestResult.ProjectId); if (projectAccessRight != EnumProjectAccessRight.Worker || projectAccessRight != EnumProjectAccessRight.Admin) { return(StatusCode(403, "Access Denied !")); } } Result <bool> result = await _requestGateway.DeleteRequest(requestId); if (result.ErrorMessage == "Request not found") { return(BadRequest(result.ErrorMessage)); } return(Ok("Request deleted")); }
private async Task <bool> UserCanModifyProject(int projectId) { EnumProjectAccessRight projectAccessRight = await _getAccessUser.GetUserAccessRightProject(Convert.ToInt32(HttpContext.User.FindFirstValue(ClaimTypes.NameIdentifier)), projectId); if (!HttpContext.User.IsInRole("admin") && projectAccessRight != EnumProjectAccessRight.Admin && projectAccessRight != EnumProjectAccessRight.Worker) { return(false); } return(true); }
private async Task <bool> UserCanReadProject(int projectId, ProjectData project) { EnumProjectAccessRight projectAccessRight = await _getAccessUser.GetUserAccessRightProject(Convert.ToInt32(HttpContext.User.FindFirstValue(ClaimTypes.NameIdentifier)), projectId); if (!HttpContext.User.IsInRole("admin") && projectAccessRight == EnumProjectAccessRight.None && project.IsPublic == 0) { return(false); } return(true); }
public async Task <EnumProjectAccessRight> GetUserAccessRightProject(int userId, int projectId) { Result <string> result = await _projectGateway.GetUserAccessRightProject(userId, projectId); if (result.Content == null) { return(EnumProjectAccessRight.None); } EnumProjectAccessRight projectAccessRight = (EnumProjectAccessRight)Enum.Parse(typeof(EnumProjectAccessRight), result.Content); return(projectAccessRight); }
public async Task <IActionResult> SendInvitationProject([FromBody] SendInvitationProjectViewModel model) { if (model.UserAuthorId == 0) { model.UserAuthorId = Convert.ToInt32(HttpContext.User.FindFirstValue(ClaimTypes.NameIdentifier)); } if (model.UserAuthorId == model.UserInvitedId) { return(BadRequest("User author cannot invite himself")); } int userInProject = await _projectGateway.CheckUserInProject(model.UserInvitedId, model.ProjectId); if (userInProject != 0) { return(BadRequest("User invited already member of this project")); } if (!HttpContext.User.IsInRole("admin")) { if (!_getAccessUser.UserCookieIs(HttpContext, model.UserAuthorId.ToString())) { return(StatusCode(403, "Access Denied !")); } EnumProjectAccessRight projectAccessRight = await _getAccessUser.GetUserAccessRightProject(Convert.ToInt32(HttpContext.User.FindFirstValue(ClaimTypes.NameIdentifier)), model.ProjectId); if (projectAccessRight != EnumProjectAccessRight.Admin) { return(StatusCode(403, "Access Denied !")); } } Result resultSendInvitationProject = await _projectGateway.CreateUserInvitationInProject(model.UserAuthorId, model.UserInvitedId, model.ProjectId); if (resultSendInvitationProject.ErrorMessage == "An invitation made by the user with this project and user invited already exist") { return(BadRequest(resultSendInvitationProject.ErrorMessage)); } string nameProject = await _getAccessUser.GetProjectName(model.ProjectId); await _projectHub.ReceiveInvitationInProject(Convert.ToString(model.UserInvitedId), Convert.ToString(model.UserAuthorId), Convert.ToString(model.ProjectId), HttpContext.User.Identity.Name, nameProject); return(Ok("The invitation has been sent")); }
public async Task <IActionResult> GetProjectById(int projectId) { Result <ProjectData> result = await _projectGateway.GetProjectById(projectId); if (result.ErrorMessage == "Project not found") { return(BadRequest(result.ErrorMessage)); } EnumProjectAccessRight projectAccessRight = await _getAccessUser.GetUserAccessRightProject(Convert.ToInt32(HttpContext.User.FindFirstValue(ClaimTypes.NameIdentifier)), projectId); if (!HttpContext.User.IsInRole("admin") && projectAccessRight == EnumProjectAccessRight.None && result.Content.IsPublic == 0) { return(StatusCode(403, "Access Denied !")); } return(Ok(result.Content)); }
public async Task <IActionResult> GetUserInProject(int projectId) { EnumProjectAccessRight projectAccessRight = await _getAccessUser.GetUserAccessRightProject(Convert.ToInt32(HttpContext.User.FindFirstValue(ClaimTypes.NameIdentifier)), projectId); if (!HttpContext.User.IsInRole("admin") && projectAccessRight == EnumProjectAccessRight.None) { return(StatusCode(403, "Access Denied !")); } IEnumerable <UserInProjectData> result = await _projectGateway.GetUserInProject(projectId); if (result == null) { return(BadRequest("Project has no user")); } return(Ok(result)); }
public async Task <IActionResult> DeleteProject(int projectId) { EnumProjectAccessRight projectAccessRight = await _getAccessUser.GetUserAccessRightProject(Convert.ToInt32(HttpContext.User.FindFirstValue(ClaimTypes.NameIdentifier)), projectId); if (!HttpContext.User.IsInRole("admin") && projectAccessRight != EnumProjectAccessRight.Admin) { return(StatusCode(403, "Access Denied !")); } _dGraphGateway.DeleteProject(projectId); Result result = await _projectGateway.DeleteProject(projectId); if (result.ErrorMessage == "Project not found") { return(BadRequest(result.ErrorMessage)); } return(Ok("Project has been deleted")); }
public async Task <IActionResult> GetUserForInvitByProjectId(int projectId) { if (!HttpContext.User.IsInRole("admin")) { EnumProjectAccessRight accessRight = await _getAccessUser.GetUserAccessRightProject(Convert.ToInt32(HttpContext.User.FindFirstValue(ClaimTypes.NameIdentifier)), projectId); if (accessRight != EnumProjectAccessRight.Admin) { return(StatusCode(403, "Access Denied !")); } } IEnumerable <UserForInvitData> result = await _userGateway.GetUserForInvitByProjectId(projectId); if (result == null) { return(BadRequest("No user avaibles for invit")); } return(Ok(result)); }
public async Task <IActionResult> UnassignUserToProject([FromBody] UnassignUserToProjectViewModel model) { if (model.UserId == 0) { model.UserId = Convert.ToInt32(HttpContext.User.FindFirstValue(ClaimTypes.NameIdentifier)); } EnumProjectAccessRight projectAccessRight = await _getAccessUser.GetUserAccessRightProject(Convert.ToInt32(HttpContext.User.FindFirstValue(ClaimTypes.NameIdentifier)), model.ProjectId); if (!HttpContext.User.IsInRole("admin") && !_getAccessUser.UserCookieIs(HttpContext, model.UserId.ToString()) && projectAccessRight != EnumProjectAccessRight.Admin) { return(StatusCode(403, "Access Denied !")); } Result resultUnassignUserToProject = await _projectGateway.UnassignUserToProject(model.UserId, model.ProjectId); if (resultUnassignUserToProject.ErrorMessage == "User is not in the project") { return(BadRequest(resultUnassignUserToProject.ErrorMessage)); } int nbOfAdminInProject = await _projectGateway.GetNumberAccessRightInProject(model.ProjectId, (int)EnumProjectAccessRight.Admin); if (nbOfAdminInProject <= 0) { _dGraphGateway.DeleteProject(model.ProjectId); await _projectGateway.DeleteProject(model.ProjectId); } string nameProject = await _getAccessUser.GetProjectName(model.ProjectId); string userName = await _getAccessUser.GetUserName(model.UserId); IEnumerable <string> userInProject = await _projectGateway.GetIdUserInProject(model.ProjectId); await _projectHub.ReceiveUserLeavedProject(userInProject.ToList(), Convert.ToString(model.ProjectId), userName, nameProject); return(Ok("Unassign success")); }
public async Task <IActionResult> UpdateProject([FromBody] UpdateProjectViewModel model) { EnumProjectAccessRight projectAccessRight = await _getAccessUser.GetUserAccessRightProject(Convert.ToInt32(HttpContext.User.FindFirstValue(ClaimTypes.NameIdentifier)), model.Id); if (!HttpContext.User.IsInRole("admin") && projectAccessRight != EnumProjectAccessRight.Admin) { return(StatusCode(403, "Access Denied !")); } Result result = await _projectGateway.UpdateProject(model.Id, model.Name, model.Description, model.IsPublic); if (result.ErrorMessage == "Project with this id not exists") { return(BadRequest(result.ErrorMessage)); } if (result.ErrorMessage == "Project with this name already exists") { return(BadRequest(result.ErrorMessage)); } return(Ok("Project has been updated")); }
public async Task <IActionResult> StartRequest(int projectId, [FromBody] StartRequestViewModel model) { if (model.Softwares.Count <= 0) { return(BadRequest("Software needed")); } if (!HttpContext.User.IsInRole("admin")) { EnumProjectAccessRight projectAccessRight = await _getAccessUser.GetUserAccessRightProject(Convert.ToInt32(HttpContext.User.FindFirstValue(ClaimTypes.NameIdentifier)), projectId); if (projectAccessRight != EnumProjectAccessRight.Worker || projectAccessRight != EnumProjectAccessRight.Admin) { return(StatusCode(403, "Access Denied !")); } } Result <int> createRequest = await _requestGateway.CreateRequest(1, projectId, model.DataEntity, model.UidNode, HttpContext.User.Identity.Name); if (createRequest.ErrorMessage == "Already research with this date exists") { return(BadRequest(createRequest.ErrorMessage)); } model.RequestId = createRequest.Content; HttpResponseMessage response = await _diggosService.RunSoftware(model, createRequest.Content); if (!response.IsSuccessStatusCode) { await _requestGateway.ChangeStatusRequest(createRequest.Content, 5); return(StatusCode(502, "Error on diggos")); } Result <bool> statusRequestSuccess = await _requestGateway.ChangeStatusRequest(createRequest.Content, 2); return(Ok("Request started")); }
public async Task <IActionResult> ChangeAccessRightUserInProject([FromBody] ChangeAccessRightUserInProjectViewModel model) { EnumProjectAccessRight projectAccessRight = await _getAccessUser.GetUserAccessRightProject(Convert.ToInt32(HttpContext.User.FindFirstValue(ClaimTypes.NameIdentifier)), model.ProjectId); if (!HttpContext.User.IsInRole("admin") && projectAccessRight != EnumProjectAccessRight.Admin) { return(StatusCode(403, "Access Denied !")); } if (Convert.ToInt32(HttpContext.User.FindFirstValue(ClaimTypes.NameIdentifier)) == model.UserId) { return(BadRequest("You cannot change your access right in project")); } Result result = await _projectGateway.UpdateAccessRightUserInProject(model.UserId, model.ProjectId, model.AccessRightId); if (result.ErrorMessage == "User not belongs in this project") { return(BadRequest(result.ErrorMessage)); } return(Ok("Access right changed")); }