private List <StandardActionType> GetAllowedStandardActionForFile(int idUser, ModuleObject source, ModuleObject destination) { List <StandardActionType> actions = new List <StandardActionType>(); Person person = Manager.GetPerson(idUser); TaskListFile taskFile = Manager.Get <TaskListFile>(source.ObjectLongID); if (taskFile != null && taskFile.Link != null && destination.ObjectLongID == taskFile.File.Id && destination.FQN == taskFile.File.GetType().FullName) { int IdCommunity = taskFile.CommunityOwner == null ? 0 : taskFile.CommunityOwner.Id; ModuleTasklist modulePermission = ServicePermission(idUser, IdCommunity); CoreModuleRepository moduleRepository = GetCoreModuleRepository(idUser, IdCommunity); CoreItemPermission itemPermission = GetTaskPermission(person, taskFile.TaskOwner, modulePermission, moduleRepository); if (taskFile.File != null) { if ((taskFile.File.IsInternal && itemPermission.AllowEdit) || (!taskFile.File.IsInternal && (moduleRepository.Administration || (moduleRepository.Edit && taskFile.File.Owner == person)))) { actions.Add(StandardActionType.EditMetadata); } if (AllowViewFileFromLink(modulePermission, itemPermission, taskFile, person)) { actions.Add(StandardActionType.Play); actions.Add(StandardActionType.ViewPersonalStatistics); } if (taskFile.File.Owner == person || (taskFile.File.IsInternal && itemPermission.AllowEdit) || (!taskFile.File.IsInternal && (moduleRepository.Administration || moduleRepository.Edit))) { actions.Add(StandardActionType.ViewAdvancedStatistics); } } } return(actions); }
public Boolean UnLinkToCommunityFileFromTask(long fileTaskID) { Boolean iResponse = false; Person person = Manager.GetPerson(UC.CurrentUserID); TaskListFile fileTaskLink = Manager.Get <TaskListFile>(fileTaskID); if (person != null && fileTaskLink != null && (fileTaskLink.File == null || !fileTaskLink.File.IsInternal)) { try { Manager.BeginTransaction(); fileTaskLink.TaskOwner.MetaInfo.ModifiedBy = person; fileTaskLink.TaskOwner.MetaInfo.ModifiedOn = DateTime.Now; Manager.SaveOrUpdate(fileTaskLink.TaskOwner); Manager.DeleteGeneric(fileTaskLink); Manager.Commit(); iResponse = true; } catch (Exception ex) { Manager.RollBack(); } } return(iResponse); }
public void EditTaskListFileVisibility(TaskListFile fileTaskLink, Boolean visibleForModule, Boolean visibleForRepository) { Person person = Manager.GetPerson(UC.CurrentUserID); if (person != null && fileTaskLink != null) { try { Manager.BeginTransaction(); fileTaskLink.UpdateMetaInfo(person, UC.IpAddress, UC.ProxyIpAddress); fileTaskLink.isVisible = visibleForModule; if (fileTaskLink.File != null & !fileTaskLink.File.IsInternal) { fileTaskLink.File.isVisible = visibleForRepository; fileTaskLink.File.ModifiedBy = person; fileTaskLink.File.ModifiedOn = fileTaskLink.ModifiedOn; Manager.SaveOrUpdate(fileTaskLink.File); } Manager.SaveOrUpdate(fileTaskLink); fileTaskLink.TaskOwner.MetaInfo.ModifiedBy = fileTaskLink.ModifiedBy; fileTaskLink.TaskOwner.MetaInfo.ModifiedOn = fileTaskLink.ModifiedOn.Value; Manager.SaveOrUpdate(fileTaskLink.TaskOwner); Manager.Commit(); } catch (Exception ex) { Manager.RollBack(); } } }
public CoreItemPermission GetItemPermissionFromLink(long IdLink) { CoreItemPermission permission = new CoreItemPermission(); ModuleLink link = Manager.Get <ModuleLink>(IdLink); if (link == null) { return(permission); } else { TaskListFile taskFileLink = (from ifl in Manager.GetAll <TaskListFile>(ifl => ifl.Link == link && ifl.Deleted == BaseStatusDeleted.None) select ifl).Skip(0).Take(1).ToList().FirstOrDefault(); if (taskFileLink == null || taskFileLink.TaskOwner == null) { return(permission); } else { int IdCommunity = taskFileLink.TaskOwner.Community == null ? 0 : taskFileLink.TaskOwner.Community.Id; ModuleTasklist moduleDiary = ServicePermission(UC.CurrentUserID, IdCommunity); CoreModuleRepository repository = GetCoreModuleRepository(UC.CurrentUserID, IdCommunity); permission = GetTaskPermission(taskFileLink.TaskOwner, moduleDiary, repository); return(permission); } } }
public void SaveTaskListFiles(Task task, int communityId, IList <ModuleActionLink> files, int moduleID, int objectTypeId, String moduleCode, Boolean AutoEvaluable) { try { Person person = Manager.GetPerson(UC.CurrentUserID); if (files.Count > 0) { Manager.BeginTransaction(); Community community = Manager.GetCommunity(communityId); foreach (ModuleActionLink file in files) { TaskListFile taskfile = (from f in Manager.GetAll <TaskListFile>(f => f.CommunityOwner == community && f.TaskOwner == task && f.ProjectOwner == task.Project && f.File == (BaseCommunityFile)file.ModuleObject.ObjectOwner) select f).Skip(0).Take(1).ToList().FirstOrDefault(); if (taskfile == null) { taskfile = new TaskListFile(); taskfile.CommunityOwner = community; taskfile.ProjectOwner = task.Project; taskfile.File = (BaseCommunityFile)file.ModuleObject.ObjectOwner; taskfile.TaskOwner = task; taskfile.Owner = person; taskfile.CreateMetaInfo(person, UC.IpAddress, UC.ProxyIpAddress); } else { taskfile.UpdateMetaInfo(person, UC.IpAddress, UC.ProxyIpAddress); } taskfile.isVisible = true; Manager.SaveOrUpdate(taskfile); ModuleLink link = new ModuleLink(file.Description, file.Permission, file.Action); link.CreateMetaInfo(person, UC.IpAddress, UC.ProxyIpAddress); link.DestinationItem = (ModuleObject)file.ModuleObject; link.AutoEvaluable = AutoEvaluable; link.SourceItem = ModuleObject.CreateLongObject(taskfile.Id, taskfile, objectTypeId, communityId, moduleCode, moduleID); Manager.SaveOrUpdate(link); taskfile.Link = link; Manager.SaveOrUpdate(taskfile); if (typeof(ModuleLongInternalFile) == file.ModuleObject.ObjectOwner.GetType()) { ModuleLongInternalFile f = (ModuleLongInternalFile)file.ModuleObject.ObjectOwner; f.ObjectOwner = taskfile; f.ObjectTypeID = objectTypeId; Manager.SaveOrUpdate(f); } task.MetaInfo.ModifiedBy = taskfile.CreatedBy; task.MetaInfo.ModifiedOn = taskfile.CreatedOn.Value; Manager.SaveOrUpdate(task); } Manager.Commit(); } } catch (Exception ex) { Manager.RollBack(); throw new lm.Comol.Core.Event.EventItemFileNotLinked(ex.Message, ex); } }
public void ValidLoadShouldLoadFile() { TestStorage loadSensor = new TestStorage(); TaskListFile file = new TaskListFile(loadSensor); file.Load("TestLoadFile"); Assert.AreEqual("TestLoadFile", loadSensor.LoadedFile, string.Format("Loaded file name should be TestLoadFile, not {0}", loadSensor.LoadedFile)); }
public void SaveWithFilePathShouldSaveData() { TestStorage saveSensor = new TestStorage(); TaskListFile file = new TaskListFile(saveSensor); file.Save(new TaskList(), new TestInputParser(new List <string> { "TestFileName" })); Assert.AreEqual("TestFileName", saveSensor.SavedFile, string.Format("Saved file name should be TestFileName, not {0}", saveSensor.SavedFile)); }
public StatTreeNode <StatFileTreeLeaf> GetObjectItemFilesForStatistics(long objectId, Int32 objectTypeId, Dictionary <Int32, string> translations, Int32 idCommunity, Int32 idUser, Dictionary <String, long> moduleUserLong = null, Dictionary <String, String> moduleUserString = null) { StatTreeNode <StatFileTreeLeaf> node = null; Person person = Manager.Get <Person>(idUser); switch (objectTypeId) { case (int)ModuleTasklist.ObjectType.Task: Task item = Manager.Get <Task>(objectId); if (item != null) { idCommunity = (item.Community == null) ? 0 : item.Community.Id; } break; case (int)ModuleTasklist.ObjectType.TaskFile: //item = Manager.Get<CommunityEventItem>(objectId); //if (item != null) // IdCommunity = (item.CommunityOwner == null) ? 0 : item.CommunityOwner.Id; break; case (int)ModuleTasklist.ObjectType.TaskLinkedFile: TaskListFile taskFile = Manager.Get <TaskListFile>(objectTypeId); if (taskFile != null) { idCommunity = (taskFile.CommunityOwner == null) ? 0 : taskFile.CommunityOwner.Id; } break; } //ModuleTasklist moduleTasklist = ServicePermission(IdUser, IdCommunity); //if (moduleTasklist.Administration || moduleTasklist.ViewTaskList || moduleTasklist.UploadFile) //moduleTasklist.Edit || //{ // CoreModuleRepository repository = GetCoreModuleRepository(IdUser, IdCommunity); // switch (objectTypeId) // { // case (int)ModuleTasklist.ObjectType.Task: // Task item = Manager.Get<Task>(objectId); // node = LoadDiaryItemForStatistics(item, person, moduleTasklist, repository, translations); // break; // case (int)ModuleTasklist.ObjectType.TaskLinkedFile: // TaskListFile eventItemFile = Manager.Get<TaskListFile>(objectTypeId); // if (eventItemFile != null && eventItemFile.ItemOwner != null) // node = LoadDiaryItemForStatistics(eventItemFile.ItemOwner, person, moduleTasklist, repository, translations); // break; // default: // node = LoadDiaryForStatistics(Manager.Get<Community>(IdCommunity), person, moduleTasklist, repository, translations); // break; // } //} //else // node = CreateTaskListTreeNode(Manager.Get<Community>(IdCommunity), translations); return(node); }
//------------------------------------------------------------------------------------------------------------------------------------------------------------------ #region "File Item Link" public lm.Comol.Modules.TaskList.Domain.TaskListFile GetTaskListFile(long IdItemFile) { TaskListFile oItem = null; try { oItem = Manager.Get <TaskListFile>(IdItemFile); } catch (Exception ex) { } return(oItem); }
public void NonExistentFileLoadShouldCreateEmptyListAndNotifyUser() { using (StringWriter sw = new StringWriter()) { Console.SetOut(sw); TaskListFile file = new TaskListFile(new TestStorage()); file.Load("Nonexistent"); string expected = string.Format("Saved file doesn't exist at Nonexistent.{0}", Environment.NewLine); Assert.AreEqual <string>(expected, sw.ToString(), string.Format("Expected output is {0}, not {1}", expected, sw.ToString())); } }
public void SecondSaveShouldDefaultToSameFilePathAsFirst() { TestStorage saveSensor = new TestStorage(); TaskListFile file = new TaskListFile(saveSensor); file.Save(new TaskList(), new TestInputParser(new List <string> { "TestFileName" })); saveSensor.Clear(); file.Save(new TaskList(), new TestInputParser(new List <string> { })); Assert.AreEqual("TestFileName", saveSensor.SavedFile, string.Format("Saved file name should be TestFileName, not {0}", saveSensor.SavedFile)); }
public void InvalidLoadShouldCreateEmptyListAndNotifyUser() { using (StringWriter sw = new StringWriter()) { Console.SetOut(sw); TaskListFile file = new TaskListFile(new TestStorage()); file.Load("Exception"); string expected = string.Format("There was a problem loading the file.{0}", Environment.NewLine); Assert.AreEqual <string>(expected, sw.ToString(), string.Format("Expected output is {0}, not {1}", expected, sw.ToString())); } }
public void SaveAfterLoadShouldDefaultToFileThatWasLoaded() { TestStorage saveSensor = new TestStorage(); TaskListFile file = new TaskListFile(saveSensor); file.Load("LoadTestFile"); file.Save(new TaskList(), new TestInputParser(new List <string> { })); //null saveSensor.Clear(); file.Save(new TaskList(), new TestInputParser(new List <string> { })); //string.Empty Assert.AreEqual("LoadTestFile", saveSensor.SavedFile, string.Format("Saved file name should be LoadTestFile, not {0}", saveSensor.SavedFile)); }
public void EditFileItemVisibility(long itemID, long LinkId, Boolean visibleForModule, Boolean visibleForRepository) { int IdCommunity = View.ItemCommunityId; TaskListFile fileLink = Service.GetTaskListFile(LinkId); if (fileLink != null && fileLink.TaskOwner != null) { Service.EditTaskListFileVisibility(fileLink, visibleForModule, visibleForRepository); //if (fileLink.ItemOwner.ShowDateInfo) // View.NotifyEdit(IdCommunity, fileLink.ItemOwner.Id, fileLink.ItemOwner.StartDate, fileLink.ItemOwner.EndDate, fileLink.ItemOwner.IsVisible); //else // View.NotifyEditNoDate(IdCommunity, fileLink.ItemOwner.Id, fileLink.ItemOwner.IsVisible); View.SendActionEditFileItemVisibility(IdCommunity, ModuleID, LinkId, fileLink.isVisible); } View.ReturnToFileManagement(View.ItemCommunityId, itemID); }
private Boolean AllowEditMetadata(int UserID, int RoleID, ModuleObject source, ModuleObject destination) { Boolean iResponse = false; if (source.ObjectTypeID == (int)ModuleTasklist.ObjectType.TaskLinkedFile) { Person person = Manager.GetPerson(UserID); TaskListFile taskFile = Manager.Get <TaskListFile>(source.ObjectLongID); if (taskFile != null && taskFile.Link != null && destination.ObjectLongID == taskFile.File.Id && destination.FQN == taskFile.File.GetType().FullName) { int IdCommunity = taskFile.CommunityOwner == null ? 0 : taskFile.CommunityOwner.Id; ModuleTasklist modulePermission = ServicePermission(UserID, IdCommunity); CoreModuleRepository moduleRepository = GetCoreModuleRepository(UserID, IdCommunity); CoreItemPermission itemPermission = GetTaskPermission(person, taskFile.TaskOwner, modulePermission, moduleRepository); iResponse = (taskFile.File.IsInternal && itemPermission.AllowEdit) || (!taskFile.File.IsInternal && (moduleRepository.Administration || (moduleRepository.Edit && taskFile.File.Owner == person))); } } return(iResponse); }
private Boolean AllowDownloadFileLinkedToItem(long itemFileLinkId, int UserID, int communityID, int RoleID) { Boolean iResponse = false; TaskListFile taskFile = Manager.Get <TaskListFile>(itemFileLinkId); Person person = Manager.GetPerson(UserID); if (taskFile != null && taskFile.TaskOwner != null && taskFile.File != null && taskFile.Link != null) { Task task = taskFile.TaskOwner; communityID = task.Community == null ? 0 : task.Community.Id; lm.Comol.Modules.TaskList.ModuleTasklist modulePermission = ServicePermission(UserID, communityID); CoreModuleRepository moduleRepository = GetCoreModuleRepository(UserID, communityID); CoreItemPermission itemPermission = GetTaskPermission(person, task, modulePermission, moduleRepository); //permission.Download = itemFileLink.File.IsDownloadable && itemPermissions.AllowViewFiles; //permission.Play = (itemFileLink.File.isSCORM || itemFileLink.File.isVideocast) && itemPermissions.AllowViewFiles; iResponse = AllowViewFileFromLink(modulePermission, itemPermission, taskFile, person); } return(iResponse); }
public void EditFileRepositoryVisibility(TaskListFile fileTaskLink) { Person person = Manager.GetPerson(UC.CurrentUserID); EditFileTaskVisibility(fileTaskLink); if (person != null && fileTaskLink != null && !fileTaskLink.File.IsInternal) { try { Manager.BeginTransaction(); fileTaskLink.File.isVisible = fileTaskLink.isVisible; fileTaskLink.File.ModifiedBy = person; fileTaskLink.File.ModifiedOn = fileTaskLink.ModifiedOn; Manager.SaveOrUpdate(fileTaskLink.File); Manager.Commit(); } catch (Exception ex) { Manager.RollBack(); } } }
private void EditFileTaskVisibility(TaskListFile fileTaskLink) { Person person = Manager.GetPerson(UC.CurrentUserID); if (person != null && fileTaskLink != null) { try { Manager.BeginTransaction(); fileTaskLink.UpdateMetaInfo(person, UC.IpAddress, UC.ProxyIpAddress); fileTaskLink.isVisible = !fileTaskLink.isVisible; Manager.SaveOrUpdate(fileTaskLink); fileTaskLink.TaskOwner.MetaInfo.ModifiedBy = fileTaskLink.ModifiedBy; fileTaskLink.TaskOwner.MetaInfo.ModifiedOn = fileTaskLink.ModifiedOn.Value; Manager.SaveOrUpdate(fileTaskLink.TaskOwner); Manager.Commit(); } catch (Exception ex) { Manager.RollBack(); } } }
//------------------------------------------------------------------------------------------------------------------------------------------------------------------ private void SetVirtualDeleteFileTaskLink(long taskfileID, Boolean delete) { Person person = Manager.GetPerson(UC.CurrentUserID); TaskListFile fileTaskLink = Manager.Get <TaskListFile>(taskfileID); if (person != null && fileTaskLink != null) { try { Manager.BeginTransaction(); fileTaskLink.UpdateMetaInfo(person, UC.IpAddress, UC.ProxyIpAddress); fileTaskLink.Deleted = delete ? BaseStatusDeleted.Manual : BaseStatusDeleted.None; fileTaskLink.TaskOwner.MetaInfo.ModifiedBy = fileTaskLink.ModifiedBy; fileTaskLink.TaskOwner.MetaInfo.ModifiedOn = fileTaskLink.ModifiedOn.Value; Manager.SaveOrUpdate(fileTaskLink.TaskOwner); Manager.SaveOrUpdate(fileTaskLink); Manager.Commit(); } catch (Exception ex) { Manager.RollBack(); } } }
private Boolean AllowViewFileFromLink(ModuleTasklist modulePermission, CoreItemPermission itemPermission, TaskListFile taskFile, Person person) { Boolean iResponse = false; iResponse = itemPermission.AllowViewFiles && (taskFile.isVisible || taskFile.Owner == person || taskFile.TaskOwner.MetaInfo.CreatedBy == person || modulePermission.Administration); return(iResponse); }
public CommandLineInterfaceTest() { list = new MockTaskList(); file = new TaskListFile(new TestStorage()); }