public async Task <IActionResult> AcceptInvitation(ProjectInvitation projectInvitation)
        {
            //get the current user
            var user = await _userManager.GetUserAsync(HttpContext.User);

            //make sure the invitee in the invitation is the current user
            if (projectInvitation.InviteeId != user.Id)
            {
                return(Unauthorized("Cannot accept invitations if requester is not the invitee"));
            }

            //create a project user object
            ProjectUser projectUser = new ProjectUser();

            projectUser.ProjectId = projectInvitation.ProjectId;
            projectUser.AppUserId = projectInvitation.InviteeId;
            projectUser.Role      = "Member";
            projectUser.TimeAdded = DateTime.Now;

            _projectsRepo.AddUserToProject(projectUser);
            _projectsRepo.DeleteProjectInvite(projectInvitation.ProjectId, projectInvitation.InviteeId);
            _projectsRepo.SaveChanges();

            return(Ok(projectUser));
        }
Ejemplo n.º 2
0
        public AcceptInvitationStatus AcceptProjectInvitation(int invitationID)
        {
            ProjectInvitation invitation = ProjectInvitations.Get(invitationID);

            if (invitation == null)
            {
                return(AcceptInvitationStatus.NoSuchInvitation);
            }

            if (invitation.TargetUserID != UserContext.AccountID)
            {
                return(AcceptInvitationStatus.NotTarget);
            }

            if (invitation.Type == ProjectInvitationType.Manager)
            {
                invitation.TargetProject.Managers.Add(invitation.TargetUser);
            }
            else if (invitation.Type == ProjectInvitationType.Reader)
            {
                invitation.TargetProject.Readers.Add(invitation.TargetUser);
            }
            else if (invitation.Type == ProjectInvitationType.Owner)
            {
                invitation.TargetProject.OwnerUserID = invitation.TargetUserID;
            }

            ActivityService.ProjectInvitationAccepted(invitation.ID);
            ProjectRepository.Update(invitation.TargetProject);
            ProjectInvitations.Delete(invitation);
            return(AcceptInvitationStatus.Accepted);
        }
Ejemplo n.º 3
0
        public void AddInvitationByEmail(long projectId, long inviterId, string inviteeEmail, string invitationMessage, long inviteePartId = 0, int bidProjId = 0)
        {
            var invitation = GetInvitation(projectId, inviterId, inviteeEmail, inviteePartId);

            if (invitation != null)
            {
                //invitation.ProjectId = projectId;
                //invitation.InviterId = inviterId;
                //invitation.InviteeEmail = inviteeEmail;
                //invitation.InviteePartId = inviteePartId;
                invitation.InviteeId             = 0;
                invitation.InvitationMessage     = invitationMessage;
                invitation.Accepted              = false;
                invitation.InviteeConfirmMessage = null;
                invitation.BidProjectId          = bidProjId;
                _invitationRepo.Update(invitation);
            }
            else
            {
                invitation = new ProjectInvitation
                {
                    ProjectId         = projectId,
                    InviterId         = inviterId,
                    InviteeEmail      = inviteeEmail,
                    InviteePartId     = inviteePartId,
                    InvitationMessage = invitationMessage,
                    BidProjectId      = bidProjId
                };
                _invitationRepo.Insert(invitation);
            }
        }
        public async Task <IActionResult> ConfirmInvitation(string token)
        {
            System.Diagnostics.Debug.WriteLine("confirming invitation");
            ProjectInvitation invitation = await InvitationService.GetInvitation(token);

            if (invitation == null)
            {
                TempData["Error"] = "This invitation is no longer valid, or you are allready a member of the project";
                return(Redirect("/"));
            }

            AppUser invitedUser = await userManager.FindByEmailAsync(invitation.Email);

            AppUser user = await userManager.GetUserAsync(HttpContext.User);

            if (user == invitedUser)
            {
                bool successful = await InvitationService.AddUserToProject(invitedUser, invitation);

                return(Redirect("/"));
            }
            else
            {
                return(Unauthorized());
            }
        }
