Added GetAssetPermissions. Few last bugs nixed. This is ready for testing.

arthursv
Diva Canto 2009-08-13 17:34:15 -07:00
parent 5246dc33dc
commit 034c9cf606
15 changed files with 171 additions and 47 deletions

View File

@ -575,5 +575,10 @@ namespace OpenSim.Framework.Communications.Tests
root.ParentID = UUID.Zero;
return root;
}
public int GetAssetPermissions(UUID userID, UUID assetID)
{
return 1;
}
}
}

View File

@ -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<BulkUpdateInventoryPacket.FolderDataBlock> folderDataBlocks
= new List<BulkUpdateInventoryPacket.FolderDataBlock>();
SendBulkUpdateInventoryFolderRecursive(folder, ref folderDataBlocks, transactionId);
SendBulkUpdateInventoryFolderRecursive(folderBase, ref folderDataBlocks, transactionId);
if (folderDataBlocks.Count > 0)
{
@ -2191,17 +2188,19 @@ namespace OpenSim.Region.ClientStack.LindenUDP
/// <param name="folderDataBlocks"></param>
/// <param name="transactionId"></param>
private void SendBulkUpdateInventoryFolderRecursive(
InventoryFolderImpl folder, ref List<BulkUpdateInventoryPacket.FolderDataBlock> folderDataBlocks,
InventoryFolderBase folder, ref List<BulkUpdateInventoryPacket.FolderDataBlock> folderDataBlocks,
UUID transactionId)
{
folderDataBlocks.Add(GenerateBulkUpdateFolderDataBlock(folder));
const int MAX_ITEMS_PER_PACKET = 5;
IInventoryService invService = m_scene.RequestModuleInterface<IInventoryService>();
// 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<InventoryItemBase> items = folder.RequestListOfItems();
InventoryCollection contents = invService.GetFolderContent(AgentId, folder.ID); // folder.RequestListOfItems();
List<InventoryItemBase> items = contents.Items;
while (items.Count > 0)
{
BulkUpdateInventoryPacket bulkUpdate
@ -2233,8 +2232,8 @@ namespace OpenSim.Region.ClientStack.LindenUDP
folderDataBlocks.Add(GenerateBulkUpdateFolderDataBlock(folder));
}
List<InventoryFolderImpl> subFolders = folder.RequestListOfFolderImpls();
foreach (InventoryFolderImpl subFolder in subFolders)
List<InventoryFolderBase> subFolders = contents.Folders;
foreach (InventoryFolderBase subFolder in subFolders)
{
SendBulkUpdateInventoryFolderRecursive(subFolder, ref folderDataBlocks, transactionId);
}

View File

@ -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");
}

View File

@ -82,7 +82,11 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Inventory
/// </summary>
/// <param name="userID"></param>
/// <returns>null if no root folder was found</returns>
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<AssetType, InventoryFolderBase> GetSystemFolders(UUID userID);
@ -202,5 +206,6 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Inventory
/// <returns></returns>
public abstract List<InventoryItemBase> GetActiveGestures(UUID userId);
public abstract int GetAssetPermissions(UUID userID, UUID assetID);
}
}

View File

@ -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,16 +424,23 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Inventory
return false;
}
public override InventoryFolderBase GetRootFolder(UUID userID)
{
return null;
}
public override List<InventoryItemBase> GetActiveGestures(UUID userId)
{
return new List<InventoryItemBase>();
}
public override int GetAssetPermissions(UUID userID, UUID assetID)
{
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
private UUID GetSessionID(UUID userID)

View File

@ -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,20 +319,15 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Inventory
return m_InventoryService.HasInventoryForUser(userID);
}
/// <summary>
/// Retrieve the root inventory folder for the given user.
/// </summary>
/// <param name="userID"></param>
/// <returns>null if no root folder was found</returns>
public override InventoryFolderBase GetRootFolder(UUID userID)
{
return m_InventoryService.GetRootFolder(userID);
}
public override List<InventoryItemBase> GetActiveGestures(UUID userId)
{
return m_InventoryService.GetActiveGestures(userId);
}
public override int GetAssetPermissions(UUID userID, UUID assetID)
{
return m_InventoryService.GetAssetPermissions(userID, assetID);
}
#endregion IInventoryService
}
}

