예제 #1
0
 public void PhisicalDelete(long idItem, long idAttachment, Int32 idCommunity, String baseFilePath, String baseThumbnailPath, String unknownUser)
 {
     if (UserContext.isAnonymous)
     {
         View.DisplaySessionTimeout(View.IdCommunityDiary);
     }
     else
     {
         litePerson person = CurrentManager.GetLitePerson(UserContext.CurrentUserID);
         if (person == null || person.Id == 0)
         {
             View.DisplaySessionTimeout(idCommunity, idItem);
         }
         else
         {
             ModuleCommunityDiary module     = Service.GetPermissions(UserContext.CurrentUserID, idCommunity);
             CommunityEventItem   item       = Service.EventItemGet(idItem);
             EventItemFile        attachment = Service.EventItemGetAttachment(idAttachment);
             if (item != null && attachment != null)
             {
                 if (module.Edit || module.Administration)
                 {
                     Service.AttachmentPhisicalDelete(item, attachment, baseFilePath, baseThumbnailPath);
                 }
                 ReloadAttachments(person, item, module, View.RepositoryIdentifier, unknownUser);
             }
             else if (item != null)
             {
                 ReloadAttachments(person, item, module, View.RepositoryIdentifier, unknownUser);
             }
         }
     }
 }
예제 #2
0
        public Boolean UnLinkAttachment(long idAttachment, litePerson person)
        {
            Boolean       unlinked   = false;
            EventItemFile attachment = Manager.Get <EventItemFile>(idAttachment);

            if (person != null && person.Id > 0 && attachment != null && (attachment.Item == null || !attachment.Item.IsInternal))
            {
                try
                {
                    CommunityEventItem item = Manager.Get <CommunityEventItem>(attachment.IdItemOwner);
                    Manager.BeginTransaction();
                    if (item != null)
                    {
                        item.ModifiedBy = person;
                        item.ModifiedOn = DateTime.Now;
                        Manager.SaveOrUpdate(item);
                    }
                    Manager.DeleteGeneric(attachment);
                    Manager.Commit();
                    unlinked = true;
                }
                catch (Exception ex)
                {
                    Manager.RollBack();
                }
            }
            return(unlinked);
        }
예제 #3
0
 public void UnlinkRepositoryItem(long idItem, long idAttachment, Int32 idCommunity, String unknownUser)
 {
     if (UserContext.isAnonymous)
     {
         View.DisplaySessionTimeout(idCommunity, idItem);
     }
     else
     {
         litePerson person = CurrentManager.GetLitePerson(UserContext.CurrentUserID);
         if (person == null || person.Id == 0)
         {
             View.DisplaySessionTimeout(idCommunity, idItem);
         }
         else
         {
             ModuleCommunityDiary module     = Service.GetPermissions(UserContext.CurrentUserID, idCommunity);
             CommunityEventItem   item       = Service.EventItemGet(idItem);
             EventItemFile        attachment = Service.EventItemGetAttachment(idAttachment);
             if (item != null && attachment != null)
             {
                 Service.UnLinkAttachment(idAttachment, person);
                 ReloadAttachments(person, item, module, View.RepositoryIdentifier, unknownUser);
             }
             else if (item != null)
             {
                 ReloadAttachments(person, item, module, View.RepositoryIdentifier, unknownUser);
             }
             else
             {
                 View.LoadAttachments(null);
             }
         }
     }
 }
