From 034c9cf606373bfa9d3f8040cd787f789e0efbf2 Mon Sep 17 00:00:00 2001 From: Diva Canto Date: Thu, 13 Aug 2009 17:34:15 -0700 Subject: Added GetAssetPermissions. Few last bugs nixed. This is ready for testing. --- .../Communications/Tests/LoginServiceTests.cs | 5 +++ .../Region/ClientStack/LindenUDP/LLClientView.cs | 15 ++++--- .../Agent/TextureDownload/TextureDownloadModule.cs | 8 +++- .../Inventory/BaseInventoryConnector.cs | 7 +++- .../Inventory/HGInventoryBroker.cs | 17 ++++++-- .../Inventory/LocalInventoryServiceConnector.cs | 20 +++++---- .../Inventory/RemoteInventoryServiceConnector.cs | 10 +++-- .../Inventory/InventoryServerInConnector.cs | 12 ++++++ .../Inventory/HGInventoryServiceConnector.cs | 14 ++++++- .../Inventory/ISessionAuthInventoryService.cs | 2 + .../Inventory/InventoryServiceConnector.cs | 49 +++++++++++++++------- .../QuickAndDirtyInventoryServiceConnector.cs | 5 +++ OpenSim/Services/Interfaces/IInventoryService.cs | 20 +++++++++ .../Services/InventoryService/InventoryService.cs | 23 ++++++++++ OpenSim/Tests/Common/Mock/TestInventoryService.cs | 5 +++ 15 files changed, 168 insertions(+), 44 deletions(-) diff --git a/OpenSim/Framework/Communications/Tests/LoginServiceTests.cs b/OpenSim/Framework/Communications/Tests/LoginServiceTests.cs index 3161364..22dcef9 100644 --- a/OpenSim/Framework/Communications/Tests/LoginServiceTests.cs +++ b/OpenSim/Framework/Communications/Tests/LoginServiceTests.cs @@ -575,5 +575,10 @@ namespace OpenSim.Framework.Communications.Tests root.ParentID = UUID.Zero; return root; } + + public int GetAssetPermissions(UUID userID, UUID assetID) + { + return 1; + } } } diff --git a/OpenSim/Region/ClientStack/LindenUDP/LLClientView.cs b/OpenSim/Region/ClientStack/LindenUDP/LLClientView.cs index a3e275d..6dda5aa 100644 --- a/OpenSim/Region/ClientStack/LindenUDP/LLClientView.cs +++ b/OpenSim/Region/ClientStack/LindenUDP/LLClientView.cs @@ -2156,16 +2156,13 @@ namespace OpenSim.Region.ClientStack.LindenUDP protected void SendBulkUpdateInventoryFolder(InventoryFolderBase folderBase) { - // XXX: Nasty temporary move that will be resolved shortly - InventoryFolderImpl folder = (InventoryFolderImpl)folderBase; - // We will use the same transaction id for all the separate packets to be sent out in this update. UUID transactionId = UUID.Random(); List folderDataBlocks = new List(); - SendBulkUpdateInventoryFolderRecursive(folder, ref folderDataBlocks, transactionId); + SendBulkUpdateInventoryFolderRecursive(folderBase, ref folderDataBlocks, transactionId); if (folderDataBlocks.Count > 0) { @@ -2191,17 +2188,19 @@ namespace OpenSim.Region.ClientStack.LindenUDP /// /// private void SendBulkUpdateInventoryFolderRecursive( - InventoryFolderImpl folder, ref List folderDataBlocks, + InventoryFolderBase folder, ref List folderDataBlocks, UUID transactionId) { folderDataBlocks.Add(GenerateBulkUpdateFolderDataBlock(folder)); const int MAX_ITEMS_PER_PACKET = 5; + IInventoryService invService = m_scene.RequestModuleInterface(); // If there are any items then we have to start sending them off in this packet - the next folder will have // to be in its own bulk update packet. Also, we can only fit 5 items in a packet (at least this was the limit // being used on the Linden grid at 20081203). - List items = folder.RequestListOfItems(); + InventoryCollection contents = invService.GetFolderContent(AgentId, folder.ID); // folder.RequestListOfItems(); + List items = contents.Items; while (items.Count > 0) { BulkUpdateInventoryPacket bulkUpdate @@ -2233,8 +2232,8 @@ namespace OpenSim.Region.ClientStack.LindenUDP folderDataBlocks.Add(GenerateBulkUpdateFolderDataBlock(folder)); } - List subFolders = folder.RequestListOfFolderImpls(); - foreach (InventoryFolderImpl subFolder in subFolders) + List subFolders = contents.Folders; + foreach (InventoryFolderBase subFolder in subFolders) { SendBulkUpdateInventoryFolderRecursive(subFolder, ref folderDataBlocks, transactionId); } diff --git a/OpenSim/Region/CoreModules/Agent/TextureDownload/TextureDownloadModule.cs b/OpenSim/Region/CoreModules/Agent/TextureDownload/TextureDownloadModule.cs index 956dd10..71ff28c 100644 --- a/OpenSim/Region/CoreModules/Agent/TextureDownload/TextureDownloadModule.cs +++ b/OpenSim/Region/CoreModules/Agent/TextureDownload/TextureDownloadModule.cs @@ -222,8 +222,12 @@ namespace OpenSim.Region.CoreModules.Agent.TextureDownload if (invService.GetRootFolder(client.AgentId) == null) // Deny no inventory return; - if (profile.UserProfile.GodLevel < 200 && profile.RootFolder.FindAsset(e.RequestedAssetID) == null) // Deny if not owned - return; + // Diva 2009-08-13: this test doesn't make any sense to many devs + //if (profile.UserProfile.GodLevel < 200 && profile.RootFolder.FindAsset(e.RequestedAssetID) == null) // Deny if not owned + //{ + // m_log.WarnFormat("[TEXTURE]: user {0} doesn't have permissions to texture {1}"); + // return; + //} m_log.Debug("Texture preview"); } diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Inventory/BaseInventoryConnector.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Inventory/BaseInventoryConnector.cs index 0526bc4..ef5ffe1 100644 --- a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Inventory/BaseInventoryConnector.cs +++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Inventory/BaseInventoryConnector.cs @@ -82,7 +82,11 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Inventory /// /// /// null if no root folder was found - public abstract InventoryFolderBase GetRootFolder(UUID userID); + public InventoryFolderBase GetRootFolder(UUID userID) + { + // Root folder is here as system type Folder. + return m_cache.GetFolderForType(userID, AssetType.Folder); + } public abstract Dictionary GetSystemFolders(UUID userID); @@ -202,5 +206,6 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Inventory /// public abstract List GetActiveGestures(UUID userId); + public abstract int GetAssetPermissions(UUID userID, UUID assetID); } } diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Inventory/HGInventoryBroker.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Inventory/HGInventoryBroker.cs index db4e7f4..fd12a57 100644 --- a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Inventory/HGInventoryBroker.cs +++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Inventory/HGInventoryBroker.cs @@ -263,6 +263,8 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Inventory folders[(AssetType)folder.Type] = folder; } m_log.DebugFormat("[HG INVENTORY CONNECTOR]: System folders count for {0}: {1}", userID, folders.Count); + // Put the root folder there, as type Folder + folders[AssetType.Folder] = root; return folders; } m_log.DebugFormat("[HG INVENTORY CONNECTOR]: Root folder content not found for {0}", userID); @@ -422,14 +424,21 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Inventory return false; } - public override InventoryFolderBase GetRootFolder(UUID userID) + public override List GetActiveGestures(UUID userId) { - return null; + return new List(); } - public override List GetActiveGestures(UUID userId) + public override int GetAssetPermissions(UUID userID, UUID assetID) { - return new List(); + if (IsLocalGridUser(userID)) + return m_GridService.GetAssetPermissions(userID, assetID); + else + { + UUID sessionID = GetSessionID(userID); + string uri = GetUserInventoryURI(userID) + "/" + userID.ToString(); + return m_HGService.GetAssetPermissions(uri, assetID, sessionID); + } } #endregion diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Inventory/LocalInventoryServiceConnector.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Inventory/LocalInventoryServiceConnector.cs index ccf06d1..2fbc5fe 100644 --- a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Inventory/LocalInventoryServiceConnector.cs +++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Inventory/LocalInventoryServiceConnector.cs @@ -201,8 +201,15 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Inventory foreach (InventoryFolderBase folder in content.Folders) { if ((folder.Type != (short)AssetType.Folder) && (folder.Type != (short)AssetType.Unknown)) + { + m_log.InfoFormat("[INVENTORY CONNECTOR]: folder type {0} ", folder.Type); folders[(AssetType)folder.Type] = folder; + } } + // Put the root folder there, as type Folder + folders[AssetType.Folder] = root; + m_log.InfoFormat("[INVENTORY CONNECTOR]: root folder is type {0} ", root.Type); + return folders; } } @@ -312,19 +319,14 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Inventory return m_InventoryService.HasInventoryForUser(userID); } - /// - /// Retrieve the root inventory folder for the given user. - /// - /// - /// null if no root folder was found - public override InventoryFolderBase GetRootFolder(UUID userID) + public override List GetActiveGestures(UUID userId) { - return m_InventoryService.GetRootFolder(userID); + return m_InventoryService.GetActiveGestures(userId); } - public override List GetActiveGestures(UUID userId) + public override int GetAssetPermissions(UUID userID, UUID assetID) { - return m_InventoryService.GetActiveGestures(userId); + return m_InventoryService.GetAssetPermissions(userID, assetID); } #endregion IInventoryService } diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Inventory/RemoteInventoryServiceConnector.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Inventory/RemoteInventoryServiceConnector.cs index 4f19573..e4bb865 100644 --- a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Inventory/RemoteInventoryServiceConnector.cs +++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Inventory/RemoteInventoryServiceConnector.cs @@ -296,16 +296,18 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Inventory return false; } - public override InventoryFolderBase GetRootFolder(UUID userID) + public override List GetActiveGestures(UUID userId) { - return null; + return new List(); } - public override List GetActiveGestures(UUID userId) + public override int GetAssetPermissions(UUID userID, UUID assetID) { - return new List(); + UUID sessionID = GetSessionID(userID); + return m_RemoteConnector.GetAssetPermissions(userID.ToString(), assetID, sessionID); } + #endregion private UUID GetSessionID(UUID userID) diff --git a/OpenSim/Server/Handlers/Inventory/InventoryServerInConnector.cs b/OpenSim/Server/Handlers/Inventory/InventoryServerInConnector.cs index 63cf034..30b3cae 100644 --- a/OpenSim/Server/Handlers/Inventory/InventoryServerInConnector.cs +++ b/OpenSim/Server/Handlers/Inventory/InventoryServerInConnector.cs @@ -153,6 +153,11 @@ namespace OpenSim.Server.Handlers.Inventory m_httpServer.AddStreamHandler( new RestDeserialiseTrustedHandler> ("POST", "/RootFolders/", GetInventorySkeleton, CheckTrustSource)); + + m_httpServer.AddStreamHandler( + new RestDeserialiseTrustedHandler + ("POST", "/AssetPermissions/", GetAssetPermissions, CheckTrustSource)); + } #region Wrappers for converting the Guid parameter @@ -185,6 +190,8 @@ namespace OpenSim.Server.Handlers.Inventory if ((folder.Type != (short)AssetType.Folder) && (folder.Type != (short)AssetType.Unknown)) folders[(AssetType)folder.Type] = folder; } + // Put the root folder there, as type Folder + folders[AssetType.Folder] = root; return folders; } } @@ -235,6 +242,11 @@ namespace OpenSim.Server.Handlers.Inventory return m_InventoryService.GetInventorySkeleton(userID); } + public int GetAssetPermissions(InventoryItemBase item) + { + return m_InventoryService.GetAssetPermissions(item.Owner, item.AssetID); + } + #endregion /// diff --git a/OpenSim/Services/Connectors/Inventory/HGInventoryServiceConnector.cs b/OpenSim/Services/Connectors/Inventory/HGInventoryServiceConnector.cs index f6d1500..94b4ad9 100644 --- a/OpenSim/Services/Connectors/Inventory/HGInventoryServiceConnector.cs +++ b/OpenSim/Services/Connectors/Inventory/HGInventoryServiceConnector.cs @@ -149,7 +149,7 @@ namespace OpenSim.Services.Connectors.Inventory /// public InventoryCollection GetFolderContent(string id, UUID folderID, UUID sessionID) { - m_log.Debug("[HGInventory]: GetSystemFolders " + id); + m_log.Debug("[HGInventory]: GetFolderContent " + id); string url = string.Empty; string userID = string.Empty; @@ -279,5 +279,17 @@ namespace OpenSim.Services.Connectors.Inventory return null; } + public int GetAssetPermissions(string id, UUID assetID, UUID sessionID) + { + string url = string.Empty; + string userID = string.Empty; + + if (StringToUrlAndUserID(id, out url, out userID)) + { + ISessionAuthInventoryService connector = GetConnector(url); + return connector.GetAssetPermissions(userID, assetID, sessionID); + } + return 0; + } } } diff --git a/OpenSim/Services/Connectors/Inventory/ISessionAuthInventoryService.cs b/OpenSim/Services/Connectors/Inventory/ISessionAuthInventoryService.cs index 973cb0a..f50bcf5 100644 --- a/OpenSim/Services/Connectors/Inventory/ISessionAuthInventoryService.cs +++ b/OpenSim/Services/Connectors/Inventory/ISessionAuthInventoryService.cs @@ -120,5 +120,7 @@ namespace OpenSim.Services.Connectors InventoryFolderBase QueryFolder(string userID, InventoryFolderBase item, UUID session_id); + int GetAssetPermissions(string userID, UUID assetID, UUID session_id); + } } diff --git a/OpenSim/Services/Connectors/Inventory/InventoryServiceConnector.cs b/OpenSim/Services/Connectors/Inventory/InventoryServiceConnector.cs index e41b427..4907015 100644 --- a/OpenSim/Services/Connectors/Inventory/InventoryServiceConnector.cs +++ b/OpenSim/Services/Connectors/Inventory/InventoryServiceConnector.cs @@ -163,21 +163,21 @@ namespace OpenSim.Services.Connectors /// public Dictionary GetSystemFolders(string userID, UUID sessionID) { - // !!! Not just yet. - //try - //{ - // List folders = SynchronousRestSessionObjectPoster>.BeginPostObject( - // "POST", m_ServerURI + "/SystemFolders/", new Guid(userID), sessionID.ToString(), userID.ToString()); - // Dictionary dFolders = new Dictionary(); - // foreach (InventoryFolderBase f in folders) - // dFolders[(AssetType)f.Type] = f; - // return dFolders; - //} - //catch (Exception e) - //{ - // m_log.ErrorFormat("[INVENTORY CONNECTOR]: GetSystemFolders operation failed, {0} {1}", - // e.Source, e.Message); - //} + try + { + List folders = SynchronousRestSessionObjectPoster>.BeginPostObject( + "POST", m_ServerURI + "/SystemFolders/", new Guid(userID), sessionID.ToString(), userID.ToString()); + + Dictionary dFolders = new Dictionary(); + foreach (InventoryFolderBase f in folders) + dFolders[(AssetType)f.Type] = f; + return dFolders; + } + catch (Exception e) + { + m_log.ErrorFormat("[INVENTORY CONNECTOR]: GetSystemFolders operation failed, {0} {1}", + e.Source, e.Message); + } return new Dictionary(); } @@ -348,6 +348,25 @@ namespace OpenSim.Services.Connectors return null; } + public int GetAssetPermissions(string userID, UUID assetID, UUID sessionID) + { + try + { + InventoryItemBase item = new InventoryItemBase(); + item.Owner = new UUID(userID); + item.AssetID = assetID; + return SynchronousRestSessionObjectPoster.BeginPostObject( + "POST", m_ServerURI + "/AssetPermissions/", item, sessionID.ToString(), userID); + } + catch (Exception e) + { + m_log.ErrorFormat("[INVENTORY CONNECTOR]: AssetPermissions operation failed, {0} {1}", + e.Source, e.Message); + } + + return 0; + } + #endregion /// diff --git a/OpenSim/Services/Connectors/Inventory/QuickAndDirtyInventoryServiceConnector.cs b/OpenSim/Services/Connectors/Inventory/QuickAndDirtyInventoryServiceConnector.cs index 41aacd0..5cbd307 100644 --- a/OpenSim/Services/Connectors/Inventory/QuickAndDirtyInventoryServiceConnector.cs +++ b/OpenSim/Services/Connectors/Inventory/QuickAndDirtyInventoryServiceConnector.cs @@ -176,5 +176,10 @@ namespace OpenSim.Services.Connectors return null; } + public int GetAssetPermissions(UUID userID, UUID assetID) + { + return 0; + } + } } diff --git a/OpenSim/Services/Interfaces/IInventoryService.cs b/OpenSim/Services/Interfaces/IInventoryService.cs index 6256c32..a89a238 100644 --- a/OpenSim/Services/Interfaces/IInventoryService.cs +++ b/OpenSim/Services/Interfaces/IInventoryService.cs @@ -149,8 +149,18 @@ namespace OpenSim.Services.Interfaces /// true if the item was successfully deleted bool DeleteItem(InventoryItemBase item); + /// + /// Get an item, given by its UUID + /// + /// + /// InventoryItemBase GetItem(InventoryItemBase item); + /// + /// Get a folder, given by its UUID + /// + /// + /// InventoryFolderBase GetFolder(InventoryFolderBase folder); /// @@ -166,5 +176,15 @@ namespace OpenSim.Services.Interfaces /// /// List GetActiveGestures(UUID userId); + + /// + /// Get the union of permissions of all inventory items + /// that hold the given assetID. + /// + /// + /// + /// The permissions or 0 if no such asset is found in + /// the user's inventory + int GetAssetPermissions(UUID userID, UUID assetID); } } diff --git a/OpenSim/Services/InventoryService/InventoryService.cs b/OpenSim/Services/InventoryService/InventoryService.cs index 3d706dc..65c2d96 100644 --- a/OpenSim/Services/InventoryService/InventoryService.cs +++ b/OpenSim/Services/InventoryService/InventoryService.cs @@ -465,6 +465,29 @@ namespace OpenSim.Services.InventoryService return null; } + public int GetAssetPermissions(UUID userID, UUID assetID) + { + InventoryFolderBase parent = GetRootFolder(userID); + return FindAssetPerms(parent, assetID); + } + + private int FindAssetPerms(InventoryFolderBase folder, UUID assetID) + { + InventoryCollection contents = GetFolderContent(folder.Owner, folder.ID); + + int perms = 0; + foreach (InventoryItemBase item in contents.Items) + { + if (item.AssetID == assetID) + perms = (int)item.CurrentPermissions | perms; + } + + foreach (InventoryFolderBase subfolder in contents.Folders) + perms = perms | FindAssetPerms(subfolder, assetID); + + return perms; + } + /// /// Used to create a new user inventory. /// diff --git a/OpenSim/Tests/Common/Mock/TestInventoryService.cs b/OpenSim/Tests/Common/Mock/TestInventoryService.cs index 6576533..ba9cbe9 100644 --- a/OpenSim/Tests/Common/Mock/TestInventoryService.cs +++ b/OpenSim/Tests/Common/Mock/TestInventoryService.cs @@ -171,5 +171,10 @@ namespace OpenSim.Tests.Common.Mock root.ParentID = UUID.Zero; return root; } + + public int GetAssetPermissions(UUID userID, UUID assetID) + { + return 1; + } } } -- cgit v1.1