View File

@ -296,16 +296,18 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Inventory
return false;
}
public override InventoryFolderBase GetRootFolder(UUID userID)
{
return null;
}
public override List<InventoryItemBase> GetActiveGestures(UUID userId)
{
return new List<InventoryItemBase>();
}
public override int GetAssetPermissions(UUID userID, UUID assetID)
{
UUID sessionID = GetSessionID(userID);
return m_RemoteConnector.GetAssetPermissions(userID.ToString(), assetID, sessionID);
}
#endregion
private UUID GetSessionID(UUID userID)

View File

@ -153,6 +153,11 @@ namespace OpenSim.Server.Handlers.Inventory
m_httpServer.AddStreamHandler(
new RestDeserialiseTrustedHandler<Guid, List<InventoryFolderBase>>
("POST", "/RootFolders/", GetInventorySkeleton, CheckTrustSource));
m_httpServer.AddStreamHandler(
new RestDeserialiseTrustedHandler<InventoryItemBase, int>
("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
/// <summary>

View File

@ -149,7 +149,7 @@ namespace OpenSim.Services.Connectors.Inventory
/// <returns></returns>
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;
}
}
}

View File

@ -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);
}
}

View File

@ -163,21 +163,21 @@ namespace OpenSim.Services.Connectors
/// <returns></returns>
public Dictionary<AssetType, InventoryFolderBase> GetSystemFolders(string userID, UUID sessionID)
{
// !!! Not just yet.
//try
//{
// List<InventoryFolderBase> folders = SynchronousRestSessionObjectPoster<Guid, List<InventoryFolderBase>>.BeginPostObject(
// "POST", m_ServerURI + "/SystemFolders/", new Guid(userID), sessionID.ToString(), userID.ToString());
// Dictionary<AssetType, InventoryFolderBase> dFolders = new Dictionary<AssetType, InventoryFolderBase>();
// 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<InventoryFolderBase> folders = SynchronousRestSessionObjectPoster<Guid, List<InventoryFolderBase>>.BeginPostObject(
"POST", m_ServerURI + "/SystemFolders/", new Guid(userID), sessionID.ToString(), userID.ToString());
Dictionary<AssetType, InventoryFolderBase> dFolders = new Dictionary<AssetType, InventoryFolderBase>();
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<AssetType, InventoryFolderBase>();
}
@ -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<InventoryItemBase, int>.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
/// <summary>

View File

@ -176,5 +176,10 @@ namespace OpenSim.Services.Connectors
return null;
}
public int GetAssetPermissions(UUID userID, UUID assetID)
{
return 0;
}
}
}

View File

@ -149,8 +149,18 @@ namespace OpenSim.Services.Interfaces
/// <returns>true if the item was successfully deleted</returns>
bool DeleteItem(InventoryItemBase item);
/// <summary>
/// Get an item, given by its UUID
/// </summary>
/// <param name="item"></param>
/// <returns></returns>
InventoryItemBase GetItem(InventoryItemBase item);
/// <summary>
/// Get a folder, given by its UUID
/// </summary>
/// <param name="folder"></param>
/// <returns></returns>
InventoryFolderBase GetFolder(InventoryFolderBase folder);
/// <summary>
@ -166,5 +176,15 @@ namespace OpenSim.Services.Interfaces
/// <param name="userId"></param>
/// <returns></returns>
List<InventoryItemBase> GetActiveGestures(UUID userId);
/// <summary>
/// Get the union of permissions of all inventory items
/// that hold the given assetID.
/// </summary>
/// <param name="userID"></param>
/// <param name="assetID"></param>
/// <returns>The permissions or 0 if no such asset is found in
/// the user's inventory</returns>
int GetAssetPermissions(UUID userID, UUID assetID);
}
}

View File

@ -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;
}
/// <summary>
/// Used to create a new user inventory.
/// </summary>

View File

@ -171,5 +171,10 @@ namespace OpenSim.Tests.Common.Mock
root.ParentID = UUID.Zero;
return root;
}
public int GetAssetPermissions(UUID userID, UUID assetID)
{
return 1;
}
}
}