Checkpoint commit on total revamp of Authority
This commit is contained in:
@@ -123,8 +123,10 @@ namespace Swarmops.Logic.DashboardTasks
|
||||
{
|
||||
TaskGroup group = new TaskGroup (TaskGroupType.ValidateExpenseClaims);
|
||||
|
||||
// TODO: Loop over roles, get all open claims for roles where person can attest
|
||||
throw new NotImplementedException(); // not moved to v5 framework (undecided whether it will happen)
|
||||
|
||||
// TODO: Loop over roles, get all open claims for roles where person can attest
|
||||
/*
|
||||
if (
|
||||
!person.GetAuthority()
|
||||
.HasPermission (Permission.CanDoEconomyTransactions, organization.Identity, Geography.RootIdentity,
|
||||
@@ -147,7 +149,7 @@ namespace Swarmops.Logic.DashboardTasks
|
||||
if (group.Tasks.Count > 0)
|
||||
{
|
||||
Add (group);
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
|
||||
@@ -183,6 +185,9 @@ namespace Swarmops.Logic.DashboardTasks
|
||||
TaskGroup groupUrgent = new TaskGroup (TaskGroupType.PayoutUrgently);
|
||||
TaskGroup groupOverdue = new TaskGroup (TaskGroupType.PayoutOverdue);
|
||||
|
||||
throw new NotImplementedException(); // not moved to v5 framework (undecided whether it will happen)
|
||||
|
||||
/*
|
||||
if (
|
||||
!person.GetAuthority()
|
||||
.HasPermission (Permission.CanPayOutMoney, organization.Identity, 1,
|
||||
@@ -223,12 +228,15 @@ namespace Swarmops.Logic.DashboardTasks
|
||||
if (groupOverdue.Tasks.Count > 0)
|
||||
{
|
||||
Add (groupOverdue);
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
|
||||
private void AddAttestationWarnings (Person person, Organization organization)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
|
||||
/*
|
||||
TaskGroup group = new TaskGroup (TaskGroupType.AttestationWarning);
|
||||
|
||||
if (
|
||||
@@ -254,7 +262,7 @@ namespace Swarmops.Logic.DashboardTasks
|
||||
if (group.Tasks.Count > 0)
|
||||
{
|
||||
Add (group);
|
||||
}
|
||||
}*/
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,48 +0,0 @@
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using Swarmops.Basic.Types;
|
||||
using Swarmops.Basic.Types.Security;
|
||||
using Swarmops.Basic.Types.Swarm;
|
||||
using Swarmops.Common.Enums;
|
||||
using Swarmops.Logic.Security;
|
||||
using Swarmops.Logic.Swarm;
|
||||
|
||||
namespace Swarmops.Logic.DataObjects
|
||||
{
|
||||
#if !__MonoCS__
|
||||
[DataObject (true)]
|
||||
#endif
|
||||
public class RolesDataObject
|
||||
{
|
||||
#if !__MonoCS__
|
||||
[DataObjectMethod (DataObjectMethodType.Select)]
|
||||
#endif
|
||||
public static BasicPersonRole[] Select (int personId, RoleClass roleClass)
|
||||
{
|
||||
BasicAuthority authority = Authorization.GetPersonAuthority (personId);
|
||||
|
||||
switch (roleClass)
|
||||
{
|
||||
case RoleClass.System:
|
||||
return authority.SystemPersonRoles;
|
||||
|
||||
case RoleClass.Organization:
|
||||
return authority.OrganizationPersonRoles;
|
||||
|
||||
case RoleClass.Local:
|
||||
return authority.LocalPersonRoles;
|
||||
|
||||
default:
|
||||
throw new InvalidOperationException ("Undefined RoleClass in RolesDataObject.Select: " + roleClass);
|
||||
}
|
||||
}
|
||||
|
||||
#if !__MonoCS__
|
||||
[DataObjectMethod (DataObjectMethodType.Select)]
|
||||
#endif
|
||||
public static BasicPersonRole[] Select (Person person, RoleClass roleClass)
|
||||
{
|
||||
return Select (person.Identity, roleClass);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -208,7 +208,6 @@
|
||||
<Compile Include="DataObjects\ExpensesDataObject.cs" />
|
||||
<Compile Include="DataObjects\MembershipsDataObject.cs" />
|
||||
<Compile Include="DataObjects\PeopleDataObject.cs" />
|
||||
<Compile Include="DataObjects\RolesDataObject.cs" />
|
||||
<Compile Include="Financial\FinancialValidation.cs" />
|
||||
<Compile Include="Financial\FinancialValidations.cs" />
|
||||
<Compile Include="Financial\IAttestable.cs" />
|
||||
|
||||
+121
-260
@@ -1,312 +1,173 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reflection.Emit;
|
||||
using System.Security.Cryptography;
|
||||
using System.Security.Permissions;
|
||||
using System.Text;
|
||||
using System.Xml.Serialization;
|
||||
using Swarmops.Basic.Types;
|
||||
using Swarmops.Basic.Types.Security;
|
||||
using Swarmops.Basic.Types.Swarm;
|
||||
using Swarmops.Common.Enums;
|
||||
using Swarmops.Logic.Structure;
|
||||
using Swarmops.Logic.Support;
|
||||
using Swarmops.Logic.Swarm;
|
||||
|
||||
namespace Swarmops.Logic.Security
|
||||
{
|
||||
public class Authority : BasicAuthority
|
||||
public class Authority
|
||||
{
|
||||
#region Construction and Creation
|
||||
|
||||
private Authority()
|
||||
: base (0, null, null, null)
|
||||
public static Authority FromXml (string xml)
|
||||
{
|
||||
return new Authority (AuthorityData.FromXml (xml));
|
||||
}
|
||||
|
||||
private Authority (BasicAuthority basic)
|
||||
: base (basic.PersonId, basic.SystemPersonRoles, basic.OrganizationPersonRoles, basic.LocalPersonRoles)
|
||||
public static Authority FromEncryptedXml (string cryptXml)
|
||||
{
|
||||
}
|
||||
byte[] keyBytes = Encoding.ASCII.GetBytes(SystemSettings.InstallationId.Replace("-", "")); // unique for this install
|
||||
byte[] cryptoBytes = Convert.FromBase64String(cryptXml);
|
||||
|
||||
|
||||
public static Authority FromBasic (BasicAuthority basic)
|
||||
{
|
||||
return new Authority (basic);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
public Organizations GetOrganizations (RoleType[] forRoles)
|
||||
{
|
||||
if (HasRoleType (RoleType.SystemAdmin))
|
||||
using (AesCryptoServiceProvider aes = new AesCryptoServiceProvider())
|
||||
{
|
||||
return Organizations.GetAll();
|
||||
aes.Key = keyBytes;
|
||||
aes.IV = new ArraySegment<byte> (cryptoBytes, 0, 16).ToArray();
|
||||
cryptoBytes = new ArraySegment<byte>(cryptoBytes, 16, cryptoBytes.Length - 16).ToArray();
|
||||
|
||||
using (ICryptoTransform crypto = aes.CreateDecryptor())
|
||||
{
|
||||
byte[] clearBytes = crypto.TransformFinalBlock(cryptoBytes, 0, cryptoBytes.Length);
|
||||
return FromXml(Encoding.UTF8.GetString (clearBytes));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public string ToXml()
|
||||
{
|
||||
return _data.ToXml();
|
||||
}
|
||||
|
||||
public string ToEncryptedXml()
|
||||
{
|
||||
byte[] keyBytes = Encoding.ASCII.GetBytes(SystemSettings.InstallationId.Replace ("-","")); // unique for this install
|
||||
byte[] dataBytes = Encoding.UTF8.GetBytes (ToXml());
|
||||
|
||||
using (AesCryptoServiceProvider aes = new AesCryptoServiceProvider())
|
||||
{
|
||||
aes.Key = keyBytes;
|
||||
aes.GenerateIV(); // unique for every encryption
|
||||
|
||||
if (aes.IV.Length != 16)
|
||||
{
|
||||
throw new InvalidDataException("IV is not 16 bytes long");
|
||||
}
|
||||
|
||||
using (ICryptoTransform crypto = aes.CreateEncryptor())
|
||||
{
|
||||
byte[] cryptoBytes = crypto.TransformFinalBlock (dataBytes, 0, dataBytes.Length);
|
||||
return Convert.ToBase64String (aes.IV.Concat (cryptoBytes).ToArray()); // joins two byte[] arrays
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private Authority (AuthorityData data)
|
||||
{
|
||||
this._data = data;
|
||||
}
|
||||
|
||||
public static Authority FromLogin (Person person)
|
||||
{
|
||||
int lastOrgId = person.LastLogonOrganizationId;
|
||||
PositionAssignment assignment = null;
|
||||
|
||||
if (lastOrgId != 0)
|
||||
{
|
||||
Organization organization = Organization.FromIdentity (lastOrgId);
|
||||
assignment = person.GetPrimaryAssignment (organization);
|
||||
}
|
||||
|
||||
List<int> orgIdentities = new List<int>();
|
||||
// TODO: Verify membership OR position OR volunteer
|
||||
|
||||
foreach (BasicPersonRole role in OrganizationPersonRoles)
|
||||
return new Authority (new AuthorityData
|
||||
{
|
||||
if (Array.IndexOf (forRoles, role.Type) >= 0)
|
||||
orgIdentities.Add (role.OrganizationId);
|
||||
}
|
||||
|
||||
foreach (BasicPersonRole role in LocalPersonRoles)
|
||||
{
|
||||
if (Array.IndexOf (forRoles, role.Type) >= 0)
|
||||
orgIdentities.Add (role.OrganizationId);
|
||||
}
|
||||
|
||||
return Organizations.FromIdentities (orgIdentities.ToArray());
|
||||
CustomData = new Basic.Types.Common.SerializableDictionary<string, string>(),
|
||||
LoginDateTimeUtc = DateTime.UtcNow,
|
||||
OrganizationId = lastOrgId,
|
||||
PersonId = person.Identity,
|
||||
PositionAssignmentId = (assignment != null ? assignment.Identity : 0)
|
||||
});
|
||||
}
|
||||
|
||||
private readonly AuthorityData _data;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public bool CanSeePerson (Person person)
|
||||
{
|
||||
People initialList = People.FromArray (new[] {person});
|
||||
People initialList = People.FromSingle (person);
|
||||
|
||||
People filteredList = Authorization.FilterPeopleToMatchAuthority (initialList, this);
|
||||
throw new NotImplementedException();
|
||||
|
||||
/*People filteredList = Authorization.FilterPeopleToMatchAuthority (initialList, this);
|
||||
|
||||
if (filteredList.Count == 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
return true;*/
|
||||
}
|
||||
|
||||
|
||||
public Geographies GetGeographiesForOrganization (Organization organization)
|
||||
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public class AuthorityData
|
||||
{
|
||||
public int PersonId { get; set; }
|
||||
public int OrganizationId { get; set; }
|
||||
public int PositionAssignmentId { get; set; }
|
||||
public DateTime LoginDateTimeUtc { get; set; }
|
||||
public Basic.Types.Common.SerializableDictionary<string,string> CustomData { get; set; }
|
||||
|
||||
internal string ToXml()
|
||||
{
|
||||
return
|
||||
GetGeographiesForOrganization (organization, RoleTypes.AllRoleTypes);
|
||||
XmlSerializer serializer = new XmlSerializer(GetType());
|
||||
|
||||
MemoryStream stream = new MemoryStream();
|
||||
serializer.Serialize(stream, this);
|
||||
|
||||
byte[] xmlBytes = stream.GetBuffer();
|
||||
return Encoding.UTF8.GetString(xmlBytes);
|
||||
}
|
||||
|
||||
public Geographies GetGeographiesForOrganization (Organization organization, RoleType[] roleTypes)
|
||||
static internal AuthorityData FromXml (string xml)
|
||||
{
|
||||
return
|
||||
Geographies.FromArray (Authorization.GetNodesInAuthorityForOrganization (this, organization.Identity,
|
||||
roleTypes));
|
||||
}
|
||||
// Compensate for stupid Mono encoding bugs
|
||||
|
||||
|
||||
public bool HasLocalRoleAtOrganizationGeography (Organization organization, Geography geography,
|
||||
Authorization.Flag flags)
|
||||
{
|
||||
return HasLocalRoleAtOrganizationGeography (organization, geography, RoleTypes.AllLocalRoleTypes, flags);
|
||||
}
|
||||
|
||||
|
||||
public bool HasLocalRoleAtOrganizationGeography (Organization organization, Geography geography,
|
||||
RoleType roleType, Authorization.Flag flags)
|
||||
{
|
||||
return HasLocalRoleAtOrganizationGeography (organization, geography,
|
||||
new[] {roleType}, flags);
|
||||
}
|
||||
|
||||
|
||||
public bool HasLocalRoleAtOrganizationGeography (Organization organization, Geography geography,
|
||||
RoleType[] roleTypes, Authorization.Flag flags)
|
||||
{
|
||||
if (organization != null && organization.Identity == Organization.SandboxIdentity)
|
||||
if (xml.StartsWith("?"))
|
||||
{
|
||||
return true; // UGLY UGLY HACK
|
||||
xml = xml.Substring(1);
|
||||
}
|
||||
|
||||
if (organization == null && (flags & Authorization.Flag.AnyOrganization) == 0)
|
||||
return false;
|
||||
xml = xml.Replace("�", "");
|
||||
xml = xml.Replace("\x00", "");
|
||||
|
||||
if (geography == null && (flags & Authorization.Flag.AnyGeography) == 0)
|
||||
return false;
|
||||
XmlSerializer serializer = new XmlSerializer(typeof(AuthorityData));
|
||||
|
||||
MemoryStream stream = new MemoryStream();
|
||||
byte[] xmlBytes = Encoding.UTF8.GetBytes(xml);
|
||||
stream.Write(xmlBytes, 0, xmlBytes.Length);
|
||||
|
||||
foreach (BasicPersonRole role in LocalPersonRoles)
|
||||
{
|
||||
foreach (RoleType type in roleTypes)
|
||||
{
|
||||
if (type == role.Type)
|
||||
{
|
||||
// Expensive op. The org/geo lookups need a cache at the logic layer.
|
||||
stream.Position = 0;
|
||||
AuthorityData result = (AuthorityData)serializer.Deserialize(stream);
|
||||
stream.Close();
|
||||
|
||||
bool organizationClear = false;
|
||||
bool geographyClear = false;
|
||||
|
||||
// First, check if the organization and geography match identically.
|
||||
|
||||
if ((flags & Authorization.Flag.AnyOrganization) != 0)
|
||||
{
|
||||
// then it is used to check if they have a local role for any org
|
||||
organizationClear = true;
|
||||
}
|
||||
else if (organization != null && organization.Identity == role.OrganizationId)
|
||||
{
|
||||
organizationClear = true;
|
||||
}
|
||||
|
||||
if ((flags & Authorization.Flag.AnyGeography) != 0)
|
||||
{
|
||||
// then it is used to check if they have a local role anywhere
|
||||
geographyClear = true;
|
||||
}
|
||||
else if (geography != null && geography.Identity == role.GeographyId)
|
||||
{
|
||||
geographyClear = true;
|
||||
}
|
||||
|
||||
|
||||
// If not clear, then check if there is inherited authority.
|
||||
|
||||
if (!organizationClear
|
||||
&& (flags & Authorization.Flag.ExactOrganization) == 0)
|
||||
{
|
||||
if (organization != null && organization.Inherits (role.OrganizationId))
|
||||
{
|
||||
organizationClear = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!geographyClear && (flags & Authorization.Flag.ExactGeography) == 0)
|
||||
{
|
||||
if (geography != null && geography.Inherits (role.GeographyId))
|
||||
{
|
||||
geographyClear = true;
|
||||
}
|
||||
}
|
||||
|
||||
// If both are ok, return that there is authority at this org & geo.
|
||||
|
||||
if (organizationClear && geographyClear)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool HasRoleAtOrganization (Organization organization, Authorization.Flag flags)
|
||||
{
|
||||
return HasRoleAtOrganization (organization, RoleTypes.AllOrganizationalRoleTypes, flags);
|
||||
}
|
||||
|
||||
public bool HasRoleAtOrganization (Organization organization, RoleType roleType, Authorization.Flag flags)
|
||||
{
|
||||
return HasRoleAtOrganization (organization, new[] {roleType}, flags);
|
||||
}
|
||||
|
||||
public bool HasRoleAtOrganization (Organization organization, RoleType[] roleTypes, Authorization.Flag flags)
|
||||
{
|
||||
if (organization == null)
|
||||
{
|
||||
if ((flags & Authorization.Flag.AnyOrganization) != 0)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (organization != null && organization.Identity == Organization.SandboxIdentity)
|
||||
{
|
||||
return true; // UGLY UGLY HACK
|
||||
}
|
||||
|
||||
foreach (BasicPersonRole role in OrganizationPersonRoles)
|
||||
{
|
||||
foreach (RoleType type in roleTypes)
|
||||
{
|
||||
if (type == role.Type)
|
||||
{
|
||||
if ((flags & Authorization.Flag.AnyOrganization) != 0)
|
||||
return true;
|
||||
|
||||
if (organization.Identity == role.OrganizationId)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if ((flags & Authorization.Flag.ExactOrganization) == 0)
|
||||
{
|
||||
if (organization.Inherits (role.OrganizationId))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
public bool HasRoleType (RoleType roleType)
|
||||
{
|
||||
return HasAnyRoleType (new[] {roleType});
|
||||
}
|
||||
|
||||
public bool HasAnyRoleType (RoleType[] roleTypes)
|
||||
{
|
||||
foreach (RoleType r in roleTypes)
|
||||
{
|
||||
foreach (BasicPersonRole r2 in LocalPersonRoles)
|
||||
if (r2.Type == r) return true;
|
||||
foreach (BasicPersonRole r2 in OrganizationPersonRoles)
|
||||
if (r2.Type == r) return true;
|
||||
foreach (BasicPersonRole r2 in SystemPersonRoles)
|
||||
if (r2.Type == r) return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool CanEditSystemRoles()
|
||||
{
|
||||
return HasPermission (Permission.CanEditSystemRoles, -1, -1,
|
||||
Authorization.Flag.ExactGeography | Authorization.Flag.ExactOrganization);
|
||||
}
|
||||
|
||||
public bool CanEditOrgRolesForOrg (int orgId)
|
||||
{
|
||||
return HasPermission (Permission.CanEditOrganisationalRoles, orgId, -1, Authorization.Flag.Default);
|
||||
}
|
||||
|
||||
|
||||
public bool HasAnyPermission (Permission perm)
|
||||
{
|
||||
return Authorization.CheckAuthorization (new PermissionSet (perm), -1, -1, this,
|
||||
Authorization.Flag.AnyGeographyAnyOrganization);
|
||||
}
|
||||
|
||||
/* -- unused, apparently
|
||||
private bool HasPermission (Permission perm, int organizationId, Authorization.Flag flags)
|
||||
{
|
||||
return Authorization.CheckAuthorization(new PermissionSet(perm), organizationId, Organization.RootIdentity, this, flags);
|
||||
} */
|
||||
|
||||
public bool HasPermission (Permission perm, int organizationId, int geographyId, Authorization.Flag flags)
|
||||
{
|
||||
return Authorization.CheckAuthorization (new PermissionSet (perm, organizationId, geographyId),
|
||||
organizationId,
|
||||
geographyId, this, flags);
|
||||
}
|
||||
|
||||
public bool HasPermission (PermissionSet perm, Authorization.Flag flags)
|
||||
{
|
||||
return Authorization.CheckAuthorization (perm, -1, -1, this, flags);
|
||||
}
|
||||
|
||||
public bool HasPermission (PermissionSet perm, int organizationId, int geographyId, Authorization.Flag flags)
|
||||
{
|
||||
return Authorization.CheckAuthorization (perm, organizationId, geographyId, this, flags);
|
||||
}
|
||||
|
||||
|
||||
public Organizations OrganisationsWithPermission (Permission perm, RoleType[] roles)
|
||||
{
|
||||
Organizations orgList = GetOrganizations (roles);
|
||||
Organizations retList = new Organizations();
|
||||
foreach (Organization org in orgList)
|
||||
{
|
||||
if (HasPermission (perm, org.Identity, -1, Authorization.Flag.Default))
|
||||
if (!retList.Contains (org))
|
||||
retList.Add (org);
|
||||
}
|
||||
return retList;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -14,6 +14,7 @@ namespace Swarmops.Logic.Security
|
||||
{
|
||||
public class Authorization
|
||||
{
|
||||
/*
|
||||
[Flags]
|
||||
public enum Flag
|
||||
{
|
||||
@@ -207,9 +208,12 @@ namespace Swarmops.Logic.Security
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
[Obsolete("Do not use calls with Ids")]
|
||||
public static Authority GetPersonAuthority (int personId)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
|
||||
|
||||
return
|
||||
Authority.FromBasic (SwarmDb.GetDatabaseForReading().GetPersonAuthority (Person.FromIdentity (personId)));
|
||||
}
|
||||
@@ -262,7 +266,7 @@ namespace Swarmops.Logic.Security
|
||||
return result.ToArray();
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
public static bool ViewerMayWatchPerson (int viewingPersonId, int watchedPersonId)
|
||||
{
|
||||
Authority authority = GetPersonAuthority(viewingPersonId);
|
||||
@@ -277,7 +281,7 @@ namespace Swarmops.Logic.Security
|
||||
}
|
||||
|
||||
return true;
|
||||
}*/
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
@@ -564,11 +568,11 @@ namespace Swarmops.Logic.Security
|
||||
}
|
||||
}
|
||||
}
|
||||
/* -- commented out. This means "does the current authority have Org Admin privileges over Person"?
|
||||
-- commented out. This means "does the current authority have Org Admin privileges over Person"?
|
||||
else if (CanSeeNonMembers)
|
||||
{ //person isn't member anywhere
|
||||
clearedPeople[person.Identity] = person;
|
||||
}*/
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -798,6 +802,6 @@ namespace Swarmops.Logic.Security
|
||||
|
||||
internal class FoundItException : Exception
|
||||
{
|
||||
}
|
||||
}*/
|
||||
}
|
||||
}
|
||||
@@ -183,64 +183,13 @@ namespace Swarmops.Logic.Swarm
|
||||
{
|
||||
if (base.Active)
|
||||
{
|
||||
//Added removal of Roles here to make SURE they always are removed with the membership.
|
||||
Authority authority = Person.GetAuthority();
|
||||
|
||||
int actingPersonId = actingPerson == null ? 0 : actingPerson.Identity;
|
||||
|
||||
BasicPersonRole[] roles = authority.AllPersonRoles;
|
||||
List<PersonRole> theRoles = new List<PersonRole>();
|
||||
|
||||
foreach (BasicPersonRole basicRole in roles)
|
||||
{
|
||||
PersonRole personRole = PersonRole.FromBasic (basicRole);
|
||||
theRoles.Add (personRole);
|
||||
if (personRole.OrganizationId == OrganizationId)
|
||||
{
|
||||
PWEvents.CreateEvent (eventSource, EventType.DeletedRole, actingPersonId,
|
||||
personRole.OrganizationId, personRole.GeographyId,
|
||||
Person.Identity, (int) personRole.Type,
|
||||
string.Empty);
|
||||
PWLog.Write (actingPersonId, PWLogItem.Person, Person.Identity, PWLogAction.RoleDeleted,
|
||||
"Role " + personRole.Type + " of " + personRole.Geography.Name +
|
||||
" was deleted with membership.", string.Empty);
|
||||
personRole.Delete();
|
||||
}
|
||||
}
|
||||
|
||||
//now check if this means that you no longer are a member of some uplevel org, then remove those roles as well
|
||||
foreach (PersonRole personRole in theRoles)
|
||||
{
|
||||
if (!Person.MemberOfWithInherited (personRole.Organization))
|
||||
{
|
||||
PWEvents.CreateEvent (eventSource, EventType.DeletedRole, actingPersonId,
|
||||
personRole.OrganizationId, personRole.GeographyId,
|
||||
Person.Identity, (int) personRole.Type,
|
||||
string.Empty);
|
||||
PWLog.Write (actingPersonId, PWLogItem.Person, Person.Identity, PWLogAction.RoleDeleted,
|
||||
"Role " + personRole.Type + " of " + personRole.Geography.Name +
|
||||
" was deleted with membership of all suborgs.", string.Empty);
|
||||
personRole.Delete();
|
||||
}
|
||||
}
|
||||
|
||||
EventSource src = EventSource.PirateWeb;
|
||||
try
|
||||
{
|
||||
if (HttpContext.Current == null)
|
||||
{
|
||||
src = EventSource.PirateBot;
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
src = EventSource.PirateBot;
|
||||
}
|
||||
// REMOVED: everything Roles related; being phased out
|
||||
|
||||
|
||||
PWLog.Write (actingPersonId, PWLogItem.Person, Person.Identity, PWLogAction.MemberLost,
|
||||
PWLog.Write (actingPerson.Identity, PWLogItem.Person, Person.Identity, PWLogAction.MemberLost,
|
||||
eventSource + ":" + description, string.Empty);
|
||||
PWEvents.CreateEvent (src, EventType.LostMember, actingPersonId, OrganizationId, Person.GeographyId,
|
||||
PWEvents.CreateEvent (EventSource.PirateWeb, EventType.LostMember, actingPerson.Identity, OrganizationId, Person.GeographyId,
|
||||
Person.Identity, 0, OrganizationId.ToString());
|
||||
|
||||
|
||||
|
||||
@@ -68,11 +68,11 @@ namespace Swarmops.Logic.Swarm
|
||||
|
||||
return GetMemberCountForOrganizations (idArray.ToArray());
|
||||
}
|
||||
|
||||
/*
|
||||
public Memberships RemoveToMatchAuthority (Geography personGeography, Authority authority)
|
||||
{
|
||||
return Authorization.FilterMembershipsToMatchAuthority (this, personGeography, authority);
|
||||
}
|
||||
}*/
|
||||
|
||||
public static Memberships ForOrganization (Organization organization, bool includeTerminated)
|
||||
{
|
||||
|
||||
+2
-11
@@ -413,16 +413,7 @@ namespace Swarmops.Logic.Swarm
|
||||
return People.FromArray (SwarmDb.GetDatabaseForReading().GetPeopleFromPhoneNumber (countryCode, phoneNumber));
|
||||
}
|
||||
|
||||
public People GetVisiblePeopleByAuthority (Authority authority)
|
||||
{
|
||||
return GetVisiblePeopleByAuthority (authority, 0);
|
||||
}
|
||||
|
||||
public People GetVisiblePeopleByAuthority (Authority authority, int gracePeriod)
|
||||
{
|
||||
return Authorization.FilterPeopleToMatchAuthority (this, authority, gracePeriod);
|
||||
}
|
||||
|
||||
/*
|
||||
public People GetVisiblePeople (Organization organization)
|
||||
{
|
||||
People result = new People();
|
||||
@@ -467,7 +458,7 @@ namespace Swarmops.Logic.Swarm
|
||||
BasicPerson[] arrayToFilter = ToArray();
|
||||
BasicPerson[] filtered = Authorization.FilterUnlistedPeople (arrayToFilter);
|
||||
return FromArray (filtered);
|
||||
}
|
||||
}*/
|
||||
|
||||
|
||||
/*
|
||||
|
||||
+15
-4
@@ -615,9 +615,9 @@ namespace Swarmops.Logic.Swarm
|
||||
// Note "for writing". Intentional. Queries master db and bypasses replication lag.
|
||||
}
|
||||
|
||||
public Authority GetAuthority()
|
||||
public Authority GetDefaultAuthority()
|
||||
{
|
||||
return Authorization.GetPersonAuthority (Identity);
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public Memberships GetMemberships (bool includeTerminated)
|
||||
@@ -1212,7 +1212,7 @@ namespace Swarmops.Logic.Swarm
|
||||
return false;
|
||||
}
|
||||
|
||||
public Position GetPrimaryPosition (Organization organization)
|
||||
public PositionAssignment GetPrimaryAssignment (Organization organization)
|
||||
{
|
||||
PositionAssignments personAssignments = PositionAssignments.ForPerson (this);
|
||||
|
||||
@@ -1221,7 +1221,7 @@ namespace Swarmops.Logic.Swarm
|
||||
if (assignment.OrganizationId == 0 || assignment.OrganizationId == organization.Identity)
|
||||
{
|
||||
// TODO: If "acting" is false, and no delegation, then...
|
||||
return assignment.Position;
|
||||
return assignment;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1230,6 +1230,17 @@ namespace Swarmops.Logic.Swarm
|
||||
return null;
|
||||
}
|
||||
|
||||
public Position GetPrimaryPosition (Organization organization)
|
||||
{
|
||||
PositionAssignment assignment = GetPrimaryAssignment (organization);
|
||||
if (assignment == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return assignment.Position;
|
||||
}
|
||||
|
||||
// A couple of special cases
|
||||
|
||||
public const int OpenLedgersIdentity = -1;
|
||||
|
||||
@@ -13,6 +13,10 @@ namespace Swarmops.Logic.Swarm
|
||||
{
|
||||
public static Roles FromArray (BasicPersonRole[] basicArray)
|
||||
{
|
||||
// This should never run anymore, so throw.
|
||||
|
||||
throw new NotImplementedException();
|
||||
|
||||
Roles result = new Roles();
|
||||
|
||||
result.Capacity = basicArray.Length*11/10;
|
||||
@@ -33,8 +37,11 @@ namespace Swarmops.Logic.Swarm
|
||||
/// <returns>A list of person Ids that hold roles above this point.</returns>
|
||||
public static int[] GetAllUpwardRoles (int organizationId, int geographyId)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
|
||||
/*
|
||||
return GetAllUpwardRoles (organizationId, geographyId,
|
||||
Authorization.RoleTypesWithPermission (Permission.CanSeePeople));
|
||||
Authorization.RoleTypesWithPermission (Permission.CanSeePeople));*/
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -34,6 +34,8 @@ public class ControlV5Base : UserControl
|
||||
|
||||
protected override void OnLoad (EventArgs e)
|
||||
{
|
||||
throw new NotImplementedException(); // this MUST be replaced with CommonV5 function
|
||||
|
||||
int currentUserId = 0;
|
||||
int currentOrganizationId = 0;
|
||||
|
||||
@@ -46,7 +48,7 @@ public class ControlV5Base : UserControl
|
||||
currentUserId = Convert.ToInt32 (userIdentityString);
|
||||
currentOrganizationId = Convert.ToInt32 (organizationIdentityString);
|
||||
this._currentUser = Person.FromIdentity (currentUserId);
|
||||
this._authority = this._currentUser.GetAuthority();
|
||||
//this._authority = this._currentUser.GetAuthority();
|
||||
try
|
||||
{
|
||||
this._currentOrganization = Organization.FromIdentity (currentOrganizationId);
|
||||
|
||||
@@ -29,6 +29,9 @@ public class DataV5Base : Page
|
||||
|
||||
if (!string.IsNullOrEmpty (identity))
|
||||
{
|
||||
// this MUST be replaced with CommonV5 function
|
||||
throw new NotImplementedException();
|
||||
|
||||
string[] identityTokens = identity.Split (',');
|
||||
|
||||
string userIdentityString = identityTokens[0];
|
||||
|
||||
@@ -15,7 +15,8 @@ namespace Swarmops.Frontend.Automation
|
||||
|
||||
People matches = People.FromNamePattern (pattern);
|
||||
|
||||
matches = Authorization.FilterPeopleToMatchAuthority (matches, CurrentUser.GetAuthority());
|
||||
throw new NotImplementedException(); // Needs security check here
|
||||
// matches = Authorization.FilterPeopleToMatchAuthority (matches, CurrentUser.GetAuthority());
|
||||
|
||||
if (matches == null)
|
||||
{
|
||||
|
||||
@@ -132,7 +132,10 @@ namespace Swarmops.Frontend.Automation
|
||||
AuthenticationData authData = GetAuthenticationDataAndCulture();
|
||||
|
||||
People matches = People.FromSingle(Person.FromIdentity(personId));
|
||||
matches = Authorization.FilterPeopleToMatchAuthority(matches, authData.CurrentUser.GetAuthority()); // TODO: Change to Access
|
||||
|
||||
// CHange to new functions
|
||||
throw new NotImplementedException();
|
||||
// matches = Authorization.FilterPeopleToMatchAuthority(matches, authData.CurrentUser.GetAuthority()); // TODO: Change to Access
|
||||
|
||||
if (matches.Count != 1)
|
||||
{
|
||||
|
||||
@@ -25,6 +25,9 @@ namespace Swarmops
|
||||
// Security stuff
|
||||
// Current authentication
|
||||
|
||||
// this MUST be replaced with CommonV5 function
|
||||
throw new NotImplementedException();
|
||||
|
||||
string identity = HttpContext.Current.User.Identity.Name;
|
||||
string[] identityTokens = identity.Split (',');
|
||||
|
||||
@@ -35,7 +38,7 @@ namespace Swarmops
|
||||
int currentOrganizationId = Convert.ToInt32 (organizationIdentityString);
|
||||
|
||||
_currentUser = Person.FromIdentity (currentUserId);
|
||||
_authority = _currentUser.GetAuthority();
|
||||
//_authority = _currentUser.GetAuthority();
|
||||
try
|
||||
{
|
||||
_currentOrganization = Organization.FromIdentity (currentOrganizationId);
|
||||
@@ -128,27 +131,8 @@ namespace Swarmops
|
||||
|
||||
// Set up main menu
|
||||
|
||||
// RadMenu mainMenu = FindControl("MainMenu") as RadMenu;
|
||||
|
||||
Dictionary<string, bool> enableCache = new Dictionary<string, bool>();
|
||||
|
||||
if (Session["MainMenu-v4_Enabling"] != null
|
||||
&& PermissionCacheTimestamp.AddSeconds (10) > DateTime.Now
|
||||
&& Authorization.lastReload < PermissionCacheTimestamp)
|
||||
{
|
||||
enableCache = Session["MainMenu-v4_Enabling"] as Dictionary<string, bool>;
|
||||
}
|
||||
else
|
||||
{
|
||||
PermissionCacheTimestamp = DateTime.Now;
|
||||
}
|
||||
|
||||
SetupMenuItems();
|
||||
|
||||
Authorization.flagReload = false;
|
||||
// SetupMenuItemsEnabling(authority, enableCache, menuItems);
|
||||
Session["MainMenu-v4_Enabling"] = enableCache;
|
||||
|
||||
this.ImageCultureIndicator.Style[HtmlTextWriterStyle.MarginTop] = "-3px";
|
||||
this.ImageCultureIndicator.Style[HtmlTextWriterStyle.MarginRight] = "3px";
|
||||
this.ImageCultureIndicator.Style[HtmlTextWriterStyle.Cursor] = "pointer";
|
||||
|
||||
@@ -39,6 +39,11 @@ namespace Swarmops.Frontend.Pages.v5.Security
|
||||
throw new UnauthorizedAccessException();
|
||||
}
|
||||
|
||||
// this MUST be replaced with CommonV5 function
|
||||
throw new NotImplementedException();
|
||||
|
||||
|
||||
|
||||
string logonFlags = string.Empty;
|
||||
string[] currentIdentityParts = HttpContext.Current.User.Identity.Name.Split (',');
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@ using System.Web.Security;
|
||||
using System.Web.Services;
|
||||
using System.Web.UI;
|
||||
using NBitcoin;
|
||||
using NBitcoin.BouncyCastle.Crypto.Generators;
|
||||
using Resources;
|
||||
using Swarmops.Database;
|
||||
using Swarmops.Interface.Support;
|
||||
|
||||
@@ -217,22 +217,8 @@ namespace Swarmops.Utility.BotCode
|
||||
|
||||
Person person = membership.Person;
|
||||
|
||||
// Remove all roles and responsibilities for this person in the org
|
||||
// TODO: Check for positions that expire with membership
|
||||
|
||||
Authority authority = person.GetAuthority();
|
||||
|
||||
foreach (BasicPersonRole basicRole in authority.LocalPersonRoles)
|
||||
{
|
||||
PersonRole personRole = PersonRole.FromBasic (basicRole);
|
||||
if (personRole.OrganizationId == membership.OrganizationId)
|
||||
{
|
||||
PWEvents.CreateEvent (EventSource.PirateBot, EventType.DeletedRole, person.Identity,
|
||||
personRole.OrganizationId, personRole.GeographyId, person.Identity,
|
||||
(int) personRole.Type,
|
||||
string.Empty);
|
||||
personRole.Delete();
|
||||
}
|
||||
}
|
||||
|
||||
// Mail
|
||||
|
||||
|
||||
Reference in New Issue
Block a user