예제 #4
0
        private void AttachmentSetVirtualDelete(long idAttachment, Boolean delete)
        {
            litePerson    person     = Manager.GetLitePerson(UC.CurrentUserID);
            EventItemFile attachment = Manager.Get <EventItemFile>(idAttachment);

            if (person != null && attachment != null)
            {
                try
                {
                    Manager.BeginTransaction();
                    attachment.UpdateMetaInfo(person, UC.IpAddress, UC.ProxyIpAddress);
                    attachment.Deleted = delete ? BaseStatusDeleted.Manual : BaseStatusDeleted.None;
                    CommunityEventItem item = EventItemGet(attachment.IdItemOwner);
                    if (item != null)
                    {
                        item.ModifiedBy = attachment.ModifiedBy;
                        item.ModifiedOn = attachment.ModifiedOn.Value;
                        Manager.SaveOrUpdate(item);
                    }
                    Manager.SaveOrUpdate(attachment);
                    Manager.Commit();
                }
                catch (Exception ex)
                {
                    Manager.RollBack();
                }
            }
        }
        public Boolean AttachmentPhisicalDelete(CommunityEventItem item, EventItemFile attachment, String baseFilePath, String baseThumbnailPath)
        {
            Boolean result = (attachment == null);

            if (item != null && attachment != null)
            {
                litePerson person          = Manager.GetLitePerson(UC.CurrentUserID);
                Boolean    isInTransaction = Manager.IsInTransaction();
                try
                {
                    List <string> filesToRemove = new List <string>();
                    if (!isInTransaction)
                    {
                        Manager.BeginTransaction();
                    }
                    if (attachment.Item != null && attachment.Item.IsInternal)
                    {
                        filesToRemove.Add(ServiceRepository.GetItemDiskFullPath(baseFilePath, attachment.Item));
                        filesToRemove.Add(ServiceRepository.GetItemThumbnailFullPath(baseThumbnailPath, attachment.Item));
                        Manager.DeletePhysical(attachment.Item);
                        if (attachment.Version != null)
                        {
                            Manager.DeletePhysical(attachment.Version);
                        }
                    }

                    if (attachment.Link != null)
                    {
                        Manager.DeletePhysical(attachment.Link);
                    }
                    Manager.DeletePhysical(attachment);

                    item.ModifiedOn = DateTime.Now;
                    item.ModifiedBy = person;
                    Manager.SaveOrUpdate(item);

                    if (!isInTransaction)
                    {
                        Manager.Commit();
                    }
                    lm.Comol.Core.File.Delete.Files(filesToRemove);
                }
                catch (Exception ex)
                {
                    if (!isInTransaction)
                    {
                        Manager.RollBack();
                    }
                    result = false;
                }
            }
            return(result);
        }
예제 #6
0
        public EventItemFile EventItemGetAttachment(long idAttachment)
        {
            EventItemFile attachment = null;

            try
            {
                attachment = Manager.Get <EventItemFile>(idAttachment);
            }
            catch (Exception ex)
            {
            }
            return(attachment);
        }
예제 #7
0
 public void EditFileItemVisibility(long idItem, long idAttachment, Int32 idCommunity, Boolean visibleForModule, Boolean visibleForRepository, String unknownUser)
 {
     if (UserContext.isAnonymous)
     {
         View.DisplaySessionTimeout(idCommunity, idItem);
     }
     else
     {
         ModuleCommunityDiary module     = Service.GetPermissions(UserContext.CurrentUserID, idCommunity);
         CommunityEventItem   item       = Service.EventItemGet(idItem);
         EventItemFile        attachment = Service.EventItemGetAttachment(idAttachment);
         if (item != null && attachment != null)
         {
             Service.AttachmentEditVisibility(item, attachment, visibleForModule, visibleForRepository);
         }
         LoadDiaryItems(idCommunity, unknownUser);
     }
 }
