add CanSellObject() permitions check functions

httptests
UbitUmarov 2017-03-30 17:39:21 +01:00
parent efed73b2c3
commit 9a01fddd1c
4 changed files with 151 additions and 66 deletions

View File

@ -1649,8 +1649,7 @@ namespace OpenSim.Region.CoreModules.World.Land
{ {
foreach (SceneObjectGroup obj in primsOverMe) foreach (SceneObjectGroup obj in primsOverMe)
{ {
if (obj.OwnerID == previousOwner && obj.GroupID == UUID.Zero && if(m_scene.Permissions.CanSellObject(previousOwner,obj, (byte)SaleType.Original))
(obj.EffectiveOwnerPerms & (uint)(OpenSim.Framework.PermissionMask.Transfer)) != 0)
m_BuySellModule.BuyObject(sp.ControllingClient, UUID.Zero, obj.LocalId, 1, 0); m_BuySellModule.BuyObject(sp.ControllingClient, UUID.Zero, obj.LocalId, 1, 0);
} }
} }

View File

@ -89,28 +89,23 @@ namespace OpenSim.Region.CoreModules.World.Objects.BuySell
if (part == null) if (part == null)
return; return;
if (part.ParentGroup.IsDeleted) SceneObjectGroup sog = part.ParentGroup;
if (sog == null || sog.IsDeleted)
return; return;
if (part.OwnerID != part.GroupID && part.OwnerID != client.AgentId && (!m_scene.Permissions.IsGod(client.AgentId)))
return;
if (part.OwnerID == part.GroupID) // Group owned
{
// Does the user have the power to put the object on sale? // Does the user have the power to put the object on sale?
if (!m_scene.Permissions.CanSellGroupObject(client.AgentId, part.GroupID)) if (!m_scene.Permissions.CanSellObject(client, sog, saleType))
{ {
client.SendAgentAlertMessage("You don't have permission to set group-owned objects on sale", false); client.SendAgentAlertMessage("You don't have permission to set object on sale", false);
return; return;
} }
}
part = part.ParentGroup.RootPart; part = sog.RootPart;
part.ObjectSaleType = saleType; part.ObjectSaleType = saleType;
part.SalePrice = salePrice; part.SalePrice = salePrice;
part.ParentGroup.HasGroupChanged = true; sog.HasGroupChanged = true;
part.SendPropertiesToClient(client); part.SendPropertiesToClient(client);
} }

View File

