public ActionResult ExitProjectSeries(string projectSeriesGuid) { return(ActionUtils.Json(() => { CheckPermission(PermissionObjectType.ProjectSeries, projectSeriesGuid, PermissionType.Read); var projectSeriesLogicModel = new ProjectSeriesLogicModel(CurrentUserName, projectSeriesGuid); var projectSeries = projectSeriesLogicModel.Instance; CommUtils.Assert(!IsCurrentUser(projectSeries.CreateUserName), "当前用户[{0}]是项目[{1}]的创建者,不能退出项目", CurrentUserName, projectSeries.Name); var projectLogicModel = projectSeriesLogicModel.CurrentProject; var project = projectLogicModel.Instance; var permissionLogicModel = new PermissionLogicModel(CurrentUserName, projectSeries); if (IsCurrentUser(projectSeries.PersonInCharge)) { projectSeries.PersonInCharge = projectSeries.CreateUserName; permissionLogicModel.RemoveUserPermissionByProjectSeries(new List <string>() { CurrentUserName }); } else if (m_dbAdapter.TeamAdmin.IsTeamAdmin(project.ProjectId, CurrentUserName)) { var teamAdmins = m_dbAdapter.TeamAdmin.GetByProjectId(project.ProjectId); var teamAdmin = teamAdmins.FirstOrDefault(x => x.UserName.Equals(CurrentUserName, StringComparison.CurrentCultureIgnoreCase)); m_dbAdapter.TeamAdmin.Delete(teamAdmin); permissionLogicModel.RemoveUserPermissionByProjectSeries(new List <string>() { CurrentUserName }); } else if (m_dbAdapter.TeamMember.IsTeamMember(project.ProjectId, CurrentUserName)) { var teamMembers = m_dbAdapter.TeamMember.GetByProjectId(project.ProjectId); var teamMember = teamMembers.FirstOrDefault(x => x.UserName.Equals(CurrentUserName, StringComparison.CurrentCultureIgnoreCase)); m_dbAdapter.TeamMember.Remove(teamMember); permissionLogicModel.RemoveUserPermissionByProjectSeries(new List <string>() { CurrentUserName }); } return ActionUtils.Success(1); })); }
public ActionResult RemoveTeamMembers(string projectSeriesGuid, string userNames) { 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 teamMembers = m_dbAdapter.TeamMember.GetByProjectId(project.ProjectId); var userNameList = CommUtils.Split(userNames).ToList(); foreach (var userName in userNameList) { CommUtils.Assert(teamMembers.Any(x => x.UserName.Equals(userName, StringComparison.CurrentCultureIgnoreCase)), "查找项目成员[{0}]失败", userName); CommUtils.Assert((!IsAdmin(projectSeriesLogicModel.Instance, userName)) && (!m_dbAdapter.TeamAdmin.IsTeamAdmin(project.ProjectId, userName)), "检测到[{0}]是产品创建者/负责人,移除项目成员失败", userName); } var projectActivityLogicModel = projectSeriesLogicModel.CurrentProject.Activity; teamMembers = teamMembers.Where(x => userNameList.Contains(x.UserName)).ToList(); foreach (var teamMember in teamMembers) { m_dbAdapter.TeamMember.Remove(teamMember); projectActivityLogicModel.Add(project.ProjectId, ActivityObjectType.TeamMember, teamMember.Guid, "删除项目成员:" + Platform.UserProfile.Get(teamMember.UserName).RealName); } var permissionLogicModel = new PermissionLogicModel(CurrentUserName, projectSeriesLogicModel.Instance); permissionLogicModel.RemoveUserPermissionByProjectSeries(userNameList); 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); })); }