diff --git a/Database/Configuration.cs b/Database/Configuration.cs index a69dee1e..3256b9c1 100644 --- a/Database/Configuration.cs +++ b/Database/Configuration.cs @@ -14,7 +14,7 @@ namespace Swarmops.Database /// public static int DbVersionExpected { - get { return 20; } + get { return 22; } } diff --git a/Database/Schemata/revisions.txt b/Database/Schemata/revisions.txt index f4723eb2..c3955aa1 100644 --- a/Database/Schemata/revisions.txt +++ b/Database/Schemata/revisions.txt @@ -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] \ No newline at end of file +0020 - Added concurrency check to TerminatePositionAssignment [RF] +0021 - Added PositionCustomTitles and its stored procedures [RF] +0022 - Added VolunteerPositions and its stored procedures [RF] diff --git a/Database/Schemata/upgrade-0021.sql b/Database/Schemata/upgrade-0021.sql new file mode 100644 index 00000000..80fb7078 --- /dev/null +++ b/Database/Schemata/upgrade-0021.sql @@ -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 diff --git a/Database/Schemata/upgrade-0022.sql b/Database/Schemata/upgrade-0022.sql new file mode 100644 index 00000000..036ce1e3 --- /dev/null +++ b/Database/Schemata/upgrade-0022.sql @@ -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 \ No newline at end of file diff --git a/Logic/Security/Authority.cs b/Logic/Security/Authority.cs index b8a08bd5..c4f88594 100644 --- a/Logic/Security/Authority.cs +++ b/Logic/Security/Authority.cs @@ -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); } diff --git a/Logic/Structure/Geography.cs b/Logic/Structure/Geography.cs index 72ce3a5e..a5badcec 100644 --- a/Logic/Structure/Geography.cs +++ b/Logic/Structure/Geography.cs @@ -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) { diff --git a/Logic/Swarm/Position.cs b/Logic/Swarm/Position.cs index 628931f3..78c175fb 100644 --- a/Logic/Swarm/Position.cs +++ b/Logic/Swarm/Position.cs @@ -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; } diff --git a/Logic/Swarm/PositionAssignment.cs b/Logic/Swarm/PositionAssignment.cs index c38dd32b..15ee34eb 100644 --- a/Logic/Swarm/PositionAssignment.cs +++ b/Logic/Swarm/PositionAssignment.cs @@ -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) diff --git a/Utility/BotCode/InternalPollMaintenance.cs b/Utility/BotCode/InternalPollMaintenance.cs index 884542e5..bc67855f 100644 --- a/Utility/BotCode/InternalPollMaintenance.cs +++ b/Utility/BotCode/InternalPollMaintenance.cs @@ -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;