Wrapping up Positions for sprint

This commit is contained in:
Rick Falkvinge
2015-05-03 11:47:16 +02:00
parent 30ee16db34
commit cf4363e5fd
9 changed files with 174 additions and 13 deletions
+1 -1
View File
@@ -14,7 +14,7 @@ namespace Swarmops.Database
/// </summary>
public static int DbVersionExpected
{
get { return 20; }
get { return 22; }
}
+3 -1
View File
@@ -17,4 +17,6 @@
0017 - Added SetCashAdvanceAmountCents procedure [RF]
0018 - Added "IsContractor" field to Payroll [RF]
0019 - Added "Acting" field to PositionAssignments [RF]
0020 - Added concurrency check to TerminatePositionAssignment [RF]
0020 - Added concurrency check to TerminatePositionAssignment [RF]
0021 - Added PositionCustomTitles and its stored procedures [RF]
0022 - Added VolunteerPositions and its stored procedures [RF]
+32
View File
@@ -0,0 +1,32 @@
CREATE TABLE `PositionCustomTitles` (
`PositionId` int(11) unsigned NOT NULL,
`CustomTitle` varchar(128) NOT NULL,
PRIMARY KEY (`PositionId`),
KEY `Index_Title` (`CustomTitle`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8
#
DROP procedure IF EXISTS `SetCustomPositionTitle`
#
CREATE PROCEDURE `SetCustomPositionTitle`(
IN positionId INT,
IN customTitle VARCHAR(128)
)
BEGIN
IF ((SELECT COUNT(*) FROM PositionCustomTitles WHERE PositionCustomTitles.PositionId = positionId) = 0)
THEN
INSERT INTO PositionCustomTitles (PositionId,CustomTitle) VALUES (positionId,customTitle);
ELSE
UPDATE PositionCustomTitles SET PositionCustomTitles.CustomTitle=customTitle WHERE PositionCustomTitles.PositionId=positionId;
END IF;
END
+60
View File
@@ -0,0 +1,60 @@
CREATE TABLE `VolunteerPositions` (
`VolunteerPositionId` INT NOT NULL AUTO_INCREMENT,
`VolunteerId` INT NOT NULL,
`PositionId` INT NOT NULL,
`GeographyId` INT NOT NULL,
`Open` TINYINT NOT NULL DEFAULT '1',
`Assigned` TINYINT NOT NULL DEFAULT '0',
PRIMARY KEY (`VolunteerPositionId`),
INDEX `Index_Position` (`PositionId` ASC),
INDEX `Index_Geography` (`GeographyId` ASC),
INDEX `Index_Open` (`Open` ASC),
INDEX `Index_Volunteer` (`VolunteerId` ASC))
#
DROP procedure IF EXISTS `CreateVolunteerPosition`
#
CREATE PROCEDURE `CreateVolunteerPosition`(
IN volunteerId INT,
IN positionId INT,
IN geographyId INT
)
BEGIN
INSERT INTO VolunteerPositions (VolunteerId,PositionId,GeographyId,Open,Assigned)
VALUES (volunteerId,positionId,geographyId,1,0);
SELECT LAST_INSERT_ID() AS Identity;
END
#
DROP procedure IF EXISTS `CloseVolunteerPosition`
#
CREATE PROCEDURE `CloseVolunteerPosition`(
volunteerPositionId INTEGER,
assigned TINYINT
)
BEGIN
UPDATE VolunteerPositions
SET VolunteerPositions.Open=0,VolunteerRoles.Assigned=assigned
WHERE VolunteerPositions.VolunteerPositionId=volunteerPositionId AND VolunteerPositions.Open=1;
SELECT ROW_COUNT() AS RowsUpdated;
END
+4 -1
View File
@@ -258,7 +258,10 @@ namespace Swarmops.Logic.Security
// Ask the current position assignment if it has the requested access
return Assignment.Position.HasAccess(access);
Position currentPosition = Assignment.Position;
currentPosition.AssignGeography (Assignment.Geography);
return currentPosition.HasAccess(access);
}
+24 -9
View File
@@ -95,24 +95,26 @@ namespace Swarmops.Logic.Structure
get { return FromIdentity (ParentIdentity); }
}
public Geographies ThisAndBelow()
public bool IsOrInherits(Geography prospectiveParent)
{
return Geographies.FromArray (GeographyCache.GetGeographyTree (Identity));
// return Geographies.FromArray(SwarmDb.GetDatabaseForReading().GetGeographyTree(Identity));
if (Identity == prospectiveParent.Identity)
return true;
return Inherits(prospectiveParent.Identity);
}
public Geographies GetRootLineage()
public bool Inherits(Geography prospectiveParent)
{
return Geographies.FromArray (GeographyCache.GetGeographyLine (Identity));
//return Geographies.FromArray(SwarmDb.GetDatabaseForReading().GetGeographyLine(Identity));
return Inherits(prospectiveParent.Identity);
}
public bool Inherits (Geography prospectiveParent)
private bool IsOrInherits(int prospectiveParentGeographyId)
{
return Inherits (prospectiveParent.Identity);
if (Identity == prospectiveParentGeographyId)
return true;
return Inherits(prospectiveParentGeographyId);
}
public bool Inherits (int prospectiveParentGeographyId)
private bool Inherits(int prospectiveParentGeographyId)
{
// Returns true if prospectiveParent is a parent of ours.
@@ -129,6 +131,19 @@ namespace Swarmops.Logic.Structure
return false;
}
public Geographies ThisAndBelow()
{
return Geographies.FromArray (GeographyCache.GetGeographyTree (Identity));
// return Geographies.FromArray(SwarmDb.GetDatabaseForReading().GetGeographyTree(Identity));
}
public Geographies GetRootLineage()
{
return Geographies.FromArray (GeographyCache.GetGeographyLine (Identity));
//return Geographies.FromArray(SwarmDb.GetDatabaseForReading().GetGeographyLine(Identity));
}
public bool AtLevel (GeographyLevel level)
{
+43
View File
@@ -213,7 +213,50 @@ namespace Swarmops.Logic.Swarm
throw new ArgumentNullException ("access", @"Access requested must always be specified. Use AccessAspect.Null if null access is desired (and access should always be true).");
}
if (this.PositionLevel == PositionLevel.SystemWide)
{
if (access.Type == AccessType.Write &&
this.PositionType == PositionType.System_SysadminAssistantReadOnly)
{
return false;
}
return true;
}
if (this.PositionLevel == PositionLevel.GeographyDefault || this.PositionLevel == PositionLevel.Geography)
{
// This Position.GeographyId has been set to the Assignments's GeographyId for this purpose
// (bad architecture, fix)
if (access.Organization.IsOrInherits (this.Organization) &&
access.Geography.IsOrInherits (this.Geography))
{
// we have an Access with applicable Org and Geo, but is the Access good enough? Cheat for now.
if (this.PositionType == PositionType.Geographic_Leader ||
this.PositionType == PositionType.Geographic_Deputy ||
this.PositionType == PositionType.Geographic_Assistant)
{
// yes, we have admin privileges and all other privileges too
return true;
}
}
// otherwise FO
return false;
}
// the positions left are at org level
if (access.Organization.IsOrInherits (this.OrganizationId))
{
// is the Position privilege sufficient to meet the Access required?
// for now, cheat and assume all positions at the Org level have Admin access
return true;
}
return false;
}
+6
View File
@@ -51,6 +51,12 @@ namespace Swarmops.Logic.Swarm
get { return Position.FromIdentity (base.PositionId); }
}
public Geography Geography
{
get { return base.GeographyId == 0 ? null : Geography.FromIdentity (base.GeographyId); }
}
public static PositionAssignment Create(Position position, Geography geography,
Person person, Person createdByPerson, Position createdByPosition, DateTime? expiresDateTimeUtc,
string assignmentNotes)
+1 -1
View File
@@ -87,7 +87,7 @@ namespace Swarmops.Utility.BotCode
{
Geography geo = membership.Person.Geography;
if (geo.Inherits (poll.GeographyId) || geo.Identity == poll.GeographyId)
if (geo.Inherits (Geography.FromIdentity(poll.GeographyId)) || geo.Identity == poll.GeographyId)
{
poll.AddVoter (membership.Person);
dupeCheck[membership.PersonId] = true;