Fixed assignment authority problem
This commit is contained in:
@@ -73,8 +73,38 @@ namespace Swarmops.Frontend.Automation
|
||||
}
|
||||
|
||||
// Deliberate: no requirement for membership (or equivalent) in order to be assigned to position.
|
||||
// Find the current user position used to assign.
|
||||
|
||||
PositionAssignments currentUserAssignments = authData.CurrentUser.PositionAssignments;
|
||||
|
||||
// Get the one this user is currently using to assign - it's either a system level position,
|
||||
// one with a parent organization (TODO), or one with this organization
|
||||
|
||||
Position activePosition = null;
|
||||
|
||||
foreach (PositionAssignment currentUserAssignment in currentUserAssignments)
|
||||
{
|
||||
if (currentUserAssignment.OrganizationId == 0 && currentUserAssignment.Active)
|
||||
{
|
||||
activePosition = currentUserAssignment.Position;
|
||||
break; // a system-level active position has priority over org-level
|
||||
}
|
||||
if (currentUserAssignment.OrganizationId == authData.CurrentOrganization.Identity &&
|
||||
currentUserAssignment.Active)
|
||||
{
|
||||
activePosition = currentUserAssignment.Position;
|
||||
}
|
||||
}
|
||||
|
||||
if (activePosition == null)
|
||||
{
|
||||
return new AjaxCallResult
|
||||
{
|
||||
Success = false,
|
||||
DisplayMessage = "Error: No authority to assign a position"
|
||||
};
|
||||
}
|
||||
|
||||
Position currentUserPosition = authData.CurrentUser.PositionAssignment.Position; // excludes acting positions. May throw!
|
||||
DateTime? expiresUtc = null;
|
||||
|
||||
if (durationMonths > 0)
|
||||
@@ -84,7 +114,7 @@ namespace Swarmops.Frontend.Automation
|
||||
|
||||
try
|
||||
{
|
||||
PositionAssignment.Create (position, geography, person, authData.CurrentUser, currentUserPosition,
|
||||
PositionAssignment.Create (position, geography, person, authData.CurrentUser, activePosition,
|
||||
expiresUtc, string.Empty);
|
||||
}
|
||||
catch (DatabaseConcurrencyException)
|
||||
|
||||
@@ -134,9 +134,18 @@
|
||||
|
||||
// TODO: Check existing position for person; can't have two positions, at least not within same org
|
||||
|
||||
var jsonData = {
|
||||
personId: personId,
|
||||
positionId: current<%=this.ClientID%>PositionId,
|
||||
durationMonths: <%= this.DropDuration.ClientID%>_val(),
|
||||
geographyId: current<%=this.ClientID%>GeographyId
|
||||
};
|
||||
|
||||
console.log(jsonData);
|
||||
|
||||
SwarmopsJS.ajaxCall(
|
||||
"/Automation/SwarmFunctions.aspx/AssignPosition",
|
||||
{ personId: personId, positionId: current<%=this.ClientID%>PositionId, durationMonths: $('#<%= this.DropDuration.ClientID%>').val(), geographyId: current<%=this.ClientID%>GeographyId },
|
||||
jsonData,
|
||||
function (result) {
|
||||
// Close modal and reload grid regardless of success or not
|
||||
// (the only failure here should be a concurrency error, in which case
|
||||
|
||||
@@ -11,6 +11,7 @@ using System.Web.Security;
|
||||
using System.Web.Services;
|
||||
using System.Web.SessionState;
|
||||
using System.Web.UI;
|
||||
using NBitcoin.Protocol;
|
||||
using Resources;
|
||||
using Swarmops.Common;
|
||||
using Swarmops.Common.Enums;
|
||||
@@ -781,12 +782,15 @@ namespace Swarmops.Frontend.Pages.v5.Public
|
||||
|
||||
SwarmDb.GetDatabaseForWriting().CreateExceptionLogEntry(DateTime.UtcNow, "Initialization", new Exception("Tracepoint 1"));
|
||||
|
||||
newPerson.AddParticipation(Organization.Sandbox, DateTime.UtcNow.AddYears(25));
|
||||
// Add membership in Sandbox
|
||||
newPerson.AddParticipation(Organization.Sandbox, DateTime.UtcNow.AddYears(25));
|
||||
|
||||
// Initialize staffing to System and Sandbox with the new user
|
||||
|
||||
Positions.CreateSysadminPositions();
|
||||
|
||||
Positions.ForOrganization(Organization.Sandbox).AtLevel(PositionLevel.OrganizationExecutive)[0].Assign(
|
||||
newPerson, null /* assignedByPerson */, null /* assignedByPosition */, "Initial Sandbox executive",
|
||||
null /* expires */);
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user