TONS AND TONS of work on Positions - good stuff!
This commit is contained in:
@@ -7,28 +7,35 @@ using Swarmops.Common.Interfaces;
|
||||
|
||||
namespace Swarmops.Basic.Types.Swarm
|
||||
{
|
||||
public class BasicPosition: IHasIdentity
|
||||
public class BasicPosition: IHasIdentity, IHasParentIdentity
|
||||
{
|
||||
public BasicPosition(int positionId, int organizationId, PositionLevel positionLevel, string positionTypeName, string positionTitleName,
|
||||
int geographyId, bool overridable, int overridesHigherPositionId, int createdByPersonId, DateTime createdDateTimeUtc,
|
||||
bool inheritsDownward, bool volunteerable, bool active, bool covert, int reportsToPositionId,
|
||||
int dotReportsToPositionId, int minCount, int maxCount)
|
||||
public BasicPosition(
|
||||
int positionId, PositionLevel positionLevel, int organizationId, int geographyId, int overridesHigherPositionId,
|
||||
int createdByPersonId, int createdByPositionId, DateTime createdDateTimeUtc, string positionTypeName, string positionTitleName,
|
||||
bool inheritsDownward, bool active, bool volunteerable, bool overridable, bool covert,
|
||||
int reportsToPositionId, int dotReportsToPositionId, int minCount, int maxCount)
|
||||
{
|
||||
// Mind the order, for maintainability and risk reduction. Same order everywhere -
|
||||
// here and in database and in Swarmops.Database, in groups of five.
|
||||
|
||||
this.PositionId = positionId;
|
||||
this.OrganizationId = organizationId;
|
||||
this.PositionLevel = positionLevel;
|
||||
this.PositionTypeName = positionTypeName;
|
||||
this.PositionTitleName = positionTitleName;
|
||||
this.OrganizationId = organizationId;
|
||||
this.GeographyId = geographyId;
|
||||
this.Overridable = overridable;
|
||||
this.OverridesHigherPositionId = overridesHigherPositionId;
|
||||
|
||||
this.CreatedByPersonId = createdByPersonId;
|
||||
this.CreatedByPositionId = createdByPositionId;
|
||||
this.CreatedDateTimeUtc = createdDateTimeUtc;
|
||||
this.PositionTypeName = positionTypeName;
|
||||
this.PositionTitleName = positionTitleName;
|
||||
|
||||
this.InheritsDownward = inheritsDownward;
|
||||
this.Volunteerable = volunteerable;
|
||||
this.Active = active;
|
||||
this.Volunteerable = volunteerable;
|
||||
this.Overridable = overridable;
|
||||
this.Covert = covert;
|
||||
|
||||
this.ReportsToPositionId = reportsToPositionId;
|
||||
this.DotReportsToPositionId = dotReportsToPositionId;
|
||||
this.MinCount = minCount;
|
||||
@@ -37,37 +44,39 @@ namespace Swarmops.Basic.Types.Swarm
|
||||
|
||||
public BasicPosition (BasicPosition original)
|
||||
: this (
|
||||
original.PositionId, original.OrganizationId, original.PositionLevel, original.PositionTypeName, original.PositionTitleName,
|
||||
original.GeographyId, original.Overridable, original.OverridesHigherPositionId, original.CreatedByPersonId, original.CreatedDateTimeUtc,
|
||||
original.InheritsDownward, original.Volunteerable, original.Active,
|
||||
original.Covert, original.ReportsToPositionId, original.DotReportsToPositionId, original.MinCount,
|
||||
original.MaxCount)
|
||||
original.PositionId, original.PositionLevel, original.OrganizationId, original.GeographyId, original.OverridesHigherPositionId,
|
||||
original.CreatedByPersonId, original.CreatedByPositionId, original.CreatedDateTimeUtc, original.PositionTypeName, original.PositionTitleName,
|
||||
original.InheritsDownward, original.Active, original.Volunteerable, original.Overridable, original.Covert,
|
||||
original.ReportsToPositionId, original.DotReportsToPositionId, original.MinCount, original.MaxCount)
|
||||
{
|
||||
// copy ctor
|
||||
}
|
||||
|
||||
public int PositionId { get; private set; }
|
||||
public PositionLevel PositionLevel { get; private set; }
|
||||
public string PositionTypeName { get; private set; }
|
||||
public string PositionTitleName { get; private set; } // strings not enums; plugins may extend from stock enum
|
||||
public int OrganizationId { get; private set; }
|
||||
public int GeographyId { get; private set; }
|
||||
public bool Overridable { get; protected set; }
|
||||
public int OverridesHigherPositionId { get; protected set; }
|
||||
|
||||
public int CreatedByPersonId { get; private set; }
|
||||
public int CreatedByPositionId { get; private set; }
|
||||
public DateTime CreatedDateTimeUtc { get; private set; }
|
||||
public string PositionTypeName { get; private set; }
|
||||
public string PositionTitleName { get; private set; } // strings not enums; plugins may extend from stock enum
|
||||
|
||||
public bool InheritsDownward { get; protected set; }
|
||||
public bool Volunteerable { get; protected set; }
|
||||
public bool Active { get; protected set; }
|
||||
public bool Volunteerable { get; protected set; }
|
||||
public bool Overridable { get; protected set; }
|
||||
public bool Covert { get; protected set; }
|
||||
|
||||
public int ReportsToPositionId { get; protected set; }
|
||||
public int DotReportsToPositionId { get; protected set; }
|
||||
public int MinCount { get; protected set; }
|
||||
public int MaxCount { get; protected set; }
|
||||
|
||||
public int Identity
|
||||
{
|
||||
get { return this.PositionId; }
|
||||
}
|
||||
|
||||
public int Identity { get { return this.PositionId; } }
|
||||
public int ParentIdentity { get { return this.ReportsToPositionId; } }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,10 +2,11 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Swarmops.Common.Interfaces;
|
||||
|
||||
namespace Swarmops.Basic.Types.Swarm
|
||||
{
|
||||
public class BasicPositionAssignment
|
||||
public class BasicPositionAssignment: IHasIdentity
|
||||
{
|
||||
public BasicPositionAssignment (int positionAssignmentId, int organizationId, int geographyId, int positionId, int personId,
|
||||
DateTime createdDateTimeUtc, int createdByPersonId, int createdByPositionId, bool active, DateTime expiresDateTimeUtc,
|
||||
@@ -53,5 +54,7 @@ namespace Swarmops.Basic.Types.Swarm
|
||||
public int TerminatedByPositionId { get; protected set; }
|
||||
public string AssignmentNotes { get; private set; }
|
||||
public string TerminationNotes { get; protected set; }
|
||||
|
||||
public int Identity { get { return this.PositionAssignmentId; } }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
using System;
|
||||
|
||||
namespace Swarmops.Common.Attributes
|
||||
{
|
||||
/// <summary>
|
||||
/// DbRecordType is used to mark a class what its database record is named
|
||||
/// Needed if a Logic entity is using Database-condition and have to work with a subclass
|
||||
/// i.e. [DbRecordType("Person")] on class Person
|
||||
/// </summary>
|
||||
[AttributeUsage (AttributeTargets.All)]
|
||||
public class DbEnumField : Attribute
|
||||
{
|
||||
public DbEnumField (string fieldName)
|
||||
{
|
||||
this.FieldName = fieldName;
|
||||
}
|
||||
|
||||
public string FieldName { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -1,26 +1,26 @@
|
||||
using System;
|
||||
|
||||
namespace Swarmops.Database.Attributes
|
||||
{
|
||||
/// <summary>
|
||||
/// DbRecordType is used to mark a class what its database record is named
|
||||
/// Needed if a Logic entity is using Database-condition and have to work with a subclass
|
||||
/// i.e. [DbRecordType("Person")] on class Person
|
||||
/// </summary>
|
||||
[AttributeUsage (AttributeTargets.All)]
|
||||
public class DbRecordType : Attribute
|
||||
{
|
||||
private string typeName = "";
|
||||
|
||||
public DbRecordType (string recordname)
|
||||
{
|
||||
this.typeName = recordname;
|
||||
}
|
||||
|
||||
public string TypeName
|
||||
{
|
||||
get { return this.typeName; }
|
||||
set { this.typeName = value; }
|
||||
}
|
||||
}
|
||||
using System;
|
||||
|
||||
namespace Swarmops.Common.Attributes
|
||||
{
|
||||
/// <summary>
|
||||
/// DbRecordType is used to mark a class what its database record is named
|
||||
/// Needed if a Logic entity is using Database-condition and have to work with a subclass
|
||||
/// i.e. [DbRecordType("Person")] on class Person
|
||||
/// </summary>
|
||||
[AttributeUsage (AttributeTargets.All)]
|
||||
public class DbRecordType : Attribute
|
||||
{
|
||||
private string typeName = "";
|
||||
|
||||
public DbRecordType (string recordname)
|
||||
{
|
||||
this.typeName = recordname;
|
||||
}
|
||||
|
||||
public string TypeName
|
||||
{
|
||||
get { return this.typeName; }
|
||||
set { this.typeName = value; }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -39,6 +39,8 @@
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Attributes\DbEnumField.cs" />
|
||||
<Compile Include="Attributes\DbRecordType.cs" />
|
||||
<Compile Include="Enums\AddressValidationResult.cs" />
|
||||
<Compile Include="Enums\AutoMailType.cs" />
|
||||
<Compile Include="Enums\CommunicationType.cs" />
|
||||
@@ -63,12 +65,16 @@
|
||||
<Compile Include="Enums\PersonOptionalDataKey.cs" />
|
||||
<Compile Include="Enums\PoliticalAffiliation.cs" />
|
||||
<Compile Include="Enums\PositionLevel.cs" />
|
||||
<Compile Include="Enums\PositionTitle.cs" />
|
||||
<Compile Include="Enums\PositionType.cs" />
|
||||
<Compile Include="Enums\RoleTypeClass.cs" />
|
||||
<Compile Include="Generics\Tree.cs" />
|
||||
<Compile Include="Interfaces\IEmailPerson.cs" />
|
||||
<Compile Include="Interfaces\IHandleProvider.cs" />
|
||||
<Compile Include="Interfaces\IHasIdentities.cs" />
|
||||
<Compile Include="Interfaces\IHasIdentity.cs" />
|
||||
<Compile Include="Interfaces\IHasSingularPluralTypes.cs" />
|
||||
<Compile Include="Interfaces\IHasParentIdentity.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
|
||||
@@ -3,21 +3,27 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Swarmops.Common.Attributes;
|
||||
|
||||
namespace Swarmops.Common.Enums
|
||||
{
|
||||
// The int values are how these values get stored in the database as an int field. Therefore, do not modify the ints under any circumstance -
|
||||
// you'll change what is persisted to databases.
|
||||
|
||||
[DbEnumField("PositionLevel")]
|
||||
public enum PositionLevel
|
||||
{
|
||||
Unknown = 0,
|
||||
System = 10,
|
||||
OrganizationDefault = 20,
|
||||
Organization = 30,
|
||||
Systemwide = 10,
|
||||
OrganizationwideDefault = 20,
|
||||
Organizationwide = 30,
|
||||
OrganizationTop = 40,
|
||||
SuborganizationDefault = 50,
|
||||
GeographyDefault = 60,
|
||||
Geography = 70
|
||||
GeographyDefault = 50,
|
||||
SuborganizationwideDefault = 60,
|
||||
SuborganizationTopDefault = 70,
|
||||
SuborganizationGeographyDefault = 80,
|
||||
Geography = 90
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Swarmops.Common.Enums
|
||||
{
|
||||
public enum PositionTitle
|
||||
{
|
||||
Unknown = 0,
|
||||
|
||||
/// <summary>
|
||||
/// Use the default title for the position type.
|
||||
/// </summary>
|
||||
Default
|
||||
|
||||
// Expand with various title names
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Swarmops.Common.Interfaces;
|
||||
|
||||
namespace Swarmops.Common.Generics
|
||||
{
|
||||
public class Tree<TNode>
|
||||
where TNode: IHasIdentity, IHasParentIdentity
|
||||
{
|
||||
public Tree()
|
||||
{
|
||||
RootNodes = new List<TreeNode<TNode>>();
|
||||
this._nodeLookup = new Dictionary<int, TreeNode<TNode>>();
|
||||
}
|
||||
|
||||
public List<TreeNode<TNode>> RootNodes { get; private set; }
|
||||
private readonly Dictionary<int, TreeNode<TNode>> _nodeLookup;
|
||||
|
||||
public TNode this [int identity]
|
||||
{
|
||||
get { return this._nodeLookup[identity].Data; }
|
||||
}
|
||||
|
||||
public static Tree<TNode> FromCollection (List<TNode> collection)
|
||||
{
|
||||
Dictionary<int, List<TreeNode<TNode>>> parentLookup = new Dictionary<int, List<TreeNode<TNode>>>();
|
||||
Tree<TNode> result = new Tree<TNode>();
|
||||
|
||||
// To construct a tree from a random collection, start by keying all parent identities into a dictionary
|
||||
|
||||
foreach (TNode item in collection)
|
||||
{
|
||||
TreeNode<TNode> node = new TreeNode<TNode>(item);
|
||||
|
||||
if (!parentLookup.ContainsKey ((item.ParentIdentity)))
|
||||
{
|
||||
parentLookup[item.ParentIdentity] = new List<TreeNode<TNode>>();
|
||||
}
|
||||
parentLookup[item.ParentIdentity].Add (node);
|
||||
result._nodeLookup[item.Identity] = node;
|
||||
}
|
||||
|
||||
// Then, recurse into that dictionary, starting at parentId zero which becomes the root level
|
||||
|
||||
result.RootNodes = ConstructRecurse (null, parentLookup);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private static List<TreeNode<TNode>> ConstructRecurse (TreeNode<TNode> parent, Dictionary<int, List<TreeNode<TNode>>> parentLookup)
|
||||
{
|
||||
List<TreeNode<TNode>> result = new List<TreeNode<TNode>>();
|
||||
int nodeId = parent == null ? 0 : parent.Data.Identity;
|
||||
|
||||
if (!parentLookup.ContainsKey (nodeId))
|
||||
{
|
||||
return result; // no nodes with requested parent - exit condition hit, return empty list
|
||||
}
|
||||
|
||||
foreach (TreeNode<TNode> node in parentLookup[nodeId])
|
||||
{
|
||||
node.Parent = parent;
|
||||
node.Children = ConstructRecurse (node, parentLookup);
|
||||
result.Add (node);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
public class TreeNode<TNode>
|
||||
where TNode: IHasIdentity, IHasParentIdentity
|
||||
{
|
||||
public TreeNode()
|
||||
{
|
||||
Children = new List<TreeNode<TNode>>();
|
||||
}
|
||||
|
||||
public TreeNode (TNode data)
|
||||
{
|
||||
Data = data;
|
||||
}
|
||||
|
||||
public TNode Data;
|
||||
public List<TreeNode<TNode>> Children;
|
||||
public TreeNode<TNode> Parent;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Swarmops.Common.Interfaces
|
||||
{
|
||||
public interface IHasParentIdentity
|
||||
{
|
||||
int ParentIdentity { get; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Swarmops.Common.Interfaces
|
||||
{
|
||||
public interface IHasSingularPluralTypes
|
||||
{
|
||||
Type SingularType { get; }
|
||||
Type PluralType { get; }
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,9 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Swarmops.Common.Attributes;
|
||||
using Swarmops.Common.Enums;
|
||||
using Swarmops.Common.Interfaces;
|
||||
using Swarmops.Database.Attributes;
|
||||
|
||||
namespace Swarmops.Database
|
||||
{
|
||||
@@ -41,7 +43,7 @@ namespace Swarmops.Database
|
||||
|
||||
foreach (object condition in conditionParameters)
|
||||
{
|
||||
if (condition is IHasIdentities)
|
||||
if (condition is IHasIdentities && condition is IHasSingularPluralTypes)
|
||||
{
|
||||
result.Add (GetWhereClauseForObjectList (condition as IHasIdentities));
|
||||
}
|
||||
@@ -62,13 +64,21 @@ namespace Swarmops.Database
|
||||
}
|
||||
else if (condition is object[]) // params object inherited and added to -- recurse
|
||||
{
|
||||
List<string> recursed = ConstructWhereClauseRecurse (tableName, condition);
|
||||
// We're being passed an array as one of the arguments. This is a bit odd but we can handle that too.
|
||||
|
||||
// copy one by one
|
||||
|
||||
foreach (string recursedCondition in recursed)
|
||||
foreach (object partialCondition in (object[]) condition)
|
||||
{
|
||||
result.Add (recursedCondition);
|
||||
result = result.Concat (ConstructWhereClauseRecurse (tableName, partialCondition)).ToList();
|
||||
}
|
||||
}
|
||||
else // iterate through attributes to find final hope of clue
|
||||
{
|
||||
foreach (object attribute in condition.GetType().GetCustomAttributes (typeof (DbEnumField), true))
|
||||
{
|
||||
if (attribute is DbEnumField)
|
||||
{
|
||||
result.Add (tableName + "." + ((DbEnumField) attribute).FieldName + "=" + (int) condition);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -120,30 +130,35 @@ namespace Swarmops.Database
|
||||
identities = new int[1] {0};
|
||||
}
|
||||
|
||||
return " " + GetForeignTypeString (((List<IHasIdentity>) foreignObjects)[0]) + "Id IN (" +
|
||||
if (!(foreignObjects is IHasSingularPluralTypes))
|
||||
{
|
||||
throw new ArgumentException("IHasIdentities object passed with missing IHasSingularPluralTypes interface");
|
||||
}
|
||||
|
||||
return " " + GetForeignTypeString (((IHasSingularPluralTypes) foreignObjects).SingularType) + "Id IN (" +
|
||||
JoinIds (identities) + ") ";
|
||||
}
|
||||
|
||||
|
||||
private static string GetForeignTypeString (IHasIdentity foreignObject)
|
||||
{
|
||||
string typeString = "";
|
||||
foreach (object attribute in foreignObject.GetType().GetCustomAttributes (typeof (DbRecordType), true))
|
||||
return GetForeignTypeString (foreignObject.GetType());
|
||||
}
|
||||
|
||||
|
||||
private static string GetForeignTypeString (Type foreignObjectType)
|
||||
{
|
||||
string typeString = string.Empty;
|
||||
foreach (object attribute in foreignObjectType.GetCustomAttributes (typeof (DbRecordType), true))
|
||||
{
|
||||
if (attribute is DbRecordType)
|
||||
{
|
||||
typeString = ((DbRecordType) attribute).TypeName;
|
||||
}
|
||||
}
|
||||
if (typeString == "")
|
||||
if (string.IsNullOrEmpty(typeString))
|
||||
{
|
||||
typeString = foreignObject.GetType().ToString();
|
||||
|
||||
if (typeString.Contains ("."))
|
||||
{
|
||||
int periodIndex = typeString.LastIndexOf ('.');
|
||||
typeString = typeString.Substring (periodIndex + 1);
|
||||
}
|
||||
typeString = foreignObjectType.Name;
|
||||
}
|
||||
|
||||
return typeString;
|
||||
|
||||
+114
-198
@@ -1,55 +1,36 @@
|
||||
/*
|
||||
|
||||
*
|
||||
* Created in DbUpdate 0012.
|
||||
* Created in DbUpdate 0012. Updated in Db0013-Db0015.
|
||||
*
|
||||
|
||||
CREATE TABLE `PositionsStandard` (
|
||||
`StandardPositionId` int(11) NOT NULL AUTO_INCREMENT,
|
||||
`OrganizationId` int(11) NOT NULL,
|
||||
CREATE TABLE `Positions` (
|
||||
`PositionId` int(11) NOT NULL AUTO_INCREMENT,
|
||||
`PositionLevel` int(11) NOT NULL,
|
||||
`PositionTypeId` int(11) NOT NULL,
|
||||
`Active` tinyint(4) NOT NULL DEFAULT '1',
|
||||
`Volunteerable` tinyint(4) NOT NULL,
|
||||
`Overridable` tinyint(4) NOT NULL,
|
||||
`Covert` tinyint(4) NOT NULL DEFAULT '0',
|
||||
`ReportsToStandardPositionId` int(11) NOT NULL,
|
||||
`DotReportsToStandardPositionId` int(11) NOT NULL,
|
||||
`MinCount` int(11) NOT NULL,
|
||||
`MaxCount` int(11) NOT NULL,
|
||||
PRIMARY KEY (`StandardPositionId`),
|
||||
KEY `Index_Org` (`OrganizationId`),
|
||||
KEY `Index_Level` (`PositionLevel`),
|
||||
KEY `Index_Type` (`PositionTypeId`),
|
||||
KEY `Index_Reports1` (`ReportsToStandardPositionId`),
|
||||
KEY `Index_Reports2` (`DotReportsToStandardPositionId`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
|
||||
|
||||
|
||||
CREATE TABLE `PositionsAdditional` (
|
||||
`AdditionalPositionId` int(11) NOT NULL AUTO_INCREMENT,
|
||||
`OrganizationId` int(11) NOT NULL,
|
||||
`GeographyId` int(11) NOT NULL,
|
||||
`OverridesHigherPositionId` int(11) NOT NULL,
|
||||
`CreatedByPersonId` int(11) NOT NULL,
|
||||
`CreatedByPositionId` int(11) NOT NULL,
|
||||
`CreatedDateTimeUtc` datetime NOT NULL,
|
||||
`PositionTypeId` int(11) NOT NULL,
|
||||
`PositionTitleId` int(11) NOT NULL,
|
||||
`InheritsDownward` tinyint(4) NOT NULL,
|
||||
`Volunteerable` tinyint(4) NOT NULL,
|
||||
`Active` tinyint(4) NOT NULL DEFAULT '1',
|
||||
`Volunteerable` tinyint(4) NOT NULL,
|
||||
`Overridable` tinyint(4) NOT NULL,
|
||||
`Covert` tinyint(4) NOT NULL DEFAULT '0',
|
||||
`ReportsToStandardPositionId` int(11) NOT NULL,
|
||||
`ReportsToAdditionalPositionId` int(11) NOT NULL,
|
||||
`ReportsToPositionId` int(11) NOT NULL,
|
||||
`DotReportsToPositionId` int(11) NOT NULL,
|
||||
`MinCount` int(11) NOT NULL,
|
||||
`MaxCount` int(11) NOT NULL,
|
||||
PRIMARY KEY (`AdditionalPositionId`),
|
||||
PRIMARY KEY (`PositionId`),
|
||||
KEY `Index_Org` (`OrganizationId`),
|
||||
KEY `Index_Geo` (`GeographyId`),
|
||||
KEY `Index_Report1` (`ReportsToStandardPositionId`),
|
||||
KEY `Index_Report2` (`ReportsToAdditionalPositionId`),
|
||||
KEY `Index_Report3` (`DotReportsToPositionId`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
|
||||
KEY `Index_Report1` (`ReportsToPositionId`),
|
||||
KEY `Index_Report2` (`DotReportsToPositionId`),
|
||||
KEY `Index_Level` (`PositionLevel`)
|
||||
);
|
||||
|
||||
|
||||
CREATE TABLE `PositionAssignments` (
|
||||
@@ -74,7 +55,7 @@ CREATE TABLE `PositionsAdditional` (
|
||||
KEY `Index_Person` (`PersonId`),
|
||||
KEY `Index_Active` (`Active`),
|
||||
KEY `Index_Pos` (`PositionId`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
|
||||
);
|
||||
|
||||
*/
|
||||
|
||||
@@ -95,22 +76,14 @@ namespace Swarmops.Database
|
||||
{
|
||||
#region Database field reading
|
||||
|
||||
private const string standardPositionFieldSequence =
|
||||
" PositionsStandard.StandardPositionId,PositionsStandard.OrganizationId,PositionsStandard.PositionLevel,PositionTypes.Name,PositionTitles.Name," + // 0-4
|
||||
"PositionsStandard.Active,PositionsStandard.Volunteerable,PositionsStandard.Overridable,PositionsStandard.Covert,PositionsStandard.ReportsToStandardPositionId," + // 5-9
|
||||
"PositionsStandard.DotReportsToStandardPositionId,PositionsStandard.MinCount,PositionsStandard.MaxCount" + // 10-12
|
||||
" FROM PositionsStandard " +
|
||||
" JOIN PositionTypes ON (PositionsStandard.PositionTypeId=PositionTypes.PositionTypeId) " +
|
||||
" JOIN PositionTitles ON (PositionsStandard.PositionTitleId=PositionTitles.PositionTitleId) ";
|
||||
|
||||
private const string additionalPositionFieldSequence =
|
||||
" PositionsAdditional.AdditionalPositionId,PositionsAdditional.OrganizationId,PositionsAdditional.GeographyId,PositionsAdditional.OverridesHigherPositionId,PositionsAdditional.CreatedByPersonId," + // 0-4
|
||||
"PositionsAdditional.CreatedDateTimeUtc,PositionTypes.Name,PositionTitles.Name,PositionsAdditional.InheritsDownward,PositionsAdditional.Volunteerable," + // 5-9
|
||||
"PositionsAdditional.Active,PositionsAdditional.Covert,PositionsAdditional.ReportsToStandardPositionId,PositionsAdditional.ReportsToAdditionalPositionId,PositionsAdditional.DotReportsToPositionId," + // 10-14
|
||||
"PositionsAdditional.MinCount,PositionsAdditional.MaxCount" + // 15-16
|
||||
" FROM PositionsAdditional " +
|
||||
" JOIN PositionTypes ON (PositionsAdditional.PositionTypeId=PositionTypes.PositionTypeId) " +
|
||||
" JOIN PositionTitles ON (PositionsAdditional.PositionTitleId=PositionTitles.PositionTitleId) ";
|
||||
private const string positionFieldSequence =
|
||||
" Positions.PositionId,Positions.PositionLevel,Positions.OrganizationId,Positions.GeographyId,Positions.OverridesHigherPositionId," + // 0-4
|
||||
"Positions.CreatedByPersonId,Positions.CreatedByPositionId,Positions.CreatedDateTimeUtc,PositionTypes.Name,PositionTitles.Name," + // 5-9
|
||||
"Positions.InheritsDownward,Positions.Active,Positions.Volunteerable,Positions.Overridable,Positions.Covert," + // 10-14
|
||||
"Positions.ReportsToPositionId,Positions.DotReportsToPositionId,Positions.MinCount,Positions.MaxCount" + // 15-18
|
||||
" FROM Positions " +
|
||||
" JOIN PositionTypes ON (Positions.PositionTypeId=PositionTypes.PositionTypeId) " +
|
||||
" JOIN PositionTitles ON (Positions.PositionTitleId=PositionTitles.PositionTitleId) ";
|
||||
|
||||
private const string positionAssignmentFieldSequence =
|
||||
" PositionAssignmentId,OrganizationId,GeographyId,PositionId,PersonId," + // 0-4
|
||||
@@ -118,56 +91,38 @@ namespace Swarmops.Database
|
||||
"TerminatedDateTimeUtc,TerminatedByPersonId,TerminatedByPositionId,AssignmentNotes,TerminationNotes" + // 10-14
|
||||
" FROM PositionAssignments ";
|
||||
|
||||
private static BasicPosition ReadStandardPositionFromDataReader(IDataRecord reader)
|
||||
private static BasicPosition ReadPositionFromDataReader(IDataRecord reader)
|
||||
{
|
||||
int standardPositionId = reader.GetInt32(0);
|
||||
int organizationId = reader.GetInt32 (1);
|
||||
PositionLevel positionLevel = (PositionLevel) reader.GetInt32 (2);
|
||||
string positionTypeName = reader.GetString (3);
|
||||
string positionTitleName = reader.GetString (4);
|
||||
bool active = reader.GetBoolean (5);
|
||||
bool volunteerable = reader.GetBoolean (6);
|
||||
bool overridable = reader.GetBoolean (7);
|
||||
bool covert = reader.GetBoolean (8);
|
||||
int reportsToStandardPositionId = reader.GetInt32 (9);
|
||||
int dotReportsToStandardPositionId = reader.GetInt32 (10);
|
||||
int minCount = reader.GetInt32 (11);
|
||||
int maxCount = reader.GetInt32 (12);
|
||||
// groups of five to match the field sequence string lines (maintainability)
|
||||
|
||||
return new BasicPosition (standardPositionId, organizationId, positionLevel, positionTypeName, positionTitleName,
|
||||
0 /*geographyId*/, overridable, 0 /*overridesId*/, 0 /*createdByPerson*/, DateTime.MinValue /*createdDateTimeUtc*/,
|
||||
true /*inheritsDownward*/, volunteerable, active, covert, reportsToStandardPositionId,
|
||||
dotReportsToStandardPositionId, minCount, maxCount);
|
||||
}
|
||||
int positionId = reader.GetInt32 (0);
|
||||
PositionLevel positionLevel = (PositionLevel) reader.GetInt32 (1);
|
||||
int organizationId = reader.GetInt32 (2);
|
||||
int geographyId = reader.GetInt32 (3);
|
||||
int overridesHigherPositionId = reader.GetInt32 (4);
|
||||
|
||||
private static BasicPosition ReadAdditionalPositionFromDataReader(IDataRecord reader)
|
||||
{
|
||||
int additionalPositionId = reader.GetInt32 (0);
|
||||
int organizationId = reader.GetInt32 (1);
|
||||
int geographyId = reader.GetInt32 (2);
|
||||
int overridesHigherPositionId = reader.GetInt32 (3);
|
||||
int createdByPersonId = reader.GetInt32 (4);
|
||||
DateTime createdDateTimeUtc = reader.GetDateTime (5);
|
||||
string positionTypeName = reader.GetString (6);
|
||||
string positionTitleName = reader.GetString (7);
|
||||
bool inheritsDownward = reader.GetBoolean (8);
|
||||
bool volunteerable = reader.GetBoolean (9);
|
||||
bool active = reader.GetBoolean (10);
|
||||
bool covert = reader.GetBoolean (11);
|
||||
int reportsToStandardPositionId = reader.GetInt32 (12);
|
||||
int reportsToAdditionalPositionId = reader.GetInt32 (13);
|
||||
int dotReportsToStandardPositionId = reader.GetInt32 (14);
|
||||
int minCount = reader.GetInt32 (15);
|
||||
int maxCount = reader.GetInt32 (16);
|
||||
int createdByPersonId = reader.GetInt32 (5);
|
||||
int createdByPositionId = reader.GetInt32 (6);
|
||||
DateTime createdDateTimeUtc = reader.GetDateTime (7);
|
||||
string positionTypeName = reader.GetString (8);
|
||||
string positionTitleName = reader.GetString (9);
|
||||
|
||||
int reportsToPositionId = (reportsToAdditionalPositionId != 0)
|
||||
? -reportsToAdditionalPositionId
|
||||
: reportsToStandardPositionId;
|
||||
bool inheritsDownward = reader.GetBoolean (10);
|
||||
bool active = reader.GetBoolean(11);
|
||||
bool volunteerable = reader.GetBoolean(12);
|
||||
bool overridable = reader.GetBoolean(13);
|
||||
bool covert = reader.GetBoolean(14);
|
||||
|
||||
return new BasicPosition (-additionalPositionId, organizationId, PositionLevel.Geography,
|
||||
positionTypeName, positionTitleName, geographyId, false /*overridable*/, overridesHigherPositionId,
|
||||
createdByPersonId, createdDateTimeUtc, inheritsDownward, volunteerable, active, covert,
|
||||
reportsToPositionId, dotReportsToStandardPositionId, minCount, maxCount);
|
||||
int reportsToPositionId = reader.GetInt32 (15);
|
||||
int dotReportsToPositionId = reader.GetInt32 (16);
|
||||
int minCount = reader.GetInt32 (17);
|
||||
int maxCount = reader.GetInt32 (18);
|
||||
|
||||
return new BasicPosition (
|
||||
positionId, positionLevel, organizationId, geographyId, overridesHigherPositionId,
|
||||
createdByPersonId, createdByPositionId, createdDateTimeUtc, positionTypeName, positionTitleName,
|
||||
inheritsDownward, active, volunteerable, overridable, covert,
|
||||
reportsToPositionId, dotReportsToPositionId, minCount, maxCount);
|
||||
|
||||
}
|
||||
|
||||
@@ -198,54 +153,33 @@ namespace Swarmops.Database
|
||||
|
||||
#region Database record reading -- SELECT clauses
|
||||
|
||||
public BasicPosition GetPosition (int positionId)
|
||||
{
|
||||
if (positionId > 0)
|
||||
{
|
||||
return GetStandardPosition (positionId);
|
||||
}
|
||||
else
|
||||
{
|
||||
return GetAdditionalPosition (-positionId);
|
||||
}
|
||||
}
|
||||
#region Positions
|
||||
|
||||
public BasicPosition[] GetPositions (params object[] conditions)
|
||||
{
|
||||
BasicPosition[] standardHits = GetStandardPositions (conditions);
|
||||
BasicPosition[] additionalHits = GetAdditionalPositions (conditions);
|
||||
|
||||
return standardHits.Concat (additionalHits).ToArray();
|
||||
|
||||
}
|
||||
|
||||
#region Standard Positions
|
||||
|
||||
public BasicPosition GetStandardPosition (int standardPositionId)
|
||||
public BasicPosition GetPosition(int positionId)
|
||||
{
|
||||
using (DbConnection connection = GetMySqlDbConnection())
|
||||
{
|
||||
connection.Open();
|
||||
|
||||
DbCommand command =
|
||||
GetDbCommand("SELECT" + standardPositionFieldSequence +
|
||||
"WHERE StandardPositionId=" + standardPositionId,
|
||||
GetDbCommand("SELECT" + positionFieldSequence +
|
||||
"WHERE PositionId=" + positionId,
|
||||
connection);
|
||||
|
||||
using (DbDataReader reader = command.ExecuteReader())
|
||||
{
|
||||
if (reader.Read())
|
||||
{
|
||||
return ReadStandardPositionFromDataReader(reader);
|
||||
return ReadPositionFromDataReader(reader);
|
||||
}
|
||||
|
||||
throw new ArgumentException("No such StandardPositionId:" + standardPositionId);
|
||||
throw new ArgumentException("No such PositionId:" + positionId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public BasicPosition[] GetStandardPositions(params object[] conditions)
|
||||
public BasicPosition[] GetPositionChildren (int positionId)
|
||||
{
|
||||
List<BasicPosition> result = new List<BasicPosition>();
|
||||
|
||||
@@ -255,13 +189,13 @@ namespace Swarmops.Database
|
||||
|
||||
DbCommand command =
|
||||
GetDbCommand(
|
||||
"SELECT" + standardPositionFieldSequence + ConstructWhereClause("PositionsStandard", conditions), connection);
|
||||
"SELECT" + positionFieldSequence + "WHERE Positions.ReportsToPositionId=" + positionId, connection);
|
||||
|
||||
using (DbDataReader reader = command.ExecuteReader())
|
||||
{
|
||||
while (reader.Read())
|
||||
{
|
||||
result.Add(ReadStandardPositionFromDataReader(reader));
|
||||
result.Add(ReadPositionFromDataReader(reader));
|
||||
}
|
||||
|
||||
return result.ToArray();
|
||||
@@ -269,36 +203,8 @@ namespace Swarmops.Database
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
#region Additional Positions
|
||||
|
||||
public BasicPosition GetAdditionalPosition(int additionalPositionId)
|
||||
{
|
||||
using (DbConnection connection = GetMySqlDbConnection())
|
||||
{
|
||||
connection.Open();
|
||||
|
||||
DbCommand command =
|
||||
GetDbCommand("SELECT" + additionalPositionFieldSequence +
|
||||
"WHERE AdditionalPositionId=" + additionalPositionId,
|
||||
connection);
|
||||
|
||||
using (DbDataReader reader = command.ExecuteReader())
|
||||
{
|
||||
if (reader.Read())
|
||||
{
|
||||
return ReadAdditionalPositionFromDataReader(reader);
|
||||
}
|
||||
|
||||
throw new ArgumentException("No such StandardPositionId:" + additionalPositionId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public BasicPosition[] GetAdditionalPositions(params object[] conditions)
|
||||
public BasicPosition[] GetPositions(params object[] conditions)
|
||||
{
|
||||
List<BasicPosition> result = new List<BasicPosition>();
|
||||
|
||||
@@ -308,13 +214,13 @@ namespace Swarmops.Database
|
||||
|
||||
DbCommand command =
|
||||
GetDbCommand(
|
||||
"SELECT" + additionalPositionFieldSequence + ConstructWhereClause("PositionsAdditional", conditions), connection);
|
||||
"SELECT" + positionFieldSequence + ConstructWhereClause("Positions", conditions), connection);
|
||||
|
||||
using (DbDataReader reader = command.ExecuteReader())
|
||||
{
|
||||
while (reader.Read())
|
||||
{
|
||||
result.Add(ReadAdditionalPositionFromDataReader(reader));
|
||||
result.Add(ReadPositionFromDataReader(reader));
|
||||
}
|
||||
|
||||
return result.ToArray();
|
||||
@@ -361,7 +267,7 @@ namespace Swarmops.Database
|
||||
|
||||
DbCommand command =
|
||||
GetDbCommand(
|
||||
"SELECT" + standardPositionFieldSequence + ConstructWhereClause("PositionsStandard", conditions), connection);
|
||||
"SELECT" + positionAssignmentFieldSequence + ConstructWhereClause("PositionAssignments", conditions), connection);
|
||||
|
||||
using (DbDataReader reader = command.ExecuteReader())
|
||||
{
|
||||
@@ -383,34 +289,10 @@ namespace Swarmops.Database
|
||||
#region Creation and manipulation -- stored procedures
|
||||
|
||||
|
||||
public int CreateStandardPosition(int organizationId, PositionLevel positionLevel, string positionTypeName,
|
||||
string positionTitleName, bool volunteerable, bool overridable, int reportsToPositionId, int dotReportsToPositionId,
|
||||
int minCount, int maxCount)
|
||||
{
|
||||
using (DbConnection connection = GetMySqlDbConnection())
|
||||
{
|
||||
connection.Open();
|
||||
|
||||
DbCommand command = GetDbCommand("CreateStandardPosition", connection);
|
||||
command.CommandType = CommandType.StoredProcedure;
|
||||
|
||||
AddParameterWithName(command, "organizationId", organizationId);
|
||||
AddParameterWithName(command, "positionLevel", (int)positionLevel);
|
||||
AddParameterWithName(command, "positionType", positionTypeName);
|
||||
AddParameterWithName(command, "positionTitle", positionTypeName);
|
||||
AddParameterWithName(command, "volunteerable", volunteerable);
|
||||
AddParameterWithName(command, "overridable", overridable);
|
||||
AddParameterWithName(command, "reportsToStandardPositionId", reportsToPositionId);
|
||||
AddParameterWithName(command, "dotReportsToStandardPositionId", dotReportsToPositionId);
|
||||
AddParameterWithName(command, "minCount", minCount);
|
||||
AddParameterWithName(command, "maxCount", maxCount);
|
||||
|
||||
return Convert.ToInt32(command.ExecuteScalar());
|
||||
}
|
||||
}
|
||||
|
||||
public int CreateAdditionalPosition(int organizationId, int geographyId, int overridesHigherPositionId, int createdByPersonId,
|
||||
string positionTypeName, string positionTitleName, bool inheritsDownward, bool volunteerable, bool overridable,
|
||||
public int CreatePosition(
|
||||
PositionLevel positionLevel, int organizationId, int geographyId, int overridesHigherPositionId,
|
||||
int createdByPersonId, int createdByPositionId, /* DateTimeCreatedUtc is measured below, */ string positionTypeName, string positionTitleName,
|
||||
bool inheritsDownward, /* active defaults true, */ bool volunteerable, bool overridable, /* covert defaults false, */
|
||||
int reportsToPositionId, int dotReportsToPositionId, int minCount, int maxCount)
|
||||
{
|
||||
DateTime utcNow = DateTime.UtcNow;
|
||||
@@ -419,29 +301,63 @@ namespace Swarmops.Database
|
||||
{
|
||||
connection.Open();
|
||||
|
||||
DbCommand command = GetDbCommand("CreateAdditionalPosition", connection);
|
||||
DbCommand command = GetDbCommand("CreatePosition", connection);
|
||||
command.CommandType = CommandType.StoredProcedure;
|
||||
|
||||
AddParameterWithName(command, "positionLevel", (int) positionLevel);
|
||||
AddParameterWithName(command, "organizationId", organizationId);
|
||||
AddParameterWithName(command, "geographyId", geographyId);
|
||||
AddParameterWithName(command, "overridesHigherPositionId", overridesHigherPositionId);
|
||||
|
||||
AddParameterWithName(command, "createdByPersonId", createdByPersonId);
|
||||
AddParameterWithName(command, "createdByPositionId", createdByPositionId);
|
||||
AddParameterWithName(command, "createdDateTimeUtc", utcNow);
|
||||
AddParameterWithName(command, "positionType", positionTypeName);
|
||||
AddParameterWithName(command, "positionTitle", positionTitleName);
|
||||
|
||||
AddParameterWithName(command, "inheritsDownward", volunteerable);
|
||||
// active defaults to true
|
||||
AddParameterWithName(command, "volunteerable", volunteerable);
|
||||
AddParameterWithName(command, "overridable", volunteerable);
|
||||
// covert defaults to false
|
||||
|
||||
AddParameterWithName(command, "reportsToPositionId", reportsToPositionId);
|
||||
AddParameterWithName(command, "dotReportsToPositionId", dotReportsToPositionId);
|
||||
AddParameterWithName(command, "minCount", minCount);
|
||||
AddParameterWithName(command, "maxCount", maxCount);
|
||||
|
||||
return Convert.ToInt32(command.ExecuteScalar());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public int CreatePositionAssignment (int organizationId, int geographyId, int positionId, int personId, int createdByPersonId, int createdByPositionId, DateTime expiresDateTimeUtc, string assignmentNotes)
|
||||
{
|
||||
DateTime utcNow = DateTime.UtcNow;
|
||||
|
||||
using (DbConnection connection = GetMySqlDbConnection())
|
||||
{
|
||||
connection.Open();
|
||||
|
||||
DbCommand command = GetDbCommand("CreatePositionAssignment", connection);
|
||||
command.CommandType = CommandType.StoredProcedure;
|
||||
|
||||
AddParameterWithName(command, "organizationId", organizationId);
|
||||
AddParameterWithName(command, "geographyId", geographyId);
|
||||
AddParameterWithName(command, "overridesHigherPositionId", overridesHigherPositionId);
|
||||
AddParameterWithName(command, "createdByPersonId", createdByPersonId);
|
||||
AddParameterWithName(command, "positionId", positionId);
|
||||
AddParameterWithName(command, "personId", personId);
|
||||
AddParameterWithName(command, "createdDateTimeUtc", utcNow);
|
||||
AddParameterWithName(command, "positionType", positionTypeName);
|
||||
AddParameterWithName(command, "positionTitle", positionTypeName);
|
||||
AddParameterWithName(command, "inheritsDownward", volunteerable);
|
||||
AddParameterWithName(command, "volunteerable", volunteerable);
|
||||
AddParameterWithName(command, "overridable", volunteerable);
|
||||
AddParameterWithName(command, "reportsToStandardPositionId", reportsToPositionId > 0 ? reportsToPositionId : 0);
|
||||
AddParameterWithName(command, "reportsToAdditionalPositionId", reportsToPositionId < 0 ? -reportsToPositionId : 0);
|
||||
AddParameterWithName(command, "dotReportsToStandardPositionId", dotReportsToPositionId);
|
||||
AddParameterWithName(command, "minCount", minCount);
|
||||
AddParameterWithName(command, "maxCount", maxCount);
|
||||
AddParameterWithName(command, "createdByPersonId", createdByPersonId);
|
||||
AddParameterWithName(command, "createdByPositionId", createdByPositionId);
|
||||
AddParameterWithName(command, "expiresDateTimeUtc", expiresDateTimeUtc);
|
||||
AddParameterWithName(command, "assignmentNotes", assignmentNotes);
|
||||
|
||||
return -Convert.ToInt32(command.ExecuteScalar()); // Do note the negative! That's intentional.
|
||||
return Convert.ToInt32 (command.ExecuteScalar());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
public int CreateRefund(int paymentId, int createdByPersonId)
|
||||
{
|
||||
|
||||
@@ -69,7 +69,6 @@
|
||||
<Compile Include="Database-Meetings.cs" />
|
||||
<Compile Include="Database-CommunicationTurnarounds.cs" />
|
||||
<Compile Include="Database-ExternalActivities.cs" />
|
||||
<Compile Include="Database-Attribute.cs" />
|
||||
<Compile Include="Database-Ballots.cs" />
|
||||
<Compile Include="Database-ExternalIdentities.cs" />
|
||||
<Compile Include="Database-Conditions.cs" />
|
||||
|
||||
+4
-4
@@ -22,14 +22,14 @@ namespace Swarmops.Logic.App_GlobalResources {
|
||||
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
|
||||
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
|
||||
internal class ParticipantTitles {
|
||||
internal class LocalizedTitles {
|
||||
|
||||
private static global::System.Resources.ResourceManager resourceMan;
|
||||
|
||||
private static global::System.Globalization.CultureInfo resourceCulture;
|
||||
|
||||
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
|
||||
internal ParticipantTitles() {
|
||||
internal LocalizedTitles() {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -39,7 +39,7 @@ namespace Swarmops.Logic.App_GlobalResources {
|
||||
internal static global::System.Resources.ResourceManager ResourceManager {
|
||||
get {
|
||||
if (object.ReferenceEquals(resourceMan, null)) {
|
||||
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Swarmops.Logic.App_GlobalResources.ParticipantTitles", typeof(ParticipantTitles).Assembly);
|
||||
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Swarmops.Logic.App_GlobalResources.LocalizedTitles", typeof(LocalizedTitles).Assembly);
|
||||
resourceMan = temp;
|
||||
}
|
||||
return resourceMan;
|
||||
@@ -205,7 +205,7 @@ namespace Swarmops.Logic.App_GlobalResources {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Sysadmins (Read/write).
|
||||
/// Looks up a localized string similar to Sysadmins (Read/Write).
|
||||
/// </summary>
|
||||
internal static string Position_System_SysadminReadWrite_Plural {
|
||||
get {
|
||||
+1
-1
@@ -166,7 +166,7 @@
|
||||
<value>Sysadmin (Read/Write)</value>
|
||||
</data>
|
||||
<data name="Position_System_SysadminReadWrite_Plural" xml:space="preserve">
|
||||
<value>Sysadmins (Read/write)</value>
|
||||
<value>Sysadmins (Read/Write)</value>
|
||||
</data>
|
||||
<data name="Title_Activist_Corps" xml:space="preserve">
|
||||
<value>Activist Swarm</value>
|
||||
+7
-4
@@ -92,10 +92,10 @@
|
||||
<AutoGen>True</AutoGen>
|
||||
<DesignTime>True</DesignTime>
|
||||
</Compile>
|
||||
<Compile Include="App_GlobalResources\ParticipantTitles.Designer.cs">
|
||||
<Compile Include="App_GlobalResources\LocalizedTitles.Designer.cs">
|
||||
<AutoGen>True</AutoGen>
|
||||
<DesignTime>True</DesignTime>
|
||||
<DependentUpon>ParticipantTitles.resx</DependentUpon>
|
||||
<DependentUpon>LocalizedTitles.resx</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="App_GlobalResources\Logic.Communications.Transmission.MailPayload.Designer.cs">
|
||||
<AutoGen>True</AutoGen>
|
||||
@@ -340,6 +340,9 @@
|
||||
<Compile Include="Swarm\Person.cs" />
|
||||
<Compile Include="Swarm\PersonRole.cs" />
|
||||
<Compile Include="Swarm\Position.cs" />
|
||||
<Compile Include="Swarm\PositionAssignment.cs" />
|
||||
<Compile Include="Swarm\PositionAssignments.cs" />
|
||||
<Compile Include="Swarm\Positions.cs" />
|
||||
<Compile Include="Swarm\RoleLookup.cs" />
|
||||
<Compile Include="Swarm\Roles.cs" />
|
||||
<Compile Include="Swarm\Volunteer.cs" />
|
||||
@@ -438,9 +441,9 @@
|
||||
<EmbeddedResource Include="App_GlobalResources\nl-NL\Logic.Communications.Transmission.NotificationPayload.nl-NL.resx" />
|
||||
<EmbeddedResource Include="App_GlobalResources\nl-NL\Logic.Financial.FinancialTransactionTagSetTypesStock.nl-NL.resx" />
|
||||
<EmbeddedResource Include="App_GlobalResources\nl-NL\Logic.Swarm.DashboardTodos.nl-NL.resx" />
|
||||
<EmbeddedResource Include="App_GlobalResources\ParticipantTitles.resx">
|
||||
<EmbeddedResource Include="App_GlobalResources\LocalizedTitles.resx">
|
||||
<Generator>ResXFileCodeGenerator</Generator>
|
||||
<LastGenOutput>ParticipantTitles.Designer.cs</LastGenOutput>
|
||||
<LastGenOutput>LocalizedTitles.Designer.cs</LastGenOutput>
|
||||
</EmbeddedResource>
|
||||
<EmbeddedResource Include="App_GlobalResources\pl-PL\Logic.Communications.Transmission.NotificationPayload.pl-PL.resx" />
|
||||
<EmbeddedResource Include="App_GlobalResources\pl-PL\Logic.Financial.FinancialTransactionTagSetTypesStock.pl-PL.resx" />
|
||||
|
||||
@@ -12,8 +12,8 @@ namespace Swarmops.Logic.Support
|
||||
public class DatabaseMaintenance
|
||||
{
|
||||
/// <summary>
|
||||
/// Feeds a newly-created database with an empty structure. Do not use on populated databases; it's like a Genesis
|
||||
/// Device.
|
||||
/// Feeds a newly-created database with an empty structure. Do not use on populated databases;
|
||||
/// it's like a Genesis Device.
|
||||
/// </summary>
|
||||
public static void FirstInitialization()
|
||||
{
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Swarmops.Common.Interfaces;
|
||||
|
||||
namespace Swarmops.Logic.Support
|
||||
{
|
||||
public class PluralBase<TPlural, TSingular, TBasic> : List<TSingular>, IHasIdentities
|
||||
public class PluralBase<TPlural, TSingular, TBasic> : List<TSingular>, IHasIdentities, IHasSingularPluralTypes
|
||||
where TPlural : PluralBase<TPlural, TSingular, TBasic>, new()
|
||||
where TBasic : IHasIdentity
|
||||
where TSingular : IHasIdentity
|
||||
@@ -145,5 +146,8 @@ namespace Swarmops.Logic.Support
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Type SingularType { get { return typeof(TSingular); } }
|
||||
public Type PluralType { get { return typeof(TPlural); } }
|
||||
}
|
||||
}
|
||||
@@ -8,7 +8,7 @@ namespace Swarmops.Logic.Swarm
|
||||
{
|
||||
public static string Localized (ParticipantTitle title, TitleVariant variant = TitleVariant.Generic)
|
||||
{
|
||||
return ParticipantTitles.ResourceManager.GetString ("Title_" + title + "_" + variant);
|
||||
return LocalizedTitles.ResourceManager.GetString ("Title_" + title + "_" + variant);
|
||||
}
|
||||
|
||||
public static string Localized (ParticipantTitle title, PersonGender gender)
|
||||
|
||||
@@ -4,6 +4,7 @@ using Swarmops.Basic.Types;
|
||||
using Swarmops.Basic.Types.Structure;
|
||||
using Swarmops.Basic.Types.Swarm;
|
||||
using Swarmops.Common.Enums;
|
||||
using Swarmops.Common.Interfaces;
|
||||
using Swarmops.Database;
|
||||
using Swarmops.Logic.Security;
|
||||
using Swarmops.Logic.Structure;
|
||||
@@ -11,7 +12,7 @@ using Swarmops.Logic.Support;
|
||||
|
||||
namespace Swarmops.Logic.Swarm
|
||||
{
|
||||
public class People : List<Person>
|
||||
public class People : List<Person>, IHasIdentities, IHasSingularPluralTypes
|
||||
{
|
||||
public int[] Identities
|
||||
{
|
||||
@@ -531,5 +532,8 @@ namespace Swarmops.Logic.Swarm
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public Type SingularType { get { return typeof(Person); } }
|
||||
public Type PluralType { get { return typeof(People); } }
|
||||
}
|
||||
}
|
||||
@@ -8,10 +8,10 @@ using NBitcoin;
|
||||
using Swarmops.Basic.Types;
|
||||
using Swarmops.Basic.Types.Structure;
|
||||
using Swarmops.Basic.Types.Swarm;
|
||||
using Swarmops.Common.Attributes;
|
||||
using Swarmops.Common.Enums;
|
||||
using Swarmops.Common.Interfaces;
|
||||
using Swarmops.Database;
|
||||
using Swarmops.Database.Attributes;
|
||||
using Swarmops.Logic.Communications;
|
||||
using Swarmops.Logic.DashboardTasks;
|
||||
using Swarmops.Logic.Security;
|
||||
|
||||
+154
-5
@@ -1,25 +1,174 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Swarmops.Basic.Types.Swarm;
|
||||
using Swarmops.Common.Enums;
|
||||
using Swarmops.Common.Generics;
|
||||
using Swarmops.Database;
|
||||
using Swarmops.Logic.App_GlobalResources;
|
||||
using Swarmops.Logic.Structure;
|
||||
|
||||
namespace Swarmops.Logic.Swarm
|
||||
{
|
||||
public class Position
|
||||
public class Position: BasicPosition
|
||||
{
|
||||
|
||||
public static string Localized (PositionType title, bool plural = false)
|
||||
[Obsolete("Do not use the parameterless constructor. Use Create() or read from database.", true)]
|
||||
private Position() : base (null)
|
||||
{
|
||||
string titleString = title.ToString();
|
||||
// do not use
|
||||
}
|
||||
|
||||
private Position (BasicPosition basic) : base (basic)
|
||||
{
|
||||
// private ctor
|
||||
}
|
||||
|
||||
public static Position FromBasic (BasicPosition basic)
|
||||
{
|
||||
return new Position (basic); // accesses private ctor
|
||||
}
|
||||
|
||||
public static Position FromIdentity (int positionId)
|
||||
{
|
||||
return FromBasic(SwarmDb.GetDatabaseForReading().GetPosition (positionId));
|
||||
}
|
||||
|
||||
public static Position FromIdentityAggressive (int positionId)
|
||||
{
|
||||
return FromBasic(SwarmDb.GetDatabaseForWriting().GetPosition (positionId));
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static Position Create(PositionLevel level, Person createdByPerson, Position createdByPosition, PositionType positionType,
|
||||
PositionTitle positionTitle, bool volunteerable, bool overridable, Position reportsTo, Position dotReportsTo,
|
||||
int minCount, int maxCount)
|
||||
{
|
||||
if (level != PositionLevel.Systemwide)
|
||||
{
|
||||
throw new ArgumentException (
|
||||
"Can only create system-wide positions (e.g. sysadmin) with this organizationless Position.Create() version.");
|
||||
}
|
||||
|
||||
int positionId = SwarmDb.GetDatabaseForWriting()
|
||||
.CreatePosition(
|
||||
PositionLevel.Systemwide, 0 /*organizationId*/, 0 /* geographyId */, 0 /*overridesHigherId */,
|
||||
createdByPerson == null? 0: createdByPerson.Identity, createdByPosition == null? 0: createdByPosition.Identity,
|
||||
positionType.ToString(), positionTitle.ToString(),
|
||||
false /*inheritsDownward*/, volunteerable, overridable,
|
||||
reportsTo == null? 0: reportsTo.Identity,
|
||||
dotReportsTo == null? 0: dotReportsTo.Identity,
|
||||
minCount, maxCount);
|
||||
|
||||
return FromIdentityAggressive(positionId);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public PositionAssignment Assign (Person person, Organization organization, Geography geography,
|
||||
Person assignedByPerson, Position assignedByPosition, string assignmentNotes, DateTime? expiresUtc)
|
||||
{
|
||||
return PositionAssignment.Create (organization, geography, this, person, assignedByPerson,
|
||||
assignedByPosition, expiresUtc, assignmentNotes);
|
||||
}
|
||||
|
||||
public PositionAssignment Assign(Person person, Geography geography, Person assignedByPerson, Position assignedByPosition,
|
||||
string assignmentNotes, DateTime? expiresUtc)
|
||||
{
|
||||
return PositionAssignment.Create(this.Organization, geography, this, person, assignedByPerson,
|
||||
assignedByPosition, expiresUtc, assignmentNotes);
|
||||
}
|
||||
|
||||
public PositionAssignment Assign(Person person, Person assignedByPerson, Position assignedByPosition,
|
||||
string assignmentNotes, DateTime? expiresUtc)
|
||||
{
|
||||
return PositionAssignment.Create(this.Organization, this.Geography, this, person, assignedByPerson,
|
||||
assignedByPosition, expiresUtc, assignmentNotes);
|
||||
}
|
||||
|
||||
public Organization Organization
|
||||
{
|
||||
get { return base.OrganizationId == 0 ? null : Organization.FromIdentity (base.OrganizationId); }
|
||||
}
|
||||
|
||||
public Geography Geography
|
||||
{
|
||||
get { return base.GeographyId == 0 ? null : Geography.FromIdentity (base.GeographyId); }
|
||||
}
|
||||
|
||||
|
||||
public PositionType PositionType
|
||||
{
|
||||
get { return (PositionType) Enum.Parse (typeof (PositionType), this.PositionTypeName); }
|
||||
}
|
||||
|
||||
public PositionTitle PositionTitle
|
||||
{
|
||||
get { return (PositionTitle) Enum.Parse (typeof (PositionTitle), this.PositionTitleName); }
|
||||
}
|
||||
|
||||
|
||||
public static Position RootSysadmin
|
||||
{
|
||||
// Gets the root position.
|
||||
get
|
||||
{
|
||||
Positions systemLevelPositions = Positions.ForSystem();
|
||||
|
||||
foreach (Position position in systemLevelPositions)
|
||||
{
|
||||
if (position.PositionType == PositionType.System_SysadminMain)
|
||||
{
|
||||
return position;
|
||||
}
|
||||
}
|
||||
|
||||
throw new InvalidOperationException("No root sysadmin position defined - this is an invalid state");
|
||||
}
|
||||
}
|
||||
|
||||
public Positions Children
|
||||
{
|
||||
get { return Positions.GetChildren (this); }
|
||||
}
|
||||
|
||||
|
||||
public PositionAssignments Assignments
|
||||
{
|
||||
get { return PositionAssignments.ForPosition (this); }
|
||||
}
|
||||
|
||||
|
||||
public string Localized(bool plural = false)
|
||||
{
|
||||
return Position.Localized ((PositionType) Enum.Parse (typeof (PositionType), this.PositionTypeName),
|
||||
(PositionTitle) Enum.Parse (typeof (PositionTitle), this.PositionTitleName), plural);
|
||||
}
|
||||
|
||||
|
||||
public static string Localized(PositionType type, bool plural = false)
|
||||
{
|
||||
string titleString = type.ToString();
|
||||
if (plural)
|
||||
{
|
||||
titleString += "_Plural";
|
||||
}
|
||||
|
||||
return ParticipantTitles.ResourceManager.GetString ("Position_" + titleString);
|
||||
return LocalizedTitles.ResourceManager.GetString("Position_" + titleString);
|
||||
}
|
||||
|
||||
public static string Localized(PositionType type, PositionTitle title, bool plural = false)
|
||||
{
|
||||
string titleString = type.ToString();
|
||||
if (plural)
|
||||
{
|
||||
titleString += "_Plural";
|
||||
}
|
||||
|
||||
return LocalizedTitles.ResourceManager.GetString("Position_" + titleString);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,101 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using NBitcoin;
|
||||
using Swarmops.Basic.Types.Swarm;
|
||||
using Swarmops.Common.Enums;
|
||||
using Swarmops.Database;
|
||||
using Swarmops.Logic.Structure;
|
||||
|
||||
namespace Swarmops.Logic.Swarm
|
||||
{
|
||||
public class PositionAssignment: BasicPositionAssignment
|
||||
{
|
||||
private PositionAssignment() : base (null)
|
||||
{
|
||||
// do not call private null ctor
|
||||
}
|
||||
|
||||
private PositionAssignment (BasicPositionAssignment basic) : base (basic)
|
||||
{
|
||||
// private ctor
|
||||
}
|
||||
|
||||
public static PositionAssignment FromBasic (BasicPositionAssignment basic)
|
||||
{
|
||||
return new PositionAssignment (basic); // calls private ctor
|
||||
}
|
||||
|
||||
public static PositionAssignment FromIdentity (int positionAssignmentId)
|
||||
{
|
||||
return FromBasic (SwarmDb.GetDatabaseForReading().GetPositionAssignment (positionAssignmentId));
|
||||
}
|
||||
|
||||
public static PositionAssignment FromIdentityAggressive (int positionAssignmentId)
|
||||
{
|
||||
return FromBasic(SwarmDb.GetDatabaseForWriting().GetPositionAssignment(positionAssignmentId)); // "ForWriting" is intentional - avoids race conditions in Create()
|
||||
}
|
||||
|
||||
|
||||
public Person Person
|
||||
{
|
||||
get { return Person.FromIdentity (base.PersonId); }
|
||||
}
|
||||
|
||||
public Position Position
|
||||
{
|
||||
get { return Position.FromIdentity (base.PositionId); }
|
||||
}
|
||||
|
||||
public static PositionAssignment Create (Organization organization, Geography geography, Position position,
|
||||
Person person, Person createdByPerson, Position createdByPosition, DateTime? expiresDateTimeUtc,
|
||||
string assignmentNotes)
|
||||
{
|
||||
int organizationId = 0;
|
||||
|
||||
if (position.PositionLevel != PositionLevel.OrganizationwideDefault &&
|
||||
position.PositionLevel != PositionLevel.Systemwide)
|
||||
{
|
||||
organizationId = organization.Identity; // can't be null in these cases
|
||||
}
|
||||
else
|
||||
{
|
||||
if (organization != null)
|
||||
{
|
||||
// MUST be null in these cases
|
||||
|
||||
throw new ArgumentException ("Organization cannot be defined when position is systemwide");
|
||||
}
|
||||
}
|
||||
|
||||
int geographyId = 0;
|
||||
|
||||
if (position.PositionLevel == PositionLevel.Geography)
|
||||
{
|
||||
geographyId = geography.Identity;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (geography != null)
|
||||
{
|
||||
throw new ArgumentException ("Geography cannot be defined when position is global");
|
||||
}
|
||||
}
|
||||
|
||||
int createdByPersonId = createdByPerson == null ? 0 : createdByPerson.Identity;
|
||||
int createdByPositionId = createdByPosition == null ? 0 : createdByPosition.Identity;
|
||||
|
||||
// TODO: Verify constraints of max/min counts for position
|
||||
|
||||
int positionAssignmentId = SwarmDb.GetDatabaseForWriting()
|
||||
.CreatePositionAssignment (organizationId, geographyId, position.Identity, person.Identity,
|
||||
createdByPersonId, createdByPositionId,
|
||||
expiresDateTimeUtc == null ? DateTime.MaxValue : (DateTime) expiresDateTimeUtc, assignmentNotes);
|
||||
|
||||
return FromIdentityAggressive (positionAssignmentId);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Swarmops.Basic.Types.Swarm;
|
||||
using Swarmops.Database;
|
||||
using Swarmops.Logic.Support;
|
||||
|
||||
namespace Swarmops.Logic.Swarm
|
||||
{
|
||||
public class PositionAssignments: PluralBase<PositionAssignments, PositionAssignment, BasicPositionAssignment>
|
||||
{
|
||||
public static PositionAssignments ForPosition (Position position, bool includeTerminated = false)
|
||||
{
|
||||
return ForPositions (Positions.FromSingle (position), includeTerminated);
|
||||
}
|
||||
|
||||
public static PositionAssignments ForPositions (Positions positions, bool includeTerminated = false)
|
||||
{
|
||||
if (!includeTerminated)
|
||||
{
|
||||
return FromArray(SwarmDb.GetDatabaseForReading().GetPositionAssignments(positions, DatabaseCondition.ActiveTrue));
|
||||
}
|
||||
|
||||
return FromArray (SwarmDb.GetDatabaseForReading().GetPositionAssignments (positions));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using NBitcoin.Protocol;
|
||||
using Swarmops.Basic.Types.Swarm;
|
||||
using Swarmops.Common.Enums;
|
||||
using Swarmops.Database;
|
||||
using Swarmops.Logic.Support;
|
||||
using Swarmops.Common.Generics;
|
||||
|
||||
namespace Swarmops.Logic.Swarm
|
||||
{
|
||||
public class Positions: PluralBase<Positions, Position, BasicPosition>
|
||||
{
|
||||
public static Positions ForSystem()
|
||||
{
|
||||
return FromArray(SwarmDb.GetDatabaseForReading().GetPositions (PositionLevel.Systemwide));
|
||||
}
|
||||
|
||||
public PositionAssignments Assignments
|
||||
{
|
||||
get { return PositionAssignments.ForPositions(this); }
|
||||
}
|
||||
|
||||
public static Positions GetChildren (Position forPosition)
|
||||
{
|
||||
return FromArray (SwarmDb.GetDatabaseForReading().GetPositionChildren (forPosition.Identity));
|
||||
}
|
||||
|
||||
public static void CreateSysadminPositions()
|
||||
{
|
||||
// first, verify there aren't actually any sysadmin positions. Defensive coding for the win.
|
||||
|
||||
if (Positions.ForSystem().Count > 0)
|
||||
{
|
||||
throw new InvalidOperationException ("Can't initialize sysadmin positions - already there");
|
||||
}
|
||||
|
||||
// Ok, so there are zero system-level positions. Create the Sysadmin positions.
|
||||
|
||||
Position sysadminPrincipal = Position.Create (PositionLevel.Systemwide, null /* createdByPerson*/, null /*createdByPosition*/, PositionType.System_SysadminMain,
|
||||
PositionTitle.Default, false /*volunteerable*/, false /*overridable*/, null /*reportsTo*/, null /*dotReportsTo*/, 1 /*minCount*/, 1 /*maxCount*/);
|
||||
|
||||
Position.Create(PositionLevel.Systemwide, null /* createdByPerson*/, null /*createdByPosition*/, PositionType.System_SysadminReadWrite, PositionTitle.Default,
|
||||
false, false, sysadminPrincipal, null /*dotReportsTo*/, 0 /*minCount*/, 0 /*maxCount*/);
|
||||
|
||||
Position.Create(PositionLevel.Systemwide, null /* createdByPerson*/, null /*createdByPosition*/, PositionType.System_SysadminAssistantReadOnly, PositionTitle.Default,
|
||||
false, false, sysadminPrincipal, null /*dotReportsTo*/, 0 /*minCount*/, 0 /*maxCount*/);
|
||||
|
||||
// If there's exactly one person in the system, we're undergoing Setup, so assign to Sysadmin Principal position.
|
||||
// Otherwise let grandfathering code handle it.
|
||||
|
||||
People allPeople = People.GetAll();
|
||||
// calling People.GetAll() would be a killer on well-built-out systems, but this code only runs once, and in Setup
|
||||
|
||||
if (allPeople.Count == 1)
|
||||
{
|
||||
sysadminPrincipal.Assign (allPeople[0], null, null, "Assigned initial sysadmin", null);
|
||||
}
|
||||
}
|
||||
|
||||
public Tree<Position> Tree { get { return Tree<Position>.FromCollection (this); }}
|
||||
}
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Json-PersonRoleTreeData.aspx.cs" Inherits="Swarmops.Frontend.Automation.Json_PersonRoleTreeData" %>
|
||||
@@ -1,81 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using Swarmops.Common.Enums;
|
||||
using Swarmops.Logic.Financial;
|
||||
using Swarmops.Logic.Structure;
|
||||
using Swarmops.Logic.Swarm;
|
||||
|
||||
namespace Swarmops.Frontend.Automation
|
||||
{
|
||||
public partial class Json_PersonRoleTreeData : DataV5Base
|
||||
{
|
||||
protected void Page_Load(object sender, EventArgs e)
|
||||
{
|
||||
Response.ContentType = "application/json";
|
||||
|
||||
// If level if system-wide, execute this block. Also, move the data to the real place, please
|
||||
|
||||
JsonPositions rootPositions = new JsonPositions();
|
||||
|
||||
Organization sandbox = Organization.FromIdentity (1); // Used as sysadmin basis
|
||||
|
||||
string[] writeAdminIds = sandbox.Parameters.TemporaryAccessListWrite.Split (',');
|
||||
string[] readAdminIds = sandbox.Parameters.TemporaryAccessListRead.Split(',');
|
||||
|
||||
JsonPosition root = new JsonPosition();
|
||||
root.Id = "Root"; // heh. Sysadmin has id "root". Heh.
|
||||
root.LocalizedTitle = Position.Localized (PositionType.System_SysadminMain);
|
||||
root.AssignedName = Person.FromIdentity (Int32.Parse (writeAdminIds[0])).Canonical;
|
||||
|
||||
root.Children.Add(new JsonPosition { Id = "AsstRW", LocalizedTitle = Position.Localized(PositionType.System_SysadminReadWrite, true), AssignedName = Resources.Global.Swarm_Vacant });
|
||||
root.Children.Add(new JsonPosition { Id = "AsstRO", LocalizedTitle = Position.Localized(PositionType.System_SysadminAssistantReadOnly, true), AssignedName = Resources.Global.Swarm_Vacant });
|
||||
|
||||
JsonPositions positions = new JsonPositions();
|
||||
positions.Add (root);
|
||||
|
||||
Response.Output.WriteLine(RecursePositionTree (positions));
|
||||
|
||||
Response.End();
|
||||
}
|
||||
|
||||
private string RecursePositionTree (JsonPositions positions)
|
||||
{
|
||||
List<string> elements = new List<string>();
|
||||
|
||||
foreach (JsonPosition position in positions)
|
||||
{
|
||||
string element = string.Format("\"id\":\"{0}\",\"positionTitle\":\"{1}\",\"assignedName\":\"{2}\"",
|
||||
JsonSanitize (position.Id), JsonSanitize (position.LocalizedTitle), JsonSanitize (position.AssignedName));
|
||||
|
||||
if (position.Children.Count > 0)
|
||||
{
|
||||
element += ",\"state\":\"open\",\"children\":" + RecursePositionTree(position.Children);
|
||||
}
|
||||
|
||||
elements.Add("{" + element + "}");
|
||||
}
|
||||
|
||||
return "[" + String.Join(",", elements.ToArray()) + "]";
|
||||
}
|
||||
|
||||
private class JsonPosition
|
||||
{
|
||||
public JsonPosition()
|
||||
{
|
||||
Children = new JsonPositions();
|
||||
}
|
||||
|
||||
public string Id { get; set; }
|
||||
public string LocalizedTitle { get; set; }
|
||||
public string AssignedName { get; set; }
|
||||
|
||||
public JsonPositions Children { get; set; }
|
||||
}
|
||||
|
||||
private class JsonPositions : List<JsonPosition>
|
||||
{
|
||||
// just a typedef
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Json-PositionTree.aspx.cs" Inherits="Swarmops.Frontend.Automation.Json_PositionTree" %>
|
||||
@@ -0,0 +1,93 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using Swarmops.Common.Enums;
|
||||
using Swarmops.Common.Generics;
|
||||
using Swarmops.Logic.Financial;
|
||||
using Swarmops.Logic.Structure;
|
||||
using Swarmops.Logic.Swarm;
|
||||
|
||||
namespace Swarmops.Frontend.Automation
|
||||
{
|
||||
public partial class Json_PositionTree : DataV5Base
|
||||
{
|
||||
protected void Page_Load(object sender, EventArgs e)
|
||||
{
|
||||
Response.ContentType = "application/json";
|
||||
|
||||
// If level if system-wide, execute this block. Also, move the data to the real place, please
|
||||
|
||||
JsonPositions rootPositions = new JsonPositions();
|
||||
|
||||
Tree<Position> systemPositions = Positions.ForSystem().Tree;
|
||||
|
||||
|
||||
|
||||
Response.Output.WriteLine(RecursePositionTree (systemPositions.RootNodes));
|
||||
|
||||
Response.End();
|
||||
}
|
||||
|
||||
private string RecursePositionTree (List<TreeNode<Position>> positionNodes)
|
||||
{
|
||||
List<string> elements = new List<string>();
|
||||
string reportsTo = string.Empty;
|
||||
if (positionNodes.Count > 0 && positionNodes[0].Data.ParentIdentity != 0)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
foreach (TreeNode<Position> positionNode in positionNodes)
|
||||
{
|
||||
Position position = positionNode.Data;
|
||||
string localizedPositionName = position.Localized (positionNode.Data.MaxCount > 1);
|
||||
PositionAssignments assignments = position.Assignments;
|
||||
|
||||
string parentName = string.Empty;
|
||||
if (positionNode.Parent != null)
|
||||
{
|
||||
parentName = positionNode.Parent.Data.Localized();
|
||||
}
|
||||
|
||||
string assignedName = Resources.Global.Swarm_Vacant;
|
||||
if (assignments.Count > 0)
|
||||
{
|
||||
assignedName = assignments[0].Person.Canonical;
|
||||
}
|
||||
|
||||
string element = string.Format("\"id\":\"{0}\",\"positionTitle\":\"{1}\",\"assignedName\":\"{2}\",\"reportsTo\":\"{3}\"",
|
||||
position.Identity, JsonSanitize (localizedPositionName), JsonSanitize (assignedName), JsonSanitize (parentName));
|
||||
|
||||
// TODO: Add all assignments after the first one right here
|
||||
|
||||
if (position.Children.Count > 0)
|
||||
{
|
||||
element += ",\"state\":\"open\",\"children\":" + RecursePositionTree(positionNode.Children);
|
||||
}
|
||||
|
||||
elements.Add("{" + element + "}");
|
||||
}
|
||||
|
||||
return "[" + String.Join(",", elements.ToArray()) + "]";
|
||||
}
|
||||
|
||||
private class JsonPosition
|
||||
{
|
||||
public JsonPosition()
|
||||
{
|
||||
Children = new JsonPositions();
|
||||
}
|
||||
|
||||
public string Id { get; set; }
|
||||
public string LocalizedTitle { get; set; }
|
||||
public string AssignedName { get; set; }
|
||||
|
||||
public JsonPositions Children { get; set; }
|
||||
}
|
||||
|
||||
private class JsonPositions : List<JsonPosition>
|
||||
{
|
||||
// just a typedef
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,37 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
using System.Web.UI;
|
||||
using System.Web.UI.WebControls;
|
||||
|
||||
public partial class Controls_v5_Swarm_TreePersonRoles : ControlV5Base
|
||||
{
|
||||
protected void Page_Init (object sender, EventArgs e)
|
||||
{
|
||||
// Request control framework in Init - the Load is too late for child controls
|
||||
|
||||
((PageV5Base)this.Page).RegisterControl(EasyUIControl.Tree | EasyUIControl.DataGrid);
|
||||
}
|
||||
|
||||
protected void Page_Load(object sender, EventArgs e)
|
||||
{
|
||||
}
|
||||
|
||||
public RoleLevel Level { get; set; }
|
||||
public int OrganizationId { get; set; }
|
||||
public int GeographyId { get; set; }
|
||||
|
||||
|
||||
public enum RoleLevel
|
||||
{
|
||||
Unknown = 0,
|
||||
Systemwide,
|
||||
Organizationwide,
|
||||
SuborganizationwideDefault,
|
||||
OrganizationTop,
|
||||
SuborganizationTopDefault,
|
||||
GeographicDefault,
|
||||
Geographic
|
||||
}
|
||||
}
|
||||
+3
-3
@@ -1,4 +1,4 @@
|
||||
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="TreePersonRoles.ascx.cs" Inherits="Controls_v5_Swarm_TreePersonRoles" %>
|
||||
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="TreePositions.ascx.cs" Inherits="Swarmops.Frontend.Controls.v5.Swarm.TreePositions" %>
|
||||
|
||||
<script language="javascript" type="text/javascript">
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
|
||||
|
||||
<table id="<%=this.ClientID %>_tablePositions" title="" class="easyui-treegrid" style="width:680px;height:600px"
|
||||
url="/Automation/Json-PersonRoleTreeData.aspx"
|
||||
url="/Automation/Json-PositionTree.aspx"
|
||||
rownumbers="false"
|
||||
animate="true"
|
||||
fitColumns="true"
|
||||
@@ -29,7 +29,7 @@
|
||||
<th field="positionTitle" width="160"><asp:Literal ID="LiteralHeaderPosition" Text="Position XYZ" runat="server"/></th>
|
||||
<th field="assignedName" width="160"><asp:Literal ID="LiteralHeaderQ1" Text="AssignedName XYZ" runat="server" /></th>
|
||||
<th field="dateExpires" width="80"><asp:Literal ID="LiteralHeaderExpires" Text="ExpiresDate XYZ" runat="server" /></th>
|
||||
<th field="reportsToName" width="120"><asp:Literal ID="LiteralHeaderReportsTo" Text="ReportsTo XYZ" runat="server" /></th>
|
||||
<th field="reportsTo" width="120"><asp:Literal ID="LiteralHeaderReportsTo" Text="ReportsTo XYZ" runat="server" /></th>
|
||||
<th field="flags" width="50" align="center"><asp:Literal ID="Literal2" Text="FLAGS" runat="server" /></th>
|
||||
<th field="vol" width="30" align="center"><asp:Literal ID="Literal3" Text="VOL" runat="server" /></th>
|
||||
<th field="editIcon" width="30" align="center"><asp:Literal ID="Literal1" Text="EDIT" runat="server" /></th>
|
||||
@@ -0,0 +1,40 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
using System.Web.UI;
|
||||
using System.Web.UI.WebControls;
|
||||
|
||||
namespace Swarmops.Frontend.Controls.v5.Swarm
|
||||
{
|
||||
public partial class TreePositions : ControlV5Base
|
||||
{
|
||||
protected void Page_Init (object sender, EventArgs e)
|
||||
{
|
||||
// Request control framework in Init - the Load is too late for child controls
|
||||
|
||||
((PageV5Base) this.Page).RegisterControl (EasyUIControl.Tree | EasyUIControl.DataGrid);
|
||||
}
|
||||
|
||||
protected void Page_Load (object sender, EventArgs e)
|
||||
{
|
||||
}
|
||||
|
||||
public RoleLevel Level { get; set; }
|
||||
public int OrganizationId { get; set; }
|
||||
public int GeographyId { get; set; }
|
||||
|
||||
|
||||
public enum RoleLevel
|
||||
{
|
||||
Unknown = 0,
|
||||
Systemwide,
|
||||
Organizationwide,
|
||||
SuborganizationwideDefault,
|
||||
OrganizationTop,
|
||||
SuborganizationTopDefault,
|
||||
GeographicDefault,
|
||||
Geographic
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -422,7 +422,7 @@
|
||||
<UserLevel>4</UserLevel>
|
||||
<Permissions />
|
||||
<ImageUrl>iconshock-box-cog</ImageUrl>
|
||||
<NavigateUrl>/Pages/v5/Admin/EditOrganization.aspx</NavigateUrl>
|
||||
<NavigateUrl>/Pages/v5/Admin/OrgSettings.aspx</NavigateUrl>
|
||||
<Type>Link</Type>
|
||||
<Children />
|
||||
</MainMenuItem>
|
||||
@@ -448,7 +448,7 @@
|
||||
<UserLevel>4</UserLevel>
|
||||
<Permissions />
|
||||
<ImageUrl>iconshock-battery-drill</ImageUrl>
|
||||
<NavigateUrl>/Pages/v5/Admin/Settings.aspx</NavigateUrl>
|
||||
<NavigateUrl>/Pages/v5/Admin/SystemSettings.aspx</NavigateUrl>
|
||||
<Type>Link</Type>
|
||||
<Children />
|
||||
</MainMenuItem>
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<%@ Page Title="" Language="C#" MasterPageFile="~/Master-v5.master" AutoEventWireup="true" CodeFile="EditOrganization.aspx.cs" Inherits="Swarmops.Frontend.Pages.v5.Admin.EditOrganization" %>
|
||||
<%@ Page Title="" Language="C#" MasterPageFile="~/Master-v5.master" AutoEventWireup="true" CodeFile="OrgSettings.aspx.cs" Inherits="Swarmops.Frontend.Pages.v5.Admin.OrgSettings" %>
|
||||
<%@ Import Namespace="Resources" %>
|
||||
<%@ Register tagPrefix="Swarmops5" tagName="FileUpload" src="~/Controls/v5/Base/FileUpload.ascx" %>
|
||||
<%@ Register tagPrefix="Swarmops5" tagName="DropDown" src="~/Controls/v5/Base/DropDown.ascx" %>
|
||||
+1
-1
@@ -9,7 +9,7 @@ using Swarmops.Logic.Swarm;
|
||||
|
||||
namespace Swarmops.Frontend.Pages.v5.Admin
|
||||
{
|
||||
public partial class EditOrganization : PageV5Base
|
||||
public partial class OrgSettings : PageV5Base
|
||||
{
|
||||
protected void Page_Load (object sender, EventArgs e)
|
||||
{
|
||||
@@ -1,6 +1,6 @@
|
||||
<%@ Page Title="" Language="C#" MasterPageFile="~/Master-v5.master" AutoEventWireup="true" CodeFile="Settings.aspx.cs" Inherits="Swarmops.Frontend.Pages.v5.Admin.Settings" %>
|
||||
<%@ Page Title="" Language="C#" MasterPageFile="~/Master-v5.master" AutoEventWireup="true" CodeFile="SystemSettings.aspx.cs" Inherits="Swarmops.Frontend.Pages.v5.Admin.SystemSettingsPage" %>
|
||||
<%@ Register tagPrefix="Swarmops5" tagName="AjaxTextBox" src="~/Controls/v5/Base/AjaxTextBox.ascx" %>
|
||||
<%@ Register tagPrefix="Swarmops5" tagName="TreePersonRoles" src="~/Controls/v5/Swarm/TreePersonRoles.ascx" %>
|
||||
<%@ Register tagPrefix="Swarmops5" tagName="TreePositions" src="~/Controls/v5/Swarm/TreePositions.ascx" %>
|
||||
|
||||
|
||||
<asp:Content ID="Content1" ContentPlaceHolderID="PlaceHolderHead" Runat="Server">
|
||||
@@ -30,7 +30,7 @@
|
||||
<div id="divTabs" class="easyui-tabs" data-options="tabWidth:70,tabHeight:70">
|
||||
<div title="<img src='/Images/Icons/iconshock-group-diversified-64px.png' />">
|
||||
<h2>System Administrators</h2>
|
||||
<Swarmops5:TreePersonRoles ID="TreeRoles" runat="server" />
|
||||
<Swarmops5:TreePositions ID="TreePositions" runat="server" />
|
||||
</div>
|
||||
<div title="<img src='/Images/Icons/iconshock-mail-open-64px.png' />">
|
||||
<h2>Correspondence transmission settings</h2>
|
||||
+63
-1
@@ -4,6 +4,8 @@ using System.Linq;
|
||||
using System.Web;
|
||||
using System.Web.UI;
|
||||
using System.Web.UI.WebControls;
|
||||
using Swarmops.Common.Enums;
|
||||
using Swarmops.Common.Interfaces;
|
||||
using Swarmops.Logic;
|
||||
using Swarmops.Logic.Support;
|
||||
using Swarmops.Logic.Security;
|
||||
@@ -13,10 +15,11 @@ using System.Text.RegularExpressions;
|
||||
using Swarmops.Frontend.Controls.v5.Base;
|
||||
using Swarmops.Logic.Communications;
|
||||
using Swarmops.Logic.Structure;
|
||||
using Swarmops.Logic.Swarm;
|
||||
|
||||
namespace Swarmops.Frontend.Pages.v5.Admin
|
||||
{
|
||||
public partial class Settings : PageV5Base
|
||||
public partial class SystemSettingsPage : PageV5Base // different classname to not collide with Logic.Structure.SystemSettings
|
||||
{
|
||||
protected void Page_Load(object sender, EventArgs e)
|
||||
{
|
||||
@@ -37,10 +40,69 @@ namespace Swarmops.Frontend.Pages.v5.Admin
|
||||
Localize();
|
||||
}
|
||||
|
||||
CheckSysadminsPopulated();
|
||||
|
||||
RegisterControl (EasyUIControl.Tabs);
|
||||
RegisterControl (IncludedControl.JsonParameters | IncludedControl.SwitchButton);
|
||||
}
|
||||
|
||||
private void CheckSysadminsPopulated()
|
||||
{
|
||||
Positions systemPositions = Positions.ForSystem();
|
||||
|
||||
if (systemPositions.Count == 0)
|
||||
{
|
||||
// not initalized. Initialize.
|
||||
|
||||
Positions.CreateSysadminPositions();
|
||||
systemPositions = Positions.ForSystem();
|
||||
}
|
||||
|
||||
PositionAssignments assignments = systemPositions.Assignments;
|
||||
if (assignments.Count == 0)
|
||||
{
|
||||
// The positions exist, but nothing was assigned to them.
|
||||
// Assign sysadmins as the org admins from org #1. (Grandfathering procedure.)
|
||||
|
||||
// This code can safely be removed once all the pilots can be certain to have run it.
|
||||
|
||||
Organization template = Organization.FromIdentity(1);
|
||||
string readWriteIdsString = template.Parameters.TemporaryAccessListWrite;
|
||||
string[] readWriteIdsArray = readWriteIdsString.Split(',');
|
||||
string readOnlyIdsString = template.Parameters.TemporaryAccessListRead;
|
||||
string[] readOnlyIdsArray = readWriteIdsString.Split(',');
|
||||
|
||||
Position rootSysadmin = Position.RootSysadmin;
|
||||
rootSysadmin.Assign(Person.FromIdentity(Int32.Parse(readWriteIdsArray[0])), null /*assignedby*/, null /*assignedby*/,
|
||||
"Initial sysadmin", null /*does not expire*/);
|
||||
|
||||
Positions rootChildren = rootSysadmin.Children;
|
||||
Position sysadminRW =
|
||||
rootChildren.Where (position => position.PositionType == PositionType.System_SysadminReadWrite).ToList() [0]; // should exist
|
||||
Position sysadminAssistantRO =
|
||||
rootChildren.Where (
|
||||
position => position.PositionType == PositionType.System_SysadminAssistantReadOnly).ToList()[0];
|
||||
|
||||
for (int readWriteIndex = 1; readWriteIndex < readWriteIdsArray.Length; readWriteIndex++)
|
||||
{
|
||||
sysadminRW.Assign (Person.FromIdentity (int.Parse (readWriteIdsArray[readWriteIndex])),
|
||||
null /*assignedBy*/, null /*assignedBy*/,
|
||||
"Initial sysadmin", null /*does not expire*/);
|
||||
}
|
||||
|
||||
foreach (string readOnlyPersonIdString in readOnlyIdsArray)
|
||||
{
|
||||
if (readOnlyPersonIdString != "1")
|
||||
{
|
||||
sysadminAssistantRO.Assign (Person.FromIdentity (int.Parse (readOnlyPersonIdString)),
|
||||
null /*assignedBy*/, null /*assignedBy*/,
|
||||
"Initial sysadmin assistant", null /*does not expire*/);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static string FormatSmtpAccessString (string user, string pass, string host, int port)
|
||||
{
|
||||
string result = host;
|
||||
+1
-1
@@ -44,7 +44,7 @@ Project("{E24C65DC-7377-472B-9ABA-BC803B73C61A}") = "Site5", "Site5\", "{367F36E
|
||||
Release.AspNetCompiler.ForceOverwrite = "true"
|
||||
Release.AspNetCompiler.FixedNames = "false"
|
||||
Release.AspNetCompiler.Debug = "False"
|
||||
VWDPort = "37689"
|
||||
VWDPort = "1186"
|
||||
VWDVirtualPath = "/"
|
||||
DefaultWebSiteLanguage = "Visual C#"
|
||||
EndProjectSection
|
||||
|
||||
Reference in New Issue
Block a user