예제 #8
0
        public CoreItemPermission GetItemPermissionFromLink(long idLink)
        {
            CoreItemPermission permission = new CoreItemPermission();
            liteModuleLink     link       = Manager.Get <liteModuleLink>(idLink);

            if (link != null)
            {
                EventItemFile itemFileLink = (from f in Manager.GetIQ <EventItemFile>() where f.Link != null && f.Link.Id == idLink && f.Deleted == BaseStatusDeleted.None select f).Skip(0).Take(1).ToList().FirstOrDefault();
                if (itemFileLink != null)
                {
                    CommunityEventItem item = EventItemGet(itemFileLink.IdItemOwner);
                    if (item != null)
                    {
                        permission = GetItemPermission(item, ServicePermission(UC.CurrentUserID, itemFileLink.IdCommunity), GetCoreModuleRepository(UC.CurrentUserID, itemFileLink.IdCommunity));
                    }
                }
            }
            return(permission);
        }
        private Boolean AllowDownloadFileLinkedToItem(long idAttachment, Int32 idUser)
        {
            Boolean       iResponse  = false;
            EventItemFile attachment = Manager.Get <EventItemFile>(idAttachment);
            litePerson    person     = Manager.GetLitePerson(idUser);

            if (attachment != null && attachment.Item != null && attachment.Link != null)
            {
                CommunityEventItem item = EventItemGet(attachment.IdItemOwner);
                if (item != null)
                {
                    ModuleCommunityDiary modulePermission = GetPermissions(idUser, attachment.IdCommunity);
                    lm.Comol.Core.FileRepository.Domain.ModuleRepository moduleRepository = GetCoreModuleRepository(idUser, attachment.IdCommunity);
                    CoreItemPermission itemPermission = GetItemPermission(person, EventItemGet(attachment.IdItemOwner), modulePermission, moduleRepository);
                    iResponse = AllowViewFileFromLink(modulePermission, itemPermission, attachment, person) && (attachment.Item.IsDownloadable || (attachment.Item.IdOwner == idUser && attachment.Item.Availability != Core.FileRepository.Domain.ItemAvailability.notavailable));
                }
            }
            return(iResponse);
        }
        private Boolean AllowEditMetadata(Int32 idUser, Int32 idRole, ModuleObject source, ModuleObject destination)
        {
            Boolean iResponse = false;

            if (source.ObjectTypeID == (int)ModuleCommunityDiary.ObjectType.DiaryItemLinkedFile)
            {
                litePerson    person     = Manager.GetLitePerson(idUser);
                EventItemFile attachment = Manager.Get <EventItemFile>(source.ObjectLongID);
                if (attachment != null && attachment.Link != null && attachment.Item != null && source.ObjectLongID == attachment.Id)
                {
                    ModuleCommunityDiary modulePermission = GetPermissions(idUser, attachment.IdCommunity);
                    lm.Comol.Core.FileRepository.Domain.ModuleRepository moduleRepository = GetCoreModuleRepository(idUser, attachment.IdCommunity);
                    CoreItemPermission itemPermission = GetItemPermission(person, EventItemGet(attachment.IdItemOwner), modulePermission, moduleRepository);
                    iResponse = ((attachment.Item.Type == Core.FileRepository.Domain.ItemType.ScormPackage || attachment.Item.Type == Core.FileRepository.Domain.ItemType.Multimedia) && (attachment.Item.Availability == Core.FileRepository.Domain.ItemAvailability.available || attachment.Item.Availability == Core.FileRepository.Domain.ItemAvailability.waitingsettings) && ((attachment.Item.IsInternal && itemPermission.AllowEdit) ||
                                                                                                                                                                                                                                                                                                                                                                                    (!attachment.Item.IsInternal && (moduleRepository.Administration || moduleRepository.EditOthersFiles || (moduleRepository.EditMyFiles && attachment.Item.IdOwner == person.Id)))));
                }
            }
            return(iResponse);
        }
예제 #11
0
        public void AttachmentEditVisibility(CommunityEventItem item, EventItemFile attachment, Boolean visibleForModule, Boolean visibleForRepository)
        {
            Boolean    updateRepositoryItems = false;
            litePerson person = Manager.GetLitePerson(UC.CurrentUserID);

            if (person != null && attachment != null)
            {
                try
                {
                    Manager.BeginTransaction();
                    attachment.UpdateMetaInfo(person, UC.IpAddress, UC.ProxyIpAddress);
                    attachment.isVisible = visibleForModule;
                    if (attachment.Item != null & !attachment.Item.IsInternal && attachment.Item.IsVisible != visibleForRepository)
                    {
                        attachment.Item.UpdateMetaInfo(person.Id, UC.IpAddress, UC.ProxyIpAddress, attachment.ModifiedOn);
                        attachment.Item.IsVisible = visibleForRepository;
                        Manager.SaveOrUpdate(attachment.Item);
                        updateRepositoryItems = true;
                    }

                    Manager.SaveOrUpdate(attachment);
                    item.ModifiedBy = attachment.ModifiedBy;
                    item.ModifiedOn = attachment.ModifiedOn.Value;
                    Manager.SaveOrUpdate(item);
                    Manager.Commit();
                    if (updateRepositoryItems)
                    {
                        Manager.Refresh(Manager.Get <lm.Comol.Core.FileRepository.Domain.RepositoryItem>(attachment.Item.Id));
                        lm.Comol.Core.DomainModel.Helpers.CacheHelper.PurgeCacheItems(lm.Comol.Core.FileRepository.Domain.CacheKeys.Repository(attachment.Item.Repository));
                        lm.Comol.Core.DomainModel.Helpers.CacheHelper.PurgeCacheItems(lm.Comol.Core.FileRepository.Domain.CacheKeys.UsersViewOfRepository(attachment.Item.Repository));
                        lm.Comol.Core.DomainModel.Helpers.CacheHelper.PurgeCacheItems(lm.Comol.Core.FileRepository.Domain.CacheKeys.UsersSizeViewOfRepository(attachment.Item.Repository));
                    }
                }
                catch (Exception ex)
                {
                    Manager.RollBack();
                }
            }
        }