Ejemplo n.º 5
0
 public void UpdateInvitation(ProjectInvitation invitation)
 {
     if (invitation == null)
     {
         throw new ArgumentNullException("invitation");
     }
     _invitationRepo.Update(invitation);
 }
Ejemplo n.º 6
0
        /**/

        /*
         * NAME:
         *      AddProjectInvite - adds a ProjectInvitatoin object to the database
         * SYNOPSIS:
         *      AddProjectInvite(ProjectInvitation projectInvitation)
         *           projectInvitation --> the projectInvitation object to be added to the database as an entry
         * DESCRIPTION:
         *      Accesses the database context in order to add the given ProjectInvitation entry
         * RETURNS
         * AUTHOR
         *      Biplab Thapa Magar
         * DATE
         *      09/10/2020
         * /
         * /**/
        public void AddProjectInvite(ProjectInvitation projectInvitation)
        {
            if (projectInvitation == null)
            {
                throw new ArgumentNullException(nameof(projectInvitation));
            }
            _context.Add(projectInvitation);
        }
Ejemplo n.º 7
0
        public async Task <bool> CreateInvitation(ProjectInvitation projectInvitation, Project project, AppUser user, string token)
        {
            projectInvitation.Email     = user.Email;
            projectInvitation.ProjectId = project.ProjectId;
            projectInvitation.token     = token;

            context.ProjectInvitations.Add(projectInvitation);
            int saveResult = await context.SaveChangesAsync();

            return(saveResult == 1);
        }
Ejemplo n.º 8
0
        public bool UserIsInvited(Project project, AppUser user)
        {
            ProjectInvitation invitation = context.ProjectInvitations
                                           .Where(x => x.Email == user.Email)
                                           .Where(x => x.ProjectId == project.ProjectId)
                                           .FirstOrDefault();

            if (invitation != null)
            {
                return(true);
            }
            return(false);
        }
        public async Task <IActionResult> DeclineInvitation(ProjectInvitation projectInvitation)
        {
            //get the current user
            var user = await _userManager.GetUserAsync(HttpContext.User);

            //make sure the invitee in the invitation is the current user
            if (projectInvitation.InviteeId != user.Id)
            {
                return(Unauthorized("Cannot decline invitations if requester is not the invitee"));
            }

            _projectsRepo.DeleteProjectInvite(projectInvitation.ProjectId, projectInvitation.InviteeId);
            _projectsRepo.SaveChanges();

            return(Ok());
        }
Ejemplo n.º 10
0
        public void AddInvitationByInviteeId(long projectId, long inviterId, long inviteeId, string invitationMessage, long inviteePartId = 0)
        {
            var invitation = GetInvitation(projectId, inviterId, inviteeId, inviteePartId);

            if (invitation != null)
            {
                return;
            }
            invitation = new ProjectInvitation
            {
                ProjectId         = projectId,
                InviterId         = inviterId,
                InviteeId         = inviteeId,
                InviteePartId     = inviteePartId,
                InvitationMessage = invitationMessage
            };
            _invitationRepo.Insert(invitation);
        }
Ejemplo n.º 11
0
        public DeleteInvitationStatus DeleteProjectInvitation(int invitationID)
        {
            ProjectInvitation invitation = ProjectInvitations.Get(invitationID);

            if (invitation == null)
            {
                return(DeleteInvitationStatus.NoSuchInvitation);
            }

            if (invitation.TargetProject.OwnerUserID != UserContext.AccountID)
            {
                return(DeleteInvitationStatus.NotOwner);
            }

            ActivityService.ProjectInvitationDeleted(invitation.ID);
            ProjectInvitations.Delete(invitation);
            return(DeleteInvitationStatus.Deleted);
        }
Ejemplo n.º 12
0
        public async Task <bool> AddUserToProject(AppUser invitedUser, ProjectInvitation invitation)
        {
            Project project = await context.Projects.FindAsync(invitation.ProjectId);

            UserProject userProject = new UserProject
            {
                AppUser = invitedUser,
                Project = project
            };

            project.UserProjects = new List <UserProject> {
                userProject
            };

            context.ProjectInvitations.Remove(invitation);
            int saveResult = await context.SaveChangesAsync();

            return(saveResult == 1);
        }