@ -300,6 +300,8 @@ namespace OpenSim.Region.CoreModules.World.Permissions
scenePermissions.OnDelinkObject += CanDelinkObject; scenePermissions.OnDelinkObject += CanDelinkObject;
scenePermissions.OnDeedObject += CanDeedObject; scenePermissions.OnDeedObject += CanDeedObject;
scenePermissions.OnSellGroupObject += CanSellGroupObject; scenePermissions.OnSellGroupObject += CanSellGroupObject;
scenePermissions.OnSellObjectByUserID += CanSellObjectByUserID;
scenePermissions.OnSellObject += CanSellObject;
scenePermissions.OnCreateObjectInventory += CanCreateObjectInventory; scenePermissions.OnCreateObjectInventory += CanCreateObjectInventory;
scenePermissions.OnEditObjectInventory += CanEditObjectInventory; scenePermissions.OnEditObjectInventory += CanEditObjectInventory;
@ -393,7 +395,10 @@ namespace OpenSim.Region.CoreModules.World.Permissions
scenePermissions.OnLinkObject -= CanLinkObject; scenePermissions.OnLinkObject -= CanLinkObject;
scenePermissions.OnDelinkObject -= CanDelinkObject; scenePermissions.OnDelinkObject -= CanDelinkObject;
scenePermissions.OnDeedObject -= CanDeedObject; scenePermissions.OnDeedObject -= CanDeedObject;
scenePermissions.OnSellGroupObject -= CanSellGroupObject; scenePermissions.OnSellGroupObject -= CanSellGroupObject;
scenePermissions.OnSellObjectByUserID -= CanSellObjectByUserID;
scenePermissions.OnSellObject -= CanSellObject;
scenePermissions.OnCreateObjectInventory -= CanCreateObjectInventory; scenePermissions.OnCreateObjectInventory -= CanCreateObjectInventory;
scenePermissions.OnEditObjectInventory -= CanEditObjectInventory; scenePermissions.OnEditObjectInventory -= CanEditObjectInventory;
@ -1826,6 +1831,86 @@ namespace OpenSim.Region.CoreModules.World.Permissions
return IsGroupMember(groupID, userID, (ulong)GroupPowers.ObjectSetForSale); return IsGroupMember(groupID, userID, (ulong)GroupPowers.ObjectSetForSale);
} }
private bool CanSellObjectByUserID(SceneObjectGroup sog, UUID userID, byte saleType)
{
DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
if (m_bypassPermissions) return m_bypassPermissionsValue;
if (sog == null || sog.IsDeleted || userID == UUID.Zero)
return false;
// sell is not a attachment op
if(sog.IsAttachment)
return false;
if(IsAdministrator(userID))
return true;
uint sogEffectiveOwnerPerms = sog.EffectiveOwnerPerms;
if((sogEffectiveOwnerPerms & (uint)PermissionMask.Transfer) == 0)
return false;
if(saleType == (byte)SaleType.Copy &&
(sogEffectiveOwnerPerms & (uint)PermissionMask.Copy) == 0)
return false;
UUID sogOwnerID = sog.OwnerID;
if(sogOwnerID == userID)
return true;
// else only group owned can be sold by members with powers
UUID sogGroupID = sog.GroupID;
if(sog.OwnerID != sogGroupID || sogGroupID == UUID.Zero)
return false;
return IsGroupMember(sogGroupID, userID, (ulong)GroupPowers.ObjectSetForSale);
}
private bool CanSellObject(SceneObjectGroup sog, ScenePresence sp, byte saleType)
{
DebugPermissionInformation(MethodInfo.GetCurrentMethod().Name);
if (m_bypassPermissions) return m_bypassPermissionsValue;
if (sog == null || sog.IsDeleted || sp == null || sp.IsDeleted)
return false;
// sell is not a attachment op
if(sog.IsAttachment)
return false;
if(sp.IsGod)
return true;
uint sogEffectiveOwnerPerms = sog.EffectiveOwnerPerms;
if((sogEffectiveOwnerPerms & (uint)PermissionMask.Transfer) == 0)
return false;
if(saleType == (byte)SaleType.Copy &&
(sogEffectiveOwnerPerms & (uint)PermissionMask.Copy) == 0)
return false;
UUID userID = sp.UUID;
UUID sogOwnerID = sog.OwnerID;
if(sogOwnerID == userID)
return true;
// else only group owned can be sold by members with powers
UUID sogGroupID = sog.GroupID;
if(sog.OwnerID != sogGroupID || sogGroupID == UUID.Zero)
return false;
ulong powers = 0;
if(!GroupMemberPowers(sogGroupID, sp, ref powers))
return false;
if((powers & (ulong)GroupPowers.ObjectSetForSale) == 0)
return false;
return true;
}
private bool CanTakeObject(SceneObjectGroup sog, ScenePresence sp) private bool CanTakeObject(SceneObjectGroup sog, ScenePresence sp)
{ {
// ignore locked, viewers shell ask for confirmation // ignore locked, viewers shell ask for confirmation

View File

@ -47,6 +47,8 @@ namespace OpenSim.Region.Framework.Scenes
public delegate bool TransferObjectHandler(UUID objectID, UUID recipient); public delegate bool TransferObjectHandler(UUID objectID, UUID recipient);
public delegate bool TakeObjectHandler(SceneObjectGroup sog, ScenePresence sp); public delegate bool TakeObjectHandler(SceneObjectGroup sog, ScenePresence sp);
public delegate bool SellGroupObjectHandler(UUID userID, UUID groupID); public delegate bool SellGroupObjectHandler(UUID userID, UUID groupID);
public delegate bool SellObjectHandlerByUserID(SceneObjectGroup sog, UUID userID, byte saleType);
public delegate bool SellObjectHandler(SceneObjectGroup sog, ScenePresence sp, byte saleType);
public delegate bool TakeCopyObjectHandler(SceneObjectGroup sog, ScenePresence sp); public delegate bool TakeCopyObjectHandler(SceneObjectGroup sog, ScenePresence sp);
public delegate bool DuplicateObjectHandler(SceneObjectGroup sog, ScenePresence sp); public delegate bool DuplicateObjectHandler(SceneObjectGroup sog, ScenePresence sp);
public delegate bool EditObjectByIDsHandler(UUID objectID, UUID editorID); public delegate bool EditObjectByIDsHandler(UUID objectID, UUID editorID);
@ -121,7 +123,11 @@ namespace OpenSim.Region.Framework.Scenes
public event DeleteObjectHandler OnDeleteObject; public event DeleteObjectHandler OnDeleteObject;
public event TransferObjectHandler OnTransferObject; public event TransferObjectHandler OnTransferObject;
public event TakeObjectHandler OnTakeObject; public event TakeObjectHandler OnTakeObject;
public event SellGroupObjectHandler OnSellGroupObject; public event SellGroupObjectHandler OnSellGroupObject;
public event SellObjectHandlerByUserID OnSellObjectByUserID;
public event SellObjectHandler OnSellObject;
public event TakeCopyObjectHandler OnTakeCopyObject; public event TakeCopyObjectHandler OnTakeCopyObject;
public event DuplicateObjectHandler OnDuplicateObject; public event DuplicateObjectHandler OnDuplicateObject;
public event EditObjectByIDsHandler OnEditObjectByIDs; public event EditObjectByIDsHandler OnEditObjectByIDs;
@ -281,14 +287,11 @@ namespace OpenSim.Region.Framework.Scenes
} }
} }
} }
return result; return result;
} }
public bool CanDeleteObject(SceneObjectGroup sog, IClientAPI client) public bool CanDeleteObject(SceneObjectGroup sog, IClientAPI client)
{ {
bool result = true;
DeleteObjectHandler handler = OnDeleteObject; DeleteObjectHandler handler = OnDeleteObject;
if (handler != null) if (handler != null)
{ {
@ -301,20 +304,15 @@ namespace OpenSim.Region.Framework.Scenes
foreach (DeleteObjectHandler h in list) foreach (DeleteObjectHandler h in list)
{ {
if (h(sog, sp) == false) if (h(sog, sp) == false)
{ return false;
result = false;
break;
}
} }
} }
return result; return true;
} }
public bool CanTransferObject(UUID objectID, UUID recipient) public bool CanTransferObject(UUID objectID, UUID recipient)
{ {
bool result = true;
TransferObjectHandler handler = OnTransferObject; TransferObjectHandler handler = OnTransferObject;
if (handler != null) if (handler != null)
{ {
@ -322,14 +320,10 @@ namespace OpenSim.Region.Framework.Scenes
foreach (TransferObjectHandler h in list) foreach (TransferObjectHandler h in list)
{ {
if (h(objectID, recipient) == false) if (h(objectID, recipient) == false)
{ return false;
result = false;
break;
} }
} }
} return true;
return result;
} }
#endregion #endregion
@ -337,8 +331,6 @@ namespace OpenSim.Region.Framework.Scenes
#region TAKE OBJECT #region TAKE OBJECT
public bool CanTakeObject(SceneObjectGroup sog, ScenePresence sp) public bool CanTakeObject(SceneObjectGroup sog, ScenePresence sp)
{ {
bool result = true;
TakeObjectHandler handler = OnTakeObject; TakeObjectHandler handler = OnTakeObject;
if (handler != null) if (handler != null)
{ {
@ -349,18 +341,13 @@ namespace OpenSim.Region.Framework.Scenes
foreach (TakeObjectHandler h in list) foreach (TakeObjectHandler h in list)
{ {
if (h(sog, sp) == false) if (h(sog, sp) == false)
{ return false;
result = false;
break;
} }
} }
}
// m_log.DebugFormat( // m_log.DebugFormat(
// "[SCENE PERMISSIONS]: CanTakeObject() fired for object {0}, taker {1}, result {2}", // "[SCENE PERMISSIONS]: CanTakeObject() fired for object {0}, taker {1}, result {2}",
// objectID, AvatarTakingUUID, result); // objectID, AvatarTakingUUID, result);
return true;
return result;
} }
#endregion #endregion
@ -368,8 +355,6 @@ namespace OpenSim.Region.Framework.Scenes
#region SELL GROUP OBJECT #region SELL GROUP OBJECT
public bool CanSellGroupObject(UUID userID, UUID groupID) public bool CanSellGroupObject(UUID userID, UUID groupID)
{ {
bool result = true;
SellGroupObjectHandler handler = OnSellGroupObject; SellGroupObjectHandler handler = OnSellGroupObject;
if (handler != null) if (handler != null)
{ {
@ -377,18 +362,52 @@ namespace OpenSim.Region.Framework.Scenes
foreach (SellGroupObjectHandler h in list) foreach (SellGroupObjectHandler h in list)
{ {
if (h(userID, groupID) == false) if (h(userID, groupID) == false)
{ return false;
result = false;
break;
} }
} }
}
//m_log.DebugFormat( //m_log.DebugFormat(
// "[SCENE PERMISSIONS]: CanSellGroupObject() fired for user {0}, group {1}, result {2}", // "[SCENE PERMISSIONS]: CanSellGroupObject() fired for user {0}, group {1}, result {2}",
// userID, groupID, result); // userID, groupID, result);
return true;
}
return result; #endregion
#region SELL OBJECT
public bool CanSellObject(IClientAPI client, SceneObjectGroup sog, byte saleType)
{
SellObjectHandler handler = OnSellObject;
if (handler != null)
{
if(sog == null || client == null || client.SceneAgent == null)
return false;
ScenePresence sp = client.SceneAgent as ScenePresence;
Delegate[] list = handler.GetInvocationList();
foreach (SellObjectHandler h in list)
{
if (h(sog, sp, saleType) == false)
return false;
}
}
return true;
}
public bool CanSellObject(UUID userID, SceneObjectGroup sog, byte saleType)
{
SellObjectHandlerByUserID handler = OnSellObjectByUserID;
if (handler != null)
{
if(sog == null)
return false;
Delegate[] list = handler.GetInvocationList();
foreach (SellObjectHandlerByUserID h in list)
{
if (h(sog, userID, saleType) == false)
return false;
}
}
return true;
} }
#endregion #endregion
@ -397,8 +416,6 @@ namespace OpenSim.Region.Framework.Scenes
#region TAKE COPY OBJECT #region TAKE COPY OBJECT
public bool CanTakeCopyObject(SceneObjectGroup sog, ScenePresence sp) public bool CanTakeCopyObject(SceneObjectGroup sog, ScenePresence sp)
{ {
bool result = true;
TakeCopyObjectHandler handler = OnTakeCopyObject; TakeCopyObjectHandler handler = OnTakeCopyObject;
if (handler != null) if (handler != null)
{ {
@ -408,18 +425,13 @@ namespace OpenSim.Region.Framework.Scenes
foreach (TakeCopyObjectHandler h in list) foreach (TakeCopyObjectHandler h in list)
{ {
if (h(sog, sp) == false) if (h(sog, sp) == false)
{ return false;
result = false;
break;
} }
} }
}
// m_log.DebugFormat( // m_log.DebugFormat(
// "[SCENE PERMISSIONS]: CanTakeCopyObject() fired for object {0}, user {1}, result {2}", // "[SCENE PERMISSIONS]: CanTakeCopyObject() fired for object {0}, user {1}, result {2}",
// objectID, userID, result); // objectID, userID, result);
return true;
return result;
} }
#endregion #endregion
@ -558,8 +570,6 @@ namespace OpenSim.Region.Framework.Scenes
#region RETURN OBJECT #region RETURN OBJECT
public bool CanReturnObjects(ILandObject land, IClientAPI client, List<SceneObjectGroup> objects) public bool CanReturnObjects(ILandObject land, IClientAPI client, List<SceneObjectGroup> objects)
{ {
bool result = true;
ReturnObjectsHandler handler = OnReturnObjects; ReturnObjectsHandler handler = OnReturnObjects;
if (handler != null) if (handler != null)
{ {
@ -574,18 +584,14 @@ namespace OpenSim.Region.Framework.Scenes
foreach (ReturnObjectsHandler h in list) foreach (ReturnObjectsHandler h in list)
{ {
if (h(land, sp, objects) == false) if (h(land, sp, objects) == false)
{ return false;
result = false;
break;
} }
} }
}
// m_log.DebugFormat( // m_log.DebugFormat(
// "[SCENE PERMISSIONS]: CanReturnObjects() fired for user {0} for {1} objects on {2}, result {3}", // "[SCENE PERMISSIONS]: CanReturnObjects() fired for user {0} for {1} objects on {2}, result {3}",
// user, objects.Count, land.LandData.Name, result); // user, objects.Count, land.LandData.Name, result);
return result; return true;
} }
#endregion #endregion