Premissions now inherit from groups listed anywhere in the db, not just below them.
TSDEV-39
This commit is contained in:
parent
a8e55d44e6
commit
7f2ff7614f
1 changed files with 30 additions and 14 deletions
|
|
@ -45,6 +45,16 @@ namespace TShockAPI
|
||||||
return true;
|
return true;
|
||||||
if (Parent != null)
|
if (Parent != null)
|
||||||
return Parent.HasPermission(permission);
|
return Parent.HasPermission(permission);
|
||||||
|
bool ret = false;
|
||||||
|
foreach( string g in permissions )
|
||||||
|
{
|
||||||
|
if (TShock.Groups.GroupExists(g))
|
||||||
|
{
|
||||||
|
ret = checkGroupForPermission(g, permission);
|
||||||
|
if (ret)
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -55,27 +65,33 @@ namespace TShockAPI
|
||||||
|
|
||||||
public void AddPermission(string permission)
|
public void AddPermission(string permission)
|
||||||
{
|
{
|
||||||
recursePermissions(permission, new List<String>());
|
permissions.Add(permission);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void recursePermissions( string permission, List<String> used){
|
private bool checkGroupForPermission(String g, String permission )
|
||||||
if (used.Contains(permission))
|
|
||||||
{
|
{
|
||||||
return;
|
bool ret = false;
|
||||||
}
|
if( !TShock.Groups.GroupExists( g ) )
|
||||||
else if( TShock.Groups.GroupExists( permission ) )
|
|
||||||
{
|
{
|
||||||
used.Add(permission);
|
if( g.Equals(permission) )
|
||||||
Group g = Tools.GetGroup(permission);
|
return true;
|
||||||
foreach (string perm in g.permissions)
|
|
||||||
{
|
|
||||||
recursePermissions(perm, used);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
permissions.Add(permission);
|
Group group = Tools.GetGroup(g);
|
||||||
|
foreach (String perm in group.permissions)
|
||||||
|
{
|
||||||
|
if( perm.Equals( permission ) )
|
||||||
|
{
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
ret = checkGroupForPermission( perm, permission );
|
||||||
|
|
||||||
|
if( ret )
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue