public ActionResult AddTeamMembers(string projectSeriesGuid, string userNames, string permissions)
        {
            return(ActionUtils.Json(() =>
            {
                CommUtils.Assert(!string.IsNullOrWhiteSpace(permissions), "权限类型不能为空");
                var permissionList = CommUtils.ParseEnumList <PermissionType>(permissions, true);
                CommUtils.Assert(permissionList.Any(x => x == PermissionType.Read), "增加项目成员时,只读权限必须勾选");
                //判断操作者权限
                var projectSeriesLogicModel = new ProjectSeriesLogicModel(CurrentUserName, projectSeriesGuid);
                var project = projectSeriesLogicModel.CurrentProject.Instance;
                CommUtils.Assert(IsAdmin(projectSeriesLogicModel.Instance, CurrentUserName) ||
                                 m_dbAdapter.TeamAdmin.IsTeamAdmin(project.ProjectId, CurrentUserName),
                                 "当前用户[{0}]不是项目[{1}]的创建者/负责人/管理员", Platform.UserProfile.GetDisplayRealNameAndUserName(CurrentUserName),
                                 projectSeriesLogicModel.Instance.Name);

                //判断传入userName是否有效
                var userNameList = CommUtils.Split(userNames);
                foreach (var userName in userNameList)
                {
                    CommUtils.Assert(m_dbAdapter.Authority.IsUserExist(userName), "用户[{0}]不存在", userName);
                    CommUtils.Assert((!IsAdmin(projectSeriesLogicModel.Instance, userName)) &&
                                     (!m_dbAdapter.TeamAdmin.IsTeamAdmin(project.ProjectId, userName)),
                                     "用户[{0}]是产品创建者/负责人/管理员,无法增加至项目成员", userName);
                }

                //判断项目成员是否已经添加
                var teamMembers = m_dbAdapter.TeamMember.GetByProjectId(project.ProjectId);
                foreach (var teamMember in teamMembers)
                {
                    CommUtils.Assert(!userNameList.Contains(teamMember.UserName),
                                     "项目成员中已经存在用户[{0}]", teamMember.UserName);
                }

                var projectActivityLogicModel = projectSeriesLogicModel.CurrentProject.Activity;

                //添加项目成员
                foreach (var userName in userNameList)
                {
                    var teamMember = new TeamMember
                    {
                        UserName = userName,
                        ProjectId = project.ProjectId,
                        Read = permissionList.Any(x => x == PermissionType.Read),
                        Write = permissionList.Any(x => x == PermissionType.Write),
                        Execute = permissionList.Any(x => x == PermissionType.Execute)
                    };

                    m_dbAdapter.TeamMember.Add(teamMember);
                    projectActivityLogicModel.Add(project.ProjectId, ActivityObjectType.TeamMember, teamMember.Guid, "增加项目成员:" + Platform.UserProfile.Get(teamMember.UserName).RealName);
                }

                teamMembers = m_dbAdapter.TeamMember.GetByProjectId(project.ProjectId);
                var newTeamMembers = teamMembers.Where(x => userNameList.Contains(x.UserName)).ToList();
                var adminUserNames = new List <string>();
                var teamAdmins = new List <TeamAdmin>();

                var permissionLogicModel = new PermissionLogicModel(CurrentUserName, projectSeriesLogicModel.Instance);
                permissionLogicModel.AddUserPermissionByProjectSeries(newTeamMembers, teamAdmins, adminUserNames);

                return ActionUtils.Success(1);
            }));
        }
Example #2
0
        public ActionResult AddTeamAdmins(string projectSeriesGuid, string userNames)
        {
            return(ActionUtils.Json(() =>
            {
                //判断操作者权限
                var projectSeriesLogicModel = new ProjectSeriesLogicModel(CurrentUserName, projectSeriesGuid);
                CommUtils.Assert(IsAdmin(projectSeriesLogicModel.Instance, CurrentUserName),
                                 "当前用户[{0}]不是项目[{1}]的创建者/负责人", Platform.UserProfile.GetDisplayRealNameAndUserName(CurrentUserName),
                                 projectSeriesLogicModel.Instance.Name);

                //判断传入userName是否有效
                var userNameList = CommUtils.Split(userNames);
                foreach (var userName in userNameList)
                {
                    CommUtils.Assert(m_dbAdapter.Authority.IsUserExist(userName), "用户[{0}]不存在", userName);
                    CommUtils.Assert(!IsAdmin(projectSeriesLogicModel.Instance, userName),
                                     "用户[{0}]是产品创建者/负责人,无法增加至项目管理员", userName);
                }

                //判断项目管理员是否已经添加
                var project = projectSeriesLogicModel.CurrentProject.Instance;
                var teamAdmins = m_dbAdapter.TeamAdmin.GetByProjectId(project.ProjectId);
                foreach (var teamAdmin in teamAdmins)
                {
                    CommUtils.Assert(!userNameList.Contains(teamAdmin.UserName),
                                     "项目管理员中已经存在用户[{0}]", teamAdmin.UserName);
                }

                var projectActivityLogicModel = projectSeriesLogicModel.CurrentProject.Activity;

                //添加项目管理员
                var teamMemberList = m_dbAdapter.TeamMember.GetByProjectId(project.ProjectId);
                var teamMemberDic = teamMemberList.ToDictionary(x => x.UserName);
                var teamMembeUserNames = teamMemberList.Select(x => x.UserName).ToList();
                foreach (var userName in userNameList)
                {
                    var teamAdmin = new TeamAdmin
                    {
                        UserName = userName,
                        ProjectId = project.ProjectId
                    };

                    m_dbAdapter.TeamAdmin.New(teamAdmin);
                    projectActivityLogicModel.Add(project.ProjectId, ActivityObjectType.TeamAdmin, teamAdmin.Guid, "增加项目管理员:" + Platform.UserProfile.Get(teamAdmin.UserName).RealName);

                    if (teamMembeUserNames.Contains(userName))
                    {
                        m_dbAdapter.TeamMember.Remove(teamMemberDic[userName]);
                    }
                }

                var teamMembers = new List <TeamMember>();
                teamAdmins = m_dbAdapter.TeamAdmin.GetByProjectId(project.ProjectId);
                var newTeamAdmins = teamAdmins.Where(x => userNameList.Contains(x.UserName)).ToList();
                var adminUserNames = new List <string>();

                var permissionLogicModel = new PermissionLogicModel(CurrentUserName, projectSeriesLogicModel.Instance);
                permissionLogicModel.AddUserPermissionByProjectSeries(teamMembers, newTeamAdmins, adminUserNames);

                return ActionUtils.Success(1);
            }));
        }
        public ActionResult ResetAllTeamMemberPermission(string projectSeriesGuid)
        {
            return(ActionUtils.Json(() =>
            {
                //获取所有有读取权限的用户
                var projectSeriesLogicModel = new ProjectSeriesLogicModel(CurrentUserName, projectSeriesGuid);
                var project = projectSeriesLogicModel.CurrentProject.Instance;
                CommUtils.Assert(IsAdmin(projectSeriesLogicModel.Instance, CurrentUserName) ||
                                 m_dbAdapter.TeamAdmin.IsTeamAdmin(project.ProjectId, CurrentUserName),
                                 "当前用户[{0}]不是项目[{1}]的创建者/负责人/管理员", Platform.UserProfile.GetDisplayRealNameAndUserName(CurrentUserName),
                                 projectSeriesLogicModel.Instance.Name);

                //只保留项目成员
                var projectSeries = projectSeriesLogicModel.Instance;
                var permissionList = m_dbAdapter.Permission.GetByObjectUid(projectSeriesGuid, PermissionObjectType.ProjectSeries, PermissionType.Read);
                var userNames = permissionList.Select(x => x.UserName).Distinct(StringComparer.OrdinalIgnoreCase).ToList();
                userNames.RemoveAll(x => IsAdmin(projectSeries, x) || m_dbAdapter.TeamAdmin.IsTeamAdmin(project.ProjectId, x));

                //从TeamMember表中移除没有读取权限的成员
                var teamMembers = m_dbAdapter.TeamMember.GetByProjectId(project.ProjectId);
                foreach (var teamMember in teamMembers)
                {
                    if (!userNames.Contains(teamMember.UserName))
                    {
                        m_dbAdapter.TeamMember.Remove(teamMember);
                    }
                }

                //增加有读取权限的成员到TeamMember中
                foreach (var userName in userNames)
                {
                    if (!teamMembers.Any(x => x.UserName.Equals(userName, StringComparison.CurrentCultureIgnoreCase)))
                    {
                        var teamMember = new TeamMember {
                            UserName = userName,
                            ProjectId = project.ProjectId,
                            Read = true,
                            Write = false,
                            Execute = false
                        };

                        m_dbAdapter.TeamMember.Add(teamMember);
                    }
                }

                //获取管理员(负责人 + 创建者)
                var adminUserNames = new List <string> {
                    projectSeries.CreateUserName, projectSeries.PersonInCharge
                };
                adminUserNames = adminUserNames.Distinct(StringComparer.OrdinalIgnoreCase).ToList();

                //获取所有项目成员
                teamMembers = m_dbAdapter.TeamMember.GetByProjectId(project.ProjectId);

                var teamAdmins = m_dbAdapter.TeamAdmin.GetByProjectId(project.ProjectId);

                var permissionLogicModel = new PermissionLogicModel(CurrentUserName, projectSeriesLogicModel.Instance);
                permissionLogicModel.AddUserPermissionByProjectSeries(teamMembers, teamAdmins, adminUserNames);

                return ActionUtils.Success(1);
            }));
        }
        public ActionResult ModifyProjectSeriesInfo(string projectSeriesGuid, string name, string projectSeriesType, string personInCharge, string createTime, string estimatedFinishTime, string email)
        {
            return(ActionUtils.Json(() =>
            {
                ValidateUtils.Name(name, "项目名称");
                CommUtils.Assert(email.Length <= 38, "名称不能超过38个字符数");
                CommUtils.AssertHasContent(personInCharge, "[项目负责人]不能为空");
                CommUtils.Assert(m_dbAdapter.Authority.IsUserExist(personInCharge), "[用户]不存在");

                CommUtils.AssertHasContent(createTime, "[立项日期]不能为空");
                CommUtils.AssertHasContent(estimatedFinishTime, "[计划完成日期]不能为空");

                var valStartTime = DateTime.Parse(createTime);
                var valEstimatedFinishTime = DateTime.Parse(estimatedFinishTime);
                CommUtils.Assert(valEstimatedFinishTime >= valStartTime, "计划完成日期[{0}]必须大于等于立项日期[{1}]", valEstimatedFinishTime, valStartTime);

                var type = CommUtils.ParseEnum <ProjectSeriesType>(projectSeriesType);
                var projectSeriesLogicModel = new ProjectSeriesLogicModel(CurrentUserName, projectSeriesGuid);
                var projectSeries = projectSeriesLogicModel.Instance;
                var project = projectSeriesLogicModel.CurrentProject.Instance;

                CommUtils.Assert(IsCurrentUser(projectSeries.CreateUserName) ||
                                 IsCurrentUser(projectSeries.PersonInCharge) ||
                                 m_dbAdapter.TeamAdmin.IsTeamAdmin(project.ProjectId, CurrentUserName),
                                 "当前用户[{0}]不是项目[{1}]的管理员/创建者/负责人,无法进行修改", CurrentUserName, projectSeries.Name);

                CommUtils.Assert(!m_dbAdapter.TeamAdmin.IsTeamAdmin(project.ProjectId, CurrentUserName) ||
                                 personInCharge == projectSeries.PersonInCharge,
                                 "当前用户[{0}]是项目[{1}]的管理员,无法修改负责人", CurrentUserName, projectSeries.Name);

                var isAdmin = projectSeries.CreateUserName.Equals(personInCharge, StringComparison.CurrentCultureIgnoreCase) ||
                              projectSeries.PersonInCharge.Equals(personInCharge, StringComparison.CurrentCultureIgnoreCase); //////////////

                var permissionLogicModel = new PermissionLogicModel(CurrentUserName, projectSeries);
                var teamAdmins = m_dbAdapter.TeamAdmin.GetByProjectId(project.ProjectId);
                var teamMembers = m_dbAdapter.TeamMember.GetByProjectId(project.ProjectId);
                var teamMember = new TeamMember
                {
                    UserName = projectSeries.PersonInCharge,
                    ProjectId = project.ProjectId,
                    Read = true,
                    Write = false,
                    Execute = false
                };



                if (!isAdmin)
                {
                    if (!projectSeries.CreateUserName.Equals(projectSeries.PersonInCharge, StringComparison.CurrentCultureIgnoreCase))
                    {
                        //删除原有负责人的所有权限,将其添加为项目成员
                        permissionLogicModel.RemoveUserPermissionByProjectSeries(new List <string> {
                            projectSeries.PersonInCharge
                        });
                        m_dbAdapter.TeamMember.Add(teamMember);
                        permissionLogicModel.AddUserPermissionByProjectSeries(new List <TeamMember> {
                            teamMember
                        }, new List <TeamAdmin>(), new List <string>());
                    }

                    foreach (var item in teamMembers)
                    {
                        //如果新的负责人为原有的项目成员,则在项目成员里移除
                        if (item.UserName.Equals(personInCharge, StringComparison.CurrentCultureIgnoreCase))
                        {
                            m_dbAdapter.TeamMember.Remove(item);
                            permissionLogicModel.RemoveUserPermissionByProjectSeries(new List <string> {
                                personInCharge
                            });
                        }
                    }

                    foreach (var item in teamAdmins)
                    {
                        //如果新的负责人为原有的项目管理员,则在项目管理员里移除
                        if (item.UserName.Equals(personInCharge, StringComparison.CurrentCultureIgnoreCase))
                        {
                            m_dbAdapter.TeamAdmin.Delete(item);
                            permissionLogicModel.RemoveUserPermissionByProjectSeries(new List <string> {
                                personInCharge
                            });
                        }
                    }

                    permissionLogicModel.AddUserPermissionByProjectSeries(new List <TeamMember>(), new List <TeamAdmin>(), new List <string> {
                        personInCharge
                    });
                }
                else
                {
                    if (!projectSeries.PersonInCharge.Equals(personInCharge, StringComparison.CurrentCultureIgnoreCase))
                    {
                        //删除原有负责人的所有权限,将其添加为项目成员
                        permissionLogicModel.RemoveUserPermissionByProjectSeries(new List <string> {
                            projectSeries.PersonInCharge
                        });
                        m_dbAdapter.TeamMember.Add(teamMember);
                        permissionLogicModel.AddUserPermissionByProjectSeries(new List <TeamMember> {
                            teamMember
                        }, new List <TeamAdmin>(), new List <string>());
                    }
                }

                //同步产品系列名字与产品名字一致
                if (projectSeries.Name != name)
                {
                    project.Name = name;
                    m_dbAdapter.Project.Update(project);
                }

                projectSeries.Name = name;
                projectSeries.Type = type;
                projectSeries.CreateTime = valStartTime;
                projectSeries.EstimatedFinishTime = valEstimatedFinishTime;
                projectSeries.PersonInCharge = personInCharge;
                projectSeries.Email = email;

                m_dbAdapter.ProjectSeries.UpdateProjectSeries(projectSeries);

                return ActionUtils.Success(1);
            }));
        }