Ejemplo n.º 13
0
        public CreateInvitationStatus InviteToProject(int projectID, string accountPublicIdentifier, int type)
        {
            Project project = ProjectService.Get(projectID);

            if (project == null || !ProjectService.IsUserOwner(projectID))
            {
                return(CreateInvitationStatus.NotOwner);
            }

            UserAccount account = UserService.GetByIdentifier(accountPublicIdentifier);

            if (account == null)
            {
                return(CreateInvitationStatus.NoSuchUser);
            }

            ProjectInvitation other = ProjectInvitations.FirstOrDefault(pi => pi.TargetProjectID == projectID && pi.TargetUserID == account.ID);

            if (other != null)
            {
                if (other.Type == type)
                {
                    return(CreateInvitationStatus.AlreadyExists);
                }

                other.Type = type;
                ProjectInvitations.Update(other);
                return(CreateInvitationStatus.UpdatedExisting);
            }

            ProjectInvitation invitation = new ProjectInvitation
            {
                Created         = DateTime.Now,
                TargetProjectID = projectID,
                TargetUserID    = account.ID,
                OwnerUserID     = project.OwnerUserID,
                Type            = type
            };

            ProjectInvitations.Insert(invitation);
            ActivityService.ProjectInvitationCreated(invitation.ID);
            return(CreateInvitationStatus.Created);
        }
Ejemplo n.º 14
0
 public static ProjectInvitationDto ToDto(this ProjectInvitation invitation)
 {
     if (invitation == null)
     {
         return(null);
     }
     return(new ProjectInvitationDto
     {
         Id = invitation.Id,
         Accepted = invitation.Accepted,
         InvitationMessage = invitation.InvitationMessage,
         InviteeConfirmMessage = invitation.InviteeConfirmMessage,
         InviteeEmail = invitation.InviteeEmail,
         InviteeId = invitation.InviteeId,
         InviteePartId = invitation.InviteePartId,
         InviterId = invitation.InviterId,
         ProjectId = invitation.ProjectId
     });
 }
Ejemplo n.º 15
0
        public void InvitationForProject(int projectId, string guid)
        {
            Invitation invitation = new Invitation
            {
                GUID = guid
            };

            this.Db.Invitation.Add(invitation);
            this.Db.SaveChanges();

            ProjectInvitation projectInvitation = new ProjectInvitation
            {
                InvitationId = invitation.Id,
                ProjectId    = projectId
            };

            this.Db.ProjectInvitation.Add(projectInvitation);
            this.Db.SaveChanges();
        }
        public async Task <IActionResult> InviteToProject([FromBody] UtilityInviteModel inviteModel)
        {
            //get the current user
            var user = await _userManager.GetUserAsync(HttpContext.User);

            //make sure the user who is making the request is a project administrator
            if (!_validation.userIsProjectAdministrator(user.Id, inviteModel.projectId))
            {
                return(Unauthorized());
            }

            var invitee = _usersRepo.GetUserByUserName(inviteModel.inviteeUserName);

            //if no user with the username exists
            if (invitee == null)
            {
                return(NotFound("User with the given username does not exist"));
            }

            //if the user is already part of the project
            if (_validation.userIsProjectMember(invitee.Id, inviteModel.projectId))
            {
                return(BadRequest("This user is already a member of the project"));
            }

            //if the user has already been invited to the project
            if (_projectsRepo.HasUserBeenInvited(inviteModel.projectId, invitee.Id) == true)
            {
                return(BadRequest("This user has already been invited to join this project"));
            }

            //build project invitation object
            ProjectInvitation projectInvitation = new ProjectInvitation();

            projectInvitation.ProjectId = inviteModel.projectId;
            projectInvitation.InviterId = user.Id;
            projectInvitation.InviteeId = invitee.Id;
            _projectsRepo.AddProjectInvite(projectInvitation);
            _projectsRepo.SaveChanges();

            return(Ok(invitee));
        }
