public void AddLink(Task parentTask, Task dependentTask, TaskLinkType linkType) { CheckLink(parentTask, dependentTask, linkType); var link = new TaskLink { ParentTaskId = parentTask.ID, DependenceTaskId = dependentTask.ID, LinkType = linkType }; if (DaoFactory.TaskDao.IsExistLink(link)) { throw new Exception("link already exist"); } ProjectSecurity.DemandEdit(dependentTask); ProjectSecurity.DemandEdit(parentTask); parentTask.Links.Add(link); dependentTask.Links.Add(link); DaoFactory.TaskDao.AddLink(link); }
public void AttachFile(ProjectEntity entity, object fileId, bool notify = false) { if (!ProjectSecurity.CanReadFiles(entity.Project)) { return; } File file; using (var dao = FilesIntegration.GetTagDao()) { dao.SaveTags(new Tag(entity.GetType().Name + entity.ID, TagType.System, Guid.Empty) { EntryType = FileEntryType.File, EntryId = fileId }); file = FileEngine.GetFile(fileId, 0); } if (notify && !Factory.DisableNotifications) { var senders = GetSubscribers(entity); NotifyClient.Instance.SendNewFile(senders, entity, file.Title); } }
public void SetTeamSecurity(Project project, Guid participant, ProjectTeamSecurity teamSecurity, bool visible) { if (project == null) { throw new ArgumentNullException("project"); } ProjectSecurity.DemandEditTeam(project); var security = projectDao.GetTeamSecurity(project.ID, participant); if (visible) { if (security != ProjectTeamSecurity.None) { security ^= teamSecurity; } } else { security |= teamSecurity; } projectDao.SetTeamSecurity(project.ID, participant, security); }
public void Delete(Message message) { if (message == null) { throw new ArgumentNullException("message"); } if (message.Project == null) { throw new Exception("Project"); } ProjectSecurity.DemandEdit(message); DaoFactory.MessageDao.Delete(message.ID); var recipients = GetSubscribers(message); if (recipients.Any() && !DisableNotifications) { NotifyClient.Instance.SendAboutMessageDeleting(recipients, message); } UnSubscribeAll(message); }
public Subtask SaveOrUpdate(Subtask subtask, Task task) { if (subtask == null) { throw new Exception("subtask.Task"); } if (task == null) { throw new ArgumentNullException("task"); } if (task.Status == TaskStatus.Closed) { throw new Exception("task can't be closed"); } // check guest responsible if (ProjectSecurity.IsVisitor(subtask.Responsible)) { ProjectSecurity.CreateGuestSecurityException(); } var isNew = subtask.ID == default(int); //Task is new var oldResponsible = Guid.Empty; subtask.LastModifiedBy = SecurityContext.CurrentAccount.ID; subtask.LastModifiedOn = TenantUtil.DateTimeNow(); if (isNew) { if (subtask.CreateBy == default(Guid)) { subtask.CreateBy = SecurityContext.CurrentAccount.ID; } if (subtask.CreateOn == default(DateTime)) { subtask.CreateOn = TenantUtil.DateTimeNow(); } ProjectSecurity.DemandEdit(task); subtask = DaoFactory.SubtaskDao.Save(subtask); } else { var oldSubtask = DaoFactory.SubtaskDao.GetById(new[] { subtask.ID }).First(); if (oldSubtask == null) { throw new ArgumentNullException("subtask"); } oldResponsible = oldSubtask.Responsible; //changed task ProjectSecurity.DemandEdit(task, oldSubtask); subtask = DaoFactory.SubtaskDao.Save(subtask); } NotifySubtask(task, subtask, isNew, oldResponsible); var senders = new HashSet <Guid> { subtask.Responsible, subtask.CreateBy }; senders.Remove(Guid.Empty); foreach (var sender in senders) { Subscribe(task, sender); } return(subtask); }
public Milestone SaveOrUpdate(Milestone milestone, bool notifyResponsible, bool import) { if (milestone == null) { throw new ArgumentNullException("milestone"); } if (milestone.Project == null) { throw new Exception("milestone.project is null"); } if (milestone.Responsible.Equals(Guid.Empty)) { throw new Exception("milestone.responsible is empty"); } // check guest responsible if (ProjectSecurity.IsVisitor(milestone.Responsible)) { ProjectSecurity.CreateGuestSecurityException(); } milestone.LastModifiedBy = SecurityContext.CurrentAccount.ID; milestone.LastModifiedOn = TenantUtil.DateTimeNow(); var isNew = milestone.ID == default(int);//Task is new var oldResponsible = Guid.Empty; if (isNew) { if (milestone.CreateBy == default(Guid)) { milestone.CreateBy = SecurityContext.CurrentAccount.ID; } if (milestone.CreateOn == default(DateTime)) { milestone.CreateOn = TenantUtil.DateTimeNow(); } ProjectSecurity.DemandCreate <Milestone>(milestone.Project); milestone = DaoFactory.MilestoneDao.Save(milestone); } else { var oldMilestone = DaoFactory.MilestoneDao.GetById(new[] { milestone.ID }).FirstOrDefault(); if (oldMilestone == null) { throw new ArgumentNullException("milestone"); } oldResponsible = oldMilestone.Responsible; ProjectSecurity.DemandEdit(milestone); milestone = DaoFactory.MilestoneDao.Save(milestone); } if (!milestone.Responsible.Equals(Guid.Empty)) { NotifyMilestone(milestone, notifyResponsible, isNew, oldResponsible); } FactoryIndexer <MilestonesWrapper> .IndexAsync(milestone); return(milestone); }
public TaskFilterOperationResult GetByFilter(TaskFilter filter) { if (filter.Offset < 0 || filter.Max < 0) { return(null); } var isAdmin = ProjectSecurity.IsAdministrator(SecurityContext.CurrentAccount.ID); var anyOne = ProjectSecurity.IsPrivateDisabled; var count = taskDao.GetByFilterCount(filter, isAdmin, anyOne); var filterLimit = filter.Max; var filterOffset = filter.Offset; if (filterOffset > count.TasksTotal) { return(new TaskFilterOperationResult(count)); //there are some records but we cant see them due to offset } var taskList = new List <Task>(); if (filter.HasTaskStatuses) { taskList = taskDao.GetByFilter(filter, isAdmin, anyOne); } else if (filterOffset > count.TasksOpen && count.TasksClosed != 0) { filter.TaskStatuses.Add(TaskStatus.Closed); filter.Offset = filterOffset - count.TasksOpen; taskList = taskDao.GetByFilter(filter, isAdmin, anyOne); } else { //TODO: to one sql query using UNION ALL if (count.TasksOpen != 0) { filter.TaskStatuses.Add(TaskStatus.Open); taskList = taskDao.GetByFilter(filter, isAdmin, anyOne); } if (taskList.Count < filterLimit && count.TasksClosed != 0) { filter.TaskStatuses.Clear(); filter.TaskStatuses.Add(TaskStatus.Closed); filter.Offset = 0; filter.Max = filterLimit - taskList.Count; taskList.AddRange(taskDao.GetByFilter(filter, isAdmin, anyOne)); } } filter.Offset = filterOffset; filter.Max = filterLimit; filter.TaskStatuses.Clear(); subtaskDao.GetSubtasks(ref taskList); var taskLinks = taskDao.GetLinks(taskList).ToList(); taskList = taskList.GroupJoin(taskLinks, task => task.ID, link => link.DependenceTaskId, (task, linksCol) => { task.Links.AddRange(linksCol); return(task); }).ToList(); taskList = taskList.GroupJoin(taskLinks, task => task.ID, link => link.ParentTaskId, (task, linksCol) => { task.Links.AddRange(linksCol); return(task); }).ToList(); return(new TaskFilterOperationResult(taskList, count)); }
private static bool CanRead(Task task) { return(ProjectSecurity.CanRead(task)); }
public List <TimeSpend> GetByProject(int projectId) { var timeSpend = timeSpendDao.GetByProject(projectId); return(GetTasks(timeSpend).FindAll(r => ProjectSecurity.CanRead(r.Task))); }
public List <SearchGroup> Search(String searchText, int projectId) { var queryResult = _searchDao.Search(searchText, projectId); var groups = new Dictionary <int, SearchGroup>(); foreach (var r in queryResult) { var projId = 0; SearchItem item = null; if (r is Project) { var p = (Project)r; if (ProjectSecurity.CanRead(p)) { projId = p.ID; if (!groups.ContainsKey(projId)) { groups[projId] = new SearchGroup(projId, p.Title); } item = new SearchItem(EntityType.Project, p.ID, p.Title, p.Description, p.CreateOn); } } else { if (r is Milestone) { var m = (Milestone)r; if (ProjectSecurity.CanRead(m)) { projId = m.Project.ID; if (!groups.ContainsKey(projId)) { groups[projId] = new SearchGroup(projId, m.Project.Title); } item = new SearchItem(EntityType.Milestone, m.ID, m.Title, null, m.CreateOn); } } else if (r is Message) { var m = (Message)r; if (ProjectSecurity.CanReadMessages(m.Project)) { projId = m.Project.ID; if (!groups.ContainsKey(projId)) { groups[projId] = new SearchGroup(projId, m.Project.Title); } item = new SearchItem(EntityType.Message, m.ID, m.Title, m.Content, m.CreateOn); } } else if (r is Task) { var t = (Task)r; if (ProjectSecurity.CanRead(t)) { projId = t.Project.ID; if (!groups.ContainsKey(projId)) { groups[projId] = new SearchGroup(projId, t.Project.Title); } item = new SearchItem(EntityType.Task, t.ID, t.Title, t.Description, t.CreateOn); } } } if (0 < projId && item != null) { groups[projId].Items.Add(item); } } try { // search in files var fileEntries = new List <Files.Core.FileEntry>(); using (var folderDao = FilesIntegration.GetFolderDao()) using (var fileDao = FilesIntegration.GetFileDao()) { fileEntries.AddRange(folderDao.Search(searchText, Files.Core.FolderType.BUNCH).Cast <Files.Core.FileEntry>()); fileEntries.AddRange(fileDao.Search(searchText, Files.Core.FolderType.BUNCH).Cast <Files.Core.FileEntry>()); var projectIds = projectId != 0 ? new List <int> { projectId } : fileEntries.GroupBy(f => f.RootFolderId) .Select(g => folderDao.GetFolder(g.Key)) .Select(f => f != null ? folderDao.GetBunchObjectID(f.RootFolderId).Split('/').Last() : null) .Where(s => !string.IsNullOrEmpty(s)) .Select(s => int.Parse(s)); var rootProject = projectIds.ToDictionary(id => FilesIntegration.RegisterBunch("projects", "project", id.ToString())); fileEntries.RemoveAll(f => !rootProject.ContainsKey(f.RootFolderId)); var security = FilesIntegration.GetFileSecurity(); fileEntries.RemoveAll(f => !security.CanRead(f)); foreach (var f in fileEntries) { var id = rootProject[f.RootFolderId]; if (!groups.ContainsKey(id)) { var project = _projDao.GetById(id); if (project != null && ProjectSecurity.CanRead(project) && ProjectSecurity.CanReadFiles(project)) { groups[id] = new SearchGroup(id, project.Title); } else { continue; } } var item = new SearchItem { EntityType = EntityType.File, ID = f is Files.Core.File ? ((Files.Core.File)f).ViewUrl : string.Format("{0}tmdocs.aspx?prjID={1}#{2}", VirtualPathUtility.ToAbsolute("~/products/projects/"), id, f.ID), Title = f.Title, CreateOn = f.CreateOn, }; groups[id].Items.Add(item); } } } catch (Exception err) { LogManager.GetLogger("ASC.Web").Error(err); } return(new List <SearchGroup>(groups.Values)); }
public virtual List <Project> GetByFilter(TaskFilter filter) { var isAdmin = ProjectSecurity.IsAdministrator(SecurityContext.CurrentAccount.ID); return(projectDao.GetByFilter(filter, isAdmin)); }
public virtual List <int> GetTaskCount(List <int> projectId, TaskStatus?taskStatus) { var isAdmin = ProjectSecurity.IsAdministrator(SecurityContext.CurrentAccount.ID); return(projectDao.GetTaskCount(projectId, taskStatus, isAdmin)); }
public string GetTaskOrder(Project project) { ProjectSecurity.DemandReadTasks(project); return(projectDao.GetTaskOrder(project.ID)); }
public void SetTaskOrder(Project project, string order) { ProjectSecurity.DemandReadTasks(project); projectDao.SetTaskOrder(project.ID, order); }
public void Delete(TimeSpend timeSpend) { ProjectSecurity.DemandDelete(timeSpend); DaoFactory.TimeSpendDao.Delete(timeSpend.ID); }
private static bool CheckAccess(UserActivity activity, EngineFactory engineFactory) { if (!string.IsNullOrEmpty(activity.SecurityId)) { var data = activity.SecurityId.Split('|'); if (data.Length == 3) { try { var entityType = (EntityType)Enum.Parse(typeof(EntityType), data[0], true); var entityId = string.IsNullOrEmpty(data[1]) ? -1 : int.Parse(data[1]); var projectId = 0; if (!int.TryParse(data[2], out projectId)) { return(false); } var project = engineFactory.GetProjectEngine().GetByID(projectId); if (project.Private) { //Switch types switch (entityType) { case EntityType.Team: case EntityType.Project: return(ProjectSecurity.CanRead(project)); case EntityType.Milestone: return(ProjectSecurity.CanRead(engineFactory.GetMilestoneEngine().GetByID(entityId))); case EntityType.Task: return(ProjectSecurity.CanRead(engineFactory.GetTaskEngine().GetByID(entityId))); case EntityType.Message: return(ProjectSecurity.CanReadMessages(project)); case EntityType.File: return(ProjectSecurity.CanReadFiles(project)); case EntityType.TimeSpend: { if (entityId < 0) { return(ProjectSecurity.CanRead(project)); } return(ProjectSecurity.CanRead(engineFactory.GetTaskEngine().GetByID(entityId))); } } } } catch (Exception) { return(false); } } } else if (!string.IsNullOrEmpty(activity.ContainerID)) { //Go long way. Parse old data int prjId; if (int.TryParse(activity.ContainerID, out prjId)) { var prj = engineFactory.GetProjectEngine().GetByID(prjId); if (prj != null) { if (prj.Private) { try { return(!string.IsNullOrEmpty(activity.AdditionalData) && CheckPermission(prj, activity, engineFactory)); } catch { return(false); } } } } } return(true); }
public IEnumerable <SearchItem> Search(string searchText, int projectId = 0) { var queryResult = DaoFactory.SearchDao.Search(searchText, projectId); using (var scope = DIHelper.Resolve()) { var projectSecurity = scope.Resolve <ProjectSecurity>(); foreach (var r in queryResult) { switch (r.EntityType) { case EntityType.Project: var project = (Project)r; if (projectSecurity.CanRead(project)) { searchItems.Add(new SearchItem(project)); } continue; case EntityType.Milestone: var milestone = (Milestone)r; if (projectSecurity.CanRead(milestone)) { searchItems.Add(new SearchItem(milestone)); } continue; case EntityType.Message: var message = (Message)r; if (projectSecurity.CanRead(message)) { searchItems.Add(new SearchItem(message)); } continue; case EntityType.Task: var task = (Task)r; if (projectSecurity.CanRead(task)) { searchItems.Add(new SearchItem(task)); } continue; case EntityType.Comment: var comment = (Comment)r; var entity = CommentEngine.GetEntityByTargetUniqId(comment); if (entity == null) { continue; } searchItems.Add(new SearchItem(comment.EntityType, comment.ID.ToString(CultureInfo.InvariantCulture), HtmlUtil.GetText(comment.Content), comment.CreateOn, new SearchItem(entity))); continue; case EntityType.SubTask: var subtask = (Subtask)r; var parentTask = TaskEngine.GetByID(subtask.Task); if (parentTask == null) { continue; } searchItems.Add(new SearchItem(subtask.EntityType, subtask.ID.ToString(CultureInfo.InvariantCulture), subtask.Title, subtask.CreateOn, new SearchItem(parentTask))); continue; } } } try { // search in files var fileEntries = new List <FileEntry>(); using (var folderDao = FilesIntegration.GetFolderDao()) using (var fileDao = FilesIntegration.GetFileDao()) { fileEntries.AddRange(folderDao.Search(searchText, true)); fileEntries.AddRange(fileDao.Search(searchText, true)); var projectIds = projectId != 0 ? new List <int> { projectId } : fileEntries.GroupBy(f => f.RootFolderId) .Select(g => folderDao.GetFolder(g.Key)) .Select(f => f != null ? folderDao.GetBunchObjectID(f.RootFolderId).Split('/').Last() : null) .Where(s => !string.IsNullOrEmpty(s)) .Select(int.Parse); var rootProject = projectIds.ToDictionary(id => FilesIntegration.RegisterBunch("projects", "project", id.ToString(CultureInfo.InvariantCulture))); fileEntries.RemoveAll(f => !rootProject.ContainsKey(f.RootFolderId)); var security = FilesIntegration.GetFileSecurity(); fileEntries.RemoveAll(f => !security.CanRead(f)); foreach (var f in fileEntries) { var id = rootProject[f.RootFolderId]; var project = DaoFactory.ProjectDao.GetById(id); if (ProjectSecurity.CanReadFiles(project)) { var itemId = f.FileEntryType == FileEntryType.File ? FilesLinkUtility.GetFileWebPreviewUrl(f.Title, f.ID) : Web.Files.Classes.PathProvider.GetFolderUrl((Folder)f, project.ID); searchItems.Add(new SearchItem(EntityType.File, itemId, f.Title, f.CreateOn, new SearchItem(project), itemPath: "{2}")); } } } } catch (Exception err) { LogManager.GetLogger("ASC").Error(err); } return(searchItems); }
public int GetByFilterCount(TaskFilter filter) { var isAdmin = ProjectSecurity.IsAdministrator(SecurityContext.CurrentAccount.ID); return(taskDao.GetByFilterCount(filter, isAdmin).TasksTotal); }
public List <TimeSpend> GetByTask(int taskId) { var timeSpend = _timeSpendDao.GetByTask(taskId); return(GetTasks(timeSpend).FindAll(r => ProjectSecurity.CanRead(r.Task))); }
public int GetByFilterCount(TaskFilter filter) { var isAdmin = ProjectSecurity.IsAdministrator(SecurityContext.CurrentAccount.ID); return(_milestoneDao.GetByFilterCount(filter, isAdmin)); }
public void Delete(TimeSpend timeSpend) { ProjectSecurity.DemandDeleteTimeSpend(timeSpend); timeSpendDao.Delete(timeSpend.ID); }
public Subtask SaveOrUpdate(Subtask subtask, Task task) { if (subtask == null) { throw new Exception("subtask.Task"); } if (task == null) { throw new ArgumentNullException("task"); } if (task.Status == TaskStatus.Closed) { throw new Exception("task can't be closed"); } var isNew = subtask.ID == default(int); //Task is new subtask.LastModifiedBy = SecurityContext.CurrentAccount.ID; subtask.LastModifiedOn = TenantUtil.DateTimeNow(); if (isNew) { if (subtask.CreateBy == default(Guid)) { subtask.CreateBy = SecurityContext.CurrentAccount.ID; } if (subtask.CreateOn == default(DateTime)) { subtask.CreateOn = TenantUtil.DateTimeNow(); } ProjectSecurity.DemandEdit(task); subtask = _subtaskDao.Save(subtask); TimeLinePublisher.Subtask(subtask, task, EngineResource.ActionText_Create, UserActivityConstants.ContentActionType, UserActivityConstants.NormalContent); } else { //changed task ProjectSecurity.DemandEdit(task, GetById(subtask.ID)); subtask = _subtaskDao.Save(subtask); TimeLinePublisher.Subtask(subtask, task, EngineResource.ActionText_Update, UserActivityConstants.ActivityActionType, UserActivityConstants.NormalActivity); } var objectID = task.UniqID + "_" + task.Project.ID; var recipients = NotifySource.Instance.GetSubscriptionProvider().GetRecipients(NotifyConstants.Event_NewCommentForTask, objectID) .Where(r => r.ID != SecurityContext.CurrentAccount.ID.ToString() && r.ID != subtask.Responsible.ToString() && r.ID != subtask.CreateBy.ToString()) .ToList(); NotifySubtask(task, subtask, recipients, isNew); var senders = new HashSet <Guid> { subtask.Responsible, subtask.CreateBy }; senders.Remove(Guid.Empty); foreach (var sender in senders) { _factory.GetTaskEngine().SubscribeToTask(task, sender); } return(subtask); }
public Task SaveOrUpdate(Task task, IEnumerable <int> attachedFileIds, bool notifyResponsible, bool isImport) { if (task == null) { throw new ArgumentNullException("task"); } if (task.Project == null) { throw new Exception("task.Project"); } // check guests responsibles foreach (var responsible in task.Responsibles) { if (ProjectSecurity.IsVisitor(responsible)) { ProjectSecurity.CreateGuestSecurityException(); } } var milestone = task.Milestone != 0 ? milestoneDao.GetById(task.Milestone) : null; var milestoneResponsible = milestone != null ? milestone.Responsible : Guid.Empty; var removeResponsibles = new List <Guid>(); var inviteToResponsibles = new List <Guid>(); task.LastModifiedBy = SecurityContext.CurrentAccount.ID; task.LastModifiedOn = TenantUtil.DateTimeNow(); var isNew = task.ID == default(int); //Task is new if (isNew) { if (task.CreateBy == default(Guid)) { task.CreateBy = SecurityContext.CurrentAccount.ID; } if (task.CreateOn == default(DateTime)) { task.CreateOn = TenantUtil.DateTimeNow(); } ProjectSecurity.DemandCreateTask(task.Project); task = taskDao.Save(task); inviteToResponsibles.AddRange(task.Responsibles.Distinct()); } else { var oldTask = GetByID(new[] { task.ID }).FirstOrDefault(); if (oldTask == null) { throw new ArgumentNullException("task"); } var newResponsibles = task.Responsibles.Distinct().ToList(); var oldResponsibles = oldTask.Responsibles.Distinct().ToList(); removeResponsibles.AddRange(oldResponsibles.Where(p => !newResponsibles.Contains(p))); inviteToResponsibles.AddRange(newResponsibles.Where(participant => !oldResponsibles.Contains(participant))); //changed task ProjectSecurity.DemandEdit(oldTask); task = taskDao.Save(task); } if (attachedFileIds != null && attachedFileIds.Any()) { foreach (var attachedFileId in attachedFileIds) { AttachFile(task, attachedFileId, false); } } var senders = new HashSet <Guid>(task.Responsibles) { task.Project.Responsible, milestoneResponsible, task.CreateBy }; senders.Remove(Guid.Empty); foreach (var subscriber in senders) { Subscribe(task, subscriber); } inviteToResponsibles.RemoveAll(r => r.Equals(Guid.Empty)); removeResponsibles.RemoveAll(r => r.Equals(Guid.Empty)); NotifyTask(task, inviteToResponsibles, removeResponsibles, isNew, notifyResponsible); return(task); }
public Task ChangeStatus(Task task, CustomTaskStatus newStatus) { ProjectSecurity.DemandEdit(task); if (task == null) { throw new ArgumentNullException("task"); } if (task.Project == null) { throw new Exception("Project can't be null."); } if (task.Project.Status == ProjectStatus.Closed) { throw new Exception(EngineResource.ProjectClosedError); } if (task.Status == newStatus.StatusType && task.CustomTaskStatus == newStatus.Id) { return(task); } var status = StatusEngine.Get().FirstOrDefault(r => r.Id == newStatus.Id); var cannotChange = status != null && status.Available.HasValue && !status.Available.Value && task.CreateBy != SecurityContext.CurrentAccount.ID && task.Project.Responsible != SecurityContext.CurrentAccount.ID && !ProjectSecurity.CurrentUserAdministrator; if (cannotChange) { ProjectSecurity.CreateSecurityException(); } var senders = GetSubscribers(task); if (newStatus.StatusType == TaskStatus.Closed && !DisableNotifications && senders.Count != 0) { NotifyClient.Instance.SendAboutTaskClosing(senders, task); } if (newStatus.StatusType == TaskStatus.Open && !DisableNotifications && senders.Count != 0) { NotifyClient.Instance.SendAboutTaskResumed(senders, task); } task.Status = newStatus.StatusType; task.CustomTaskStatus = newStatus.Id < 0 ? null : (int?)newStatus.Id; task.LastModifiedBy = SecurityContext.CurrentAccount.ID; task.LastModifiedOn = TenantUtil.DateTimeNow(); task.StatusChangedOn = TenantUtil.DateTimeNow(); //subtask if (newStatus.StatusType == TaskStatus.Closed) { if (!task.Responsibles.Any()) { task.Responsibles.Add(SecurityContext.CurrentAccount.ID); } DaoFactory.SubtaskDao.CloseAllSubtasks(task); foreach (var subTask in task.SubTasks) { subTask.Status = TaskStatus.Closed; } } return(DaoFactory.TaskDao.Update(task)); }
private bool CanRead(Milestone m) { return(ProjectSecurity.CanRead(m)); }
public Task SaveOrUpdate(Task task, IEnumerable <int> attachedFileIds, bool notifyResponsible, bool isImport) { if (task == null) { throw new ArgumentNullException("task"); } if (task.Project == null) { throw new Exception("task.Project"); } var milestone = task.Milestone != 0 ? _milestoneDao.GetById(task.Milestone) : null; var milestoneResponsible = milestone != null ? milestone.Responsible : Guid.Empty; task.LastModifiedBy = SecurityContext.CurrentAccount.ID; task.LastModifiedOn = TenantUtil.DateTimeNow(); var isNew = task.ID == default(int); //Task is new if (isNew) { if (task.CreateBy == default(Guid)) { task.CreateBy = SecurityContext.CurrentAccount.ID; } if (task.CreateOn == default(DateTime)) { task.CreateOn = TenantUtil.DateTimeNow(); } ProjectSecurity.DemandCreateTask(task.Project); task = _taskDao.Save(task); TimeLinePublisher.Task(task, milestone, isImport ? EngineResource.ActionText_Imported : EngineResource.ActionText_Create, UserActivityConstants.ContentActionType, UserActivityConstants.NormalContent, true); } else { //changed task ProjectSecurity.DemandEdit(GetByID(new[] { task.ID }).FirstOrDefault()); task = _taskDao.Save(task); TimeLinePublisher.Task(task, milestone, EngineResource.ActionText_Update, UserActivityConstants.ActivityActionType, UserActivityConstants.NormalActivity); } if (attachedFileIds != null && attachedFileIds.Count() > 0) { foreach (var attachedFileId in attachedFileIds) { _fileEngine.AttachFileToTask(task.ID, attachedFileId); } } //Object id for sender var objectID = task.UniqID + "_" + task.Project.ID; var senders = new HashSet <Guid>(task.Responsibles) { task.Project.Responsible, milestoneResponsible, task.CreateBy, task.Responsible }; senders.Remove(Guid.Empty); var subscriptionProvider = NotifySource.Instance.GetSubscriptionProvider(); var recipientsProvider = NotifySource.Instance.GetRecipientsProvider(); var recipients = senders .Select(r => recipientsProvider.GetRecipient(r.ToString())) .Where(r => r != null && !IsUnsubscribedToTask(task, r.ID)) .ToList(); foreach (var recipient in recipients) { subscriptionProvider.Subscribe(NotifyConstants.Event_NewCommentForTask, objectID, recipient); } recipients.RemoveAll(r => r.ID == SecurityContext.CurrentAccount.ID.ToString()); if (isNew) { NotifyTaskCreated(task, recipients, milestoneResponsible, notifyResponsible); } else { NotifyTaskEdited(task, notifyResponsible); } return(task); }
public bool CanRead(Message message) { return(ProjectSecurity.CanRead(message)); }
public Task ChangeStatus(Task task, TaskStatus newStatus) { ProjectSecurity.DemandEdit(task); if (task == null) { throw new ArgumentNullException("task"); } if (task.Project == null) { throw new Exception("Project can be null."); } if (task.Status == newStatus) { return(task); } var objectID = String.Format("{0}_{1}", task.UniqID, task.Project.ID); var milestone = task.Milestone != 0 ? _milestoneDao.GetById(task.Milestone) : null; switch (newStatus) { case TaskStatus.Closed: TimeLinePublisher.Task(task, milestone, EngineResource.ActionText_Closed, UserActivityConstants.ActivityActionType, UserActivityConstants.ImportantActivity); break; case TaskStatus.Open: TimeLinePublisher.Task(task, milestone, task.Status == TaskStatus.Closed ? EngineResource.ActionText_Reopen : EngineResource.ActionText_Accept, UserActivityConstants.ActivityActionType, UserActivityConstants.NormalActivity); break; } var senders = NotifySource.Instance.GetSubscriptionProvider().GetRecipients(NotifyConstants.Event_NewCommentForTask, objectID).ToList(); senders.RemoveAll(r => r.ID == SecurityContext.CurrentAccount.ID.ToString()); if (newStatus == TaskStatus.Closed && !_factory.DisableNotifications && senders.Count != 0) { NotifyClient.Instance.SendAboutTaskClosing(senders, task); } if (newStatus == TaskStatus.Open && !_factory.DisableNotifications && senders.Count != 0) { NotifyClient.Instance.SendAboutTaskResumed(senders, task); } _taskDao.TaskTrace(task.ID, (Guid)CallContext.GetData("CURRENT_ACCOUNT"), TenantUtil.DateTimeNow(), newStatus); task.Status = newStatus; task.LastModifiedBy = SecurityContext.CurrentAccount.ID; task.LastModifiedOn = TenantUtil.DateTimeNow(); task.StatusChangedOn = TenantUtil.DateTimeNow(); //subtask if (newStatus == TaskStatus.Closed) { if (task.Responsible.Equals(Guid.Empty)) { task.Responsible = SecurityContext.CurrentAccount.ID; } _subtaskDao.CloseAllSubtasks(task); } return(_taskDao.Save(task)); }
private static bool CanRead(Project project) { return(ProjectSecurity.CanRead(project)); }
public List <TimeSpend> GetUpdates(DateTime from, DateTime to) { return(timeSpendDao.GetUpdates(from, to) .Where(x => ProjectSecurity.CanRead(x.Task.Project)).ToList()); }