예제 #12
0
        public dtoAttachment(EventItemFile itemFile)
        {
            Id          = itemFile.Id;
            IdEvent     = itemFile.IdEventOwner;
            IdEventItem = itemFile.IdItemOwner;
            IdCommunity = itemFile.IdCommunity;

            Link         = itemFile.Link;
            IdModuleLink = (Link == null) ? 0 : Link.Id;
            if (itemFile.Item != null)
            {
                File = new RepositoryItemObject(itemFile.Item);
            }

            CreatedOn = itemFile.CreatedOn.Value;
            if (ModifiedOn.HasValue)
            {
                ModifiedOn = itemFile.ModifiedOn.Value;
            }
            Deleted   = itemFile.Deleted;
            IsVisible = itemFile.isVisible;
        }
        private List <StandardActionType> GetAllowedStandardActionForFile(int idUser, ModuleObject source, ModuleObject destination)
        {
            List <StandardActionType> actions = new List <StandardActionType>();
            litePerson    person     = Manager.GetLitePerson(idUser);
            EventItemFile attachment = Manager.Get <EventItemFile>(source.ObjectLongID);

            if (attachment != null && attachment.Link != null && source.ObjectLongID == attachment.Id)
            {
                ModuleCommunityDiary modulePermission = GetPermissions(idUser, attachment.IdCommunity);
                lm.Comol.Core.FileRepository.Domain.ModuleRepository moduleRepository = GetCoreModuleRepository(idUser, attachment.IdCommunity);
                CoreItemPermission itemPermission = GetItemPermission(person, EventItemGet(attachment.IdItemOwner), modulePermission, moduleRepository);

                if (attachment.Item != null)
                {
                    Boolean isMultimedia = attachment.Item.Type == Core.FileRepository.Domain.ItemType.Multimedia;
                    Boolean isScorm      = attachment.Item.Type == Core.FileRepository.Domain.ItemType.ScormPackage;
                    Boolean isInternal   = attachment.Item.IsInternal;
                    if ((isScorm || isMultimedia) && (attachment.Item.Availability == Core.FileRepository.Domain.ItemAvailability.available || attachment.Item.Availability == Core.FileRepository.Domain.ItemAvailability.waitingsettings) && ((isInternal && itemPermission.AllowEdit) ||
                                                                                                                                                                                                                                                (!isInternal && (moduleRepository.Administration || moduleRepository.EditOthersFiles || (moduleRepository.EditMyFiles && attachment.Item.IdOwner == person.Id)))))
                    {
                        actions.Add(StandardActionType.EditMetadata);
                    }
                    if (AllowViewFileFromLink(modulePermission, itemPermission, attachment, person))
                    {
                        actions.Add(StandardActionType.Play);
                        if (isScorm)
                        {
                            actions.Add(StandardActionType.ViewPersonalStatistics);
                        }
                    }
                    if ((isScorm && attachment.Item.Availability == Core.FileRepository.Domain.ItemAvailability.available) && ((isInternal && itemPermission.AllowEdit) || (!isInternal && (moduleRepository.Administration || moduleRepository.EditOthersFiles || (moduleRepository.EditMyFiles && attachment.Item.IdOwner == person.Id)))))
                    {
                        actions.Add(StandardActionType.ViewAdvancedStatistics);
                    }
                }
            }
            return(actions);
        }
        public List <EventItemFile> AttachmentsAddFiles(CommunityEventItem eventItem, List <dtoModuleUploadedItem> items, Boolean visibleForItem)
        {
            List <EventItemFile> attachments = null;
            Boolean isInTransaction          = Manager.IsInTransaction();

            try
            {
                if (!isInTransaction)
                {
                    Manager.BeginTransaction();
                }
                litePerson person = Manager.GetLitePerson(UC.CurrentUserID);
                if (items.Any() && eventItem != null && person != null && person.TypeID != (int)UserTypeStandard.Guest && person.TypeID != (int)UserTypeStandard.PublicUser)
                {
                    attachments = new List <EventItemFile>();
                    DateTime date = DateTime.Now;
                    foreach (dtoModuleUploadedItem item in items)
                    {
                        EventItemFile attachment = new EventItemFile();
                        attachment.CreateMetaInfo(person, UC.IpAddress, UC.ProxyIpAddress, date);
                        attachment.IdCommunity  = eventItem.IdCommunityOwner;
                        attachment.IdEventOwner = (eventItem.EventOwner != null ? eventItem.EventOwner.Id : 0);
                        attachment.IdItemOwner  = eventItem.Id;
                        attachment.Item         = item.ItemAdded;
                        attachment.isVisible    = visibleForItem;
                        attachment.Owner        = person;
                        Manager.SaveOrUpdate(attachment);
                        liteModuleLink link = new liteModuleLink(item.Link.Description, item.Link.Permission, item.Link.Action);
                        link.CreateMetaInfo(person.Id, UC.IpAddress, UC.ProxyIpAddress, date);
                        link.DestinationItem = (ModuleObject)item.Link.ModuleObject;
                        link.AutoEvaluable   = false;
                        link.SourceItem      = ModuleObject.CreateLongObject(attachment.Id, attachment, (int)ModuleCommunityDiary.ObjectType.DiaryItemLinkedFile, attachment.IdCommunity, ModuleCommunityDiary.UniqueID, ServiceModuleID());
                        Manager.SaveOrUpdate(link);
                        attachment.Link = link;

                        if (item.ItemAdded.IsInternal)
                        {
                            if (item.ItemAdded.Module == null)
                            {
                                item.ItemAdded.Module = new lm.Comol.Core.FileRepository.Domain.ItemModuleSettings();
                            }
                            item.ItemAdded.Module.IdObject     = attachment.Id;
                            item.ItemAdded.Module.IdObjectType = (int)ModuleCommunityDiary.ObjectType.DiaryItemLinkedFile;
                            Manager.SaveOrUpdate(item.ItemAdded);
                        }

                        Manager.SaveOrUpdate(attachment);
                        attachments.Add(attachment);
                    }
                }
                if (!isInTransaction)
                {
                    Manager.Commit();
                }
            }
            catch (Exception ex)
            {
                if (!isInTransaction)
                {
                    Manager.RollBack();
                }
                attachments = null;
            }
            return(attachments);
        }
        public List <EventItemFile> AttachmentsLinkFiles(long idEvent, long idEventItem, List <ModuleActionLink> links, Boolean visibleForItem, Boolean?visibleForRepository)
        {
            List <EventItemFile> attachments = null;
            Boolean isInTransaction          = Manager.IsInTransaction();

            try
            {
                if (!isInTransaction)
                {
                    Manager.BeginTransaction();
                }
                CommunityEventItem item   = EventItemGet(idEventItem);
                litePerson         person = Manager.GetLitePerson(UC.CurrentUserID);
                Boolean            updateRepositoryItems = false;
                if (links.Any() && item != null && person != null && person.TypeID != (int)UserTypeStandard.Guest && person.TypeID != (int)UserTypeStandard.PublicUser)
                {
                    DateTime date = DateTime.Now;
                    attachments = new List <EventItemFile>();
                    foreach (ModuleActionLink link in links)
                    {
                        EventItemFile attachment = QueryAttachments(a => a.Deleted == BaseStatusDeleted.None && a.IdItemOwner == idEventItem).ToList().Where(a => a.Item == (liteRepositoryItem)link.ModuleObject.ObjectOwner).Skip(0).Take(1).ToList().FirstOrDefault();
                        if (attachment == null)
                        {
                            attachment = new EventItemFile();
                            attachment.CreateMetaInfo(person, UC.IpAddress, UC.ProxyIpAddress, date);
                            attachment.Owner        = person;
                            attachment.IdCommunity  = item.IdCommunityOwner;
                            attachment.IdEventOwner = (item.EventOwner != null ? item.EventOwner.Id : 0);
                            attachment.IdItemOwner  = item.Id;
                            attachment.Item         = (liteRepositoryItem)link.ModuleObject.ObjectOwner;
                            attachment.isVisible    = visibleForItem;
                            attachment.Version      = null;
                            Manager.SaveOrUpdate(attachment);
                            if (!attachment.Item.IsInternal && visibleForRepository.HasValue && visibleForRepository.Value != attachment.Item.IsVisible)
                            {
                                attachment.Item.IsVisible = visibleForRepository.Value;
                                Manager.SaveOrUpdate(attachment.Item);
                                updateRepositoryItems = true;
                            }

                            liteModuleLink mLink = new liteModuleLink(link.Description, link.Permission, link.Action);
                            mLink.CreateMetaInfo(person.Id, UC.IpAddress, UC.ProxyIpAddress, date);
                            mLink.DestinationItem = (ModuleObject)link.ModuleObject;
                            mLink.AutoEvaluable   = false;
                            mLink.SourceItem      = ModuleObject.CreateLongObject(attachment.Id, attachment, (int)ModuleCommunityDiary.ObjectType.DiaryItemLinkedFile, attachment.IdCommunity, ModuleCommunityDiary.UniqueID, ServiceModuleID());
                            Manager.SaveOrUpdate(mLink);
                            attachment.Link = mLink;
                            Manager.SaveOrUpdate(attachment);
                        }
                        else if (attachment.Deleted != BaseStatusDeleted.None)
                        {
                            attachment.RecoverMetaInfo(person, UC.IpAddress, UC.ProxyIpAddress, date);
                            if (attachment.Item != null && attachment.Item.IsInternal && attachment.Item.Deleted != BaseStatusDeleted.None)
                            {
                                attachment.Item.Deleted = BaseStatusDeleted.None;
                                attachment.Item.UpdateMetaInfo(person.Id, UC.IpAddress, UC.ProxyIpAddress, date);
                                Manager.SaveOrUpdate(attachment.Item);
                            }
                            Manager.SaveOrUpdate(attachment);
                        }
                        attachments.Add(attachment);
                    }
                }
                if (!isInTransaction)
                {
                    Manager.Commit();
                }
                if (updateRepositoryItems && attachments.Any(a => !a.Item.IsInternal))
                {
                    RepositoryIdentifier identifier = attachments.Where(a => !a.Item.IsInternal).Select(a => a.Item.Repository).FirstOrDefault();
                    foreach (EventItemFile attachment in attachments.Where(a => !a.Item.IsInternal))
                    {
                        Manager.Refresh(Manager.Get <lm.Comol.Core.FileRepository.Domain.RepositoryItem>(attachment.Item.Id));
                    }
                    lm.Comol.Core.DomainModel.Helpers.CacheHelper.PurgeCacheItems(lm.Comol.Core.FileRepository.Domain.CacheKeys.Repository(identifier));
                    lm.Comol.Core.DomainModel.Helpers.CacheHelper.PurgeCacheItems(lm.Comol.Core.FileRepository.Domain.CacheKeys.UsersViewOfRepository(identifier));
                    lm.Comol.Core.DomainModel.Helpers.CacheHelper.PurgeCacheItems(lm.Comol.Core.FileRepository.Domain.CacheKeys.UsersSizeViewOfRepository(identifier));
                }
            }
            catch (Exception ex)
            {
                if (!isInTransaction)
                {
                    Manager.RollBack();
                }
                attachments = null;
            }
            return(attachments);
        }
예제 #16
0
 public dtoAttachment(EventItemFile itemFile, String unknownUser)
     : this(itemFile)
 {
     CreatedBy  = (itemFile.CreatedBy == null ? unknownUser : itemFile.CreatedBy.SurnameAndName);
     ModifiedBy = (itemFile.ModifiedBy == null ? unknownUser : itemFile.ModifiedBy.SurnameAndName);
 }
        private Boolean AllowViewFileFromLink(ModuleCommunityDiary modulePermission, CoreItemPermission itemPermission, EventItemFile attachment, litePerson person)
        {
            Boolean iResponse = false;

            iResponse = itemPermission.AllowViewFiles && (attachment.isVisible || attachment.IdItemOwner == person.Id || modulePermission.Administration);
            return(iResponse);
        }