Ejemplo n.º 17
0
        public async Task <ProjectInvitation> GetInvitation(string token)
        {
            ProjectInvitation invitation = await context.ProjectInvitations.FindAsync(token);

            return(invitation);
        }
Ejemplo n.º 18
0
        public async Task <IActionResult> Invite(string userSlug, string projectSlug, ProjectInvitation projectInvitation)
        {
            if (!ModelState.IsValid)
            {
                return(RedirectToAction("Index"));
            }

            AppUser projectOwner = InvitationService.GetProjectOwner(userSlug);

            Project project = InvitationService.GetProject(projectOwner, projectSlug);

            if (project == null)
            {
                return(NotFound());
            }

            AppUser invitedUser = await userManager.FindByEmailAsync(projectInvitation.Email);

            //AppUser invitedUser = await userManager.FindByIdAsync(projectInvitation.Email);
            if (invitedUser == null)
            {
                TempData["Error"] = "The user doesn't exist";
                return(RedirectToAction("Index"));
            }

            if (InvitationService.UserInProject(project, invitedUser))
            {
                TempData["Error"] = "The user is allready a part of the project";
                return(RedirectToAction("Index"));
            }

            if (InvitationService.UserIsInvited(project, invitedUser))
            {
                TempData["Error"] = "The user has allready been invited";
                return(RedirectToAction("Index"));
            }

            string token = await userManager.GenerateUserTokenAsync(invitedUser, "Default", "ProjectInvitation");

            string confirmationLink = "https://localhost:44388" + Url.Action("ConfirmInvitation", "Invitations", new { token = token });

            bool successful = await InvitationService.CreateInvitation(projectInvitation, project, invitedUser, token);

            if (!successful)
            {
                return(BadRequest("Could not create invitation"));
            }

            InvitationService.SendInvitation(invitedUser, confirmationLink);

            TempData["Success"] = "An invatation has been sent to " + invitedUser.Email;

            return(RedirectToAction("Index"));
        }
Ejemplo n.º 19
0
        public CreateInvitationStatus InviteToProject(int projectID, string accountPublicIdentifier, int type)
        {
            Project project = ProjectService.Get(projectID);
            if (project == null || !ProjectService.IsUserOwner(projectID))
                return CreateInvitationStatus.NotOwner;

            UserAccount account = UserService.GetByIdentifier(accountPublicIdentifier);
            if (account == null)
                return CreateInvitationStatus.NoSuchUser;

            ProjectInvitation other = ProjectInvitations.FirstOrDefault(pi => pi.TargetProjectID == projectID && pi.TargetUserID == account.ID);
            if (other != null)
            {
                if (other.Type == type)
                    return CreateInvitationStatus.AlreadyExists;

                other.Type = type;
                ProjectInvitations.Update(other);
                return CreateInvitationStatus.UpdatedExisting;
            }

            ProjectInvitation invitation = new ProjectInvitation
            {
                Created = DateTime.Now,
                TargetProjectID = projectID,
                TargetUserID = account.ID,
                OwnerUserID = project.OwnerUserID,
                Type = type
            };
            ProjectInvitations.Insert(invitation);
            ActivityService.ProjectInvitationCreated(invitation.ID);
            return CreateInvitationStatus.Created;
        }
