public dtoDisplayRepositoryItem(dtoRepositoryItem item, Int32 idPerson, liteRepositorySettings settings, ModuleRepository modulePermissions, Boolean forAdmin = false, Boolean hasAssignments = false)
     : base(item)
 {
     IsUserAvailable = forAdmin || hasAssignments;
     Children        = new List <dtoDisplayRepositoryItem>();
     Permissions     = CreatePermission(item, idPerson, settings, modulePermissions, forAdmin);
     Identifier      = new dtoItemIdentifier();
 }
        private ItemPermission CreatePermission(dtoRepositoryItem item, Int32 idPerson, liteRepositorySettings settings, ModuleRepository modulePermissions, Boolean forAdmin = false)
        {
            ItemPermission permissions  = new ItemPermission();
            Boolean        isOwner      = (item.IdOwner == idPerson);
            Boolean        manageOthers = (modulePermissions.Administration || modulePermissions.ManageItems || modulePermissions.EditOthersFiles);

            if (IsUserAvailable)
            {
                IsUserAvailable = manageOthers || (((isOwner && item.IsVisible) || item.IsVisible) && (item.Status == ItemStatus.Active || isOwner));
            }
            item.AllowUpload        = (!item.IsFile && item.FolderType == Domain.FolderType.standard && (item.AllowUpload || modulePermissions.Administration || modulePermissions.ManageItems || isOwner));
            permissions.AllowUpload = item.AllowUpload;
            switch (item.Type)
            {
            case ItemType.File:
                permissions.Unzip = (item.Availability == ItemAvailability.available) && ((item.Extension == ".zip") && (manageOthers || (modulePermissions.EditMyFiles && isOwner) || (modulePermissions.UploadFile && isOwner)));
                permissions.Zip   = (item.Availability == ItemAvailability.available) && (manageOthers || modulePermissions.DownloadOrPlay || (modulePermissions.EditMyFiles && isOwner) || (modulePermissions.UploadFile && isOwner));
                break;

            case ItemType.Folder:
                break;

            case ItemType.Multimedia:
            case ItemType.ScormPackage:
                permissions.CanEditSettings = ((item.Deleted == DomainModel.BaseStatusDeleted.None && manageOthers || (modulePermissions.EditMyFiles && isOwner) || (modulePermissions.UploadFile && isOwner && item.Availability == ItemAvailability.available)));
                permissions.EditSettings    = IsAvailableByType(item.Type, item.Availability) && ((item.Deleted == DomainModel.BaseStatusDeleted.None && manageOthers || (modulePermissions.EditMyFiles && isOwner) || (modulePermissions.UploadFile && isOwner && item.Availability == ItemAvailability.available)));
                permissions.Zip             = (item.Availability != ItemAvailability.notavailable) && (manageOthers || modulePermissions.DownloadOrPlay || (modulePermissions.EditMyFiles && isOwner) || (modulePermissions.UploadFile && isOwner));
                break;

            case ItemType.Link:
                break;
            }
            permissions.Edit                = manageOthers || (modulePermissions.EditMyFiles && isOwner) || (modulePermissions.UploadFile && isOwner);
            permissions.ViewMyStatistics    = ((item.Deleted == DomainModel.BaseStatusDeleted.None && item.Type != ItemType.Link && item.Type != ItemType.Folder && item.Type != ItemType.File) && !(manageOthers || (modulePermissions.EditMyFiles && isOwner && IsAvailableByType(item.Type, item.Availability)) || (modulePermissions.UploadFile && isOwner && IsAvailableByType(item.Type, item.Availability))));
            permissions.ViewOtherStatistics = (item.Deleted == DomainModel.BaseStatusDeleted.None && item.Type != ItemType.Link && item.Type != ItemType.Folder && item.Type != ItemType.File) && (manageOthers || (modulePermissions.EditMyFiles && isOwner && IsAvailableByType(item.Type, item.Availability)) || (modulePermissions.UploadFile && isOwner && IsAvailableByType(item.Type, item.Availability)));

            permissions.VersioningAvailable = (item.Availability != ItemAvailability.notavailable) && ((item.Deleted == DomainModel.BaseStatusDeleted.None && item.Type != ItemType.Folder && item.Type != ItemType.Link && settings.AllowVersioning));

            permissions.ViewPermission = permissions.Edit;
            permissions.EditPermission = manageOthers || (modulePermissions.EditMyFiles && isOwner) || (modulePermissions.UploadFile && isOwner && item.Availability != ItemAvailability.available);
            permissions.Delete         = (item.Deleted != DomainModel.BaseStatusDeleted.None && (manageOthers || (modulePermissions.DeleteMyFiles && isOwner)));
            permissions.UnDelete       = (item.Deleted != DomainModel.BaseStatusDeleted.None && (manageOthers || (modulePermissions.DeleteMyFiles && isOwner)));
            permissions.VirtualDelete  = (item.Deleted == DomainModel.BaseStatusDeleted.None && (manageOthers || (modulePermissions.DeleteMyFiles && isOwner)));


            permissions.Download       = (item.Availability != ItemAvailability.notavailable) && (manageOthers || (item.IsDownloadable && item.Type != ItemType.Folder && permissions.Download));
            permissions.Play           = IsAvailableByType(item.Type, item.Availability) && (item.Type == ItemType.Multimedia || item.Type == ItemType.ScormPackage) && ((manageOthers || permissions.Download) && item.Type != ItemType.Folder);
            permissions.Preview        = IsAvailableByType(item.Type, item.Availability) && (item.DisplayMode == Domain.DisplayMode.inModal || item.DisplayMode == Domain.DisplayMode.downloadOrPlayOrModal);
            permissions.AllowSelection = (item.Availability != ItemAvailability.notavailable && (isOwner || manageOthers || item.IsDownloadable || item.Type == ItemType.Link || item.Type == ItemType.Folder));
            permissions.Hide           = (item.Deleted == DomainModel.BaseStatusDeleted.None && permissions.Edit && item.IsVisible);
            permissions.Show           = (item.Deleted == DomainModel.BaseStatusDeleted.None && permissions.Edit && !item.IsVisible);
            return(permissions);
        }