Ejemplo n.º 20
0
        public async Task <IActionResult> InviteMany([FromRoute] string userSlug, [FromRoute] string projectSlug, string[] emails)
        {
            System.Diagnostics.Debug.WriteLine("in invitemany");

            System.Diagnostics.Debug.WriteLine(userSlug);
            System.Diagnostics.Debug.WriteLine(projectSlug);

            System.Diagnostics.Debug.WriteLine(emails);



            if (!ModelState.IsValid)
            {
                System.Diagnostics.Debug.WriteLine("modelstate not valid");
                return(RedirectToAction("Index"));
            }


            System.Diagnostics.Debug.WriteLine("in invitemany2");

            AppUser projectOwner = InvitationService.GetProjectOwner(userSlug);

            System.Diagnostics.Debug.WriteLine("in invitemany3");

            Project project = InvitationService.GetProject(projectOwner, projectSlug);

            System.Diagnostics.Debug.WriteLine("in invitemany4");

            if (project == null)
            {
                return(NotFound());
            }

            System.Diagnostics.Debug.WriteLine("in invitemany5");

            foreach (string email in emails)
            {
                System.Diagnostics.Debug.WriteLine(email);
                AppUser invitedUser = await userManager.FindByEmailAsync(email);


                //if (invitedUser == null)
                //{
                //    return StatusCode(500);
                //}

                //if (invitedUser == null)
                //{
                //    return StatusCode(500);
                //}

                //if (InvitationService.UserInProject(project, invitedUser))
                //{
                //    return StatusCode(500);
                //}

                //if (InvitationService.UserIsInvited(project, invitedUser))
                //{
                //    return StatusCode(500);
                //}


                ProjectInvitation projectInvitation = new ProjectInvitation
                {
                };
                System.Diagnostics.Debug.WriteLine("5");
                string token = await userManager.GenerateUserTokenAsync(invitedUser, "Default", "ProjectInvitation");

                string confirmationLink = "https://localhost:44388" + Url.Action("ConfirmInvitation", "Invitations", new { token = token });
                System.Diagnostics.Debug.WriteLine("6");
                bool successful = await InvitationService.CreateInvitation(projectInvitation, project, invitedUser, token);

                if (!successful)
                {
                    System.Diagnostics.Debug.WriteLine("failed to invite");
                    return(BadRequest("Could not create invitation"));
                }
                System.Diagnostics.Debug.WriteLine("7");

                InvitationService.SendInvitation(invitedUser, confirmationLink);
                System.Diagnostics.Debug.WriteLine("8");
            }

            System.Diagnostics.Debug.WriteLine("9");
            return(Ok());
        }
Ejemplo n.º 21
0
        /// <summary>
        /// Asynchronously sends invitation to each of the users specified.
        /// </summary>
        private async Task InviteAsync(
            ActionLink actionLink,
            AuthTicket authTicket,
            ContactItem contact,
            WorkflowInvitationDto model,
            CancellationToken cancellationToken)
        {
            if (actionLink == null)
            {
                throw new ArgumentNullException(nameof(actionLink));
            }
            if (model == null)
            {
                throw new ArgumentNullException(nameof(model));
            }
            if (model.Action == null)
            {
                throw new InvalidOperationException("An action link with the given ID was not found.");
            }
            if (model.To == null || model.To.Length == 0)
            {
                throw new InvalidOperationException("At least one person is required for invitation.");
            }
            var invActionLinkParams = _actionLinkService.DecodeLink(model.Action);

            var action = await _projectManager.GetActionByIdAsync(invActionLinkParams.ActionId, cancellationToken);

            if (action == null)
            {
                throw new InvalidOperationException($"The specified action link was not found: {invActionLinkParams.ToString()}");
            }

            var project = await _projectManager.FindByIdAsync(action.Project.Id, cancellationToken);

            var context    = Request.Properties["MS_HttpContext"] as HttpContextWrapper;
            var logEvent   = context.Request.CreateEvent();
            var invitation = new ProjectInvitation {
                From = contact, Message = model.Message, To = model.To.Select(c => c.ToContact())
            };
            var properties = new PropertyDictionary {
                { "Invitation", invitation }
            };

            foreach (var to in invitation.To.Where(to => to != null))
            {
                var eventItem = new EventItem
                {
                    AnonymId       = logEvent.AnonymId,
                    Project        = project,
                    ClientId       = logEvent.ClientId,
                    CustomUri      = actionLink.CustomUri,
                    BrowserBrand   = logEvent.BrowserBrand,
                    BrowserVersion = logEvent.BrowserVersion,
                    MobileDevice   = logEvent.MobileDevice,
                    ReferrerUrl    = logEvent.ReferrerUrl
                };
                await _workflowInvoker.InvokeAsync(new ActionActivityContext(
                                                       project : project,
                                                       action : action,
                                                       authTicket : authTicket,
                                                       contact : to,
                                                       contactState : ObjectState.Unchanged,
                                                       properties : properties,
                                                       eventItem : eventItem), cancellationToken);
            }
        }