Permissions & Authorization for Users #24
Initial Release; Includes Database and MVC refactoring
This commit is contained in:
@@ -1,22 +1,19 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
using System.Web.Mvc;
|
||||
using Disco.BI;
|
||||
using Disco.BI.Extensions;
|
||||
using Disco.Data.Repository;
|
||||
using Disco.BI.Extensions;
|
||||
using Disco.Models.Repository;
|
||||
using System.Data.Objects.SqlClient;
|
||||
using Disco.Web.Extensions;
|
||||
using Disco.Services.Plugins.Features.UIExtension;
|
||||
using Disco.Models.UI.Device;
|
||||
using Disco.Services.Authorization;
|
||||
using Disco.Services.Plugins;
|
||||
using Disco.Services.Plugins.Features.UIExtension;
|
||||
using Disco.Services.Users;
|
||||
using Disco.Services.Web;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Web.Mvc;
|
||||
|
||||
|
||||
namespace Disco.Web.Controllers
|
||||
{
|
||||
public partial class DeviceController : dbAdminController
|
||||
public partial class DeviceController : AuthorizedDatabaseController
|
||||
{
|
||||
#region Index
|
||||
public virtual ActionResult Index()
|
||||
@@ -31,17 +28,24 @@ namespace Disco.Web.Controllers
|
||||
#endregion
|
||||
|
||||
#region Add Offline
|
||||
[DiscoAuthorize(Claims.Device.Actions.EnrolDevices)]
|
||||
public virtual ActionResult AddOffline()
|
||||
{
|
||||
var m = new Models.Device.AddOfflineModel()
|
||||
{
|
||||
DefaultDeviceProfileId = dbContext.DiscoConfiguration.DeviceProfiles.DefaultAddDeviceOfflineDeviceProfileId
|
||||
DefaultDeviceProfileId = Database.DiscoConfiguration.DeviceProfiles.DefaultAddDeviceOfflineDeviceProfileId
|
||||
};
|
||||
m.DeviceBatches = dbContext.DeviceBatches.ToList();
|
||||
m.DeviceProfiles = dbContext.DeviceProfiles.ToList();
|
||||
if (m.DefaultDeviceProfileId == 0)
|
||||
|
||||
if (Authorization.Has(Claims.Device.Properties.DeviceBatch))
|
||||
m.DeviceBatches = Database.DeviceBatches.ToList();
|
||||
|
||||
if (Authorization.Has(Claims.Device.Properties.DeviceProfile))
|
||||
{
|
||||
m.DeviceProfiles.Insert(0, new DeviceProfile() { Id = 0, Name = "Select a Device Profile" });
|
||||
m.DeviceProfiles = Database.DeviceProfiles.ToList();
|
||||
if (m.DefaultDeviceProfileId == 0)
|
||||
{
|
||||
m.DeviceProfiles.Insert(0, new DeviceProfile() { Id = 0, Name = "Select a Device Profile" });
|
||||
}
|
||||
}
|
||||
|
||||
// UI Extensions
|
||||
@@ -49,7 +53,7 @@ namespace Disco.Web.Controllers
|
||||
|
||||
return View(m);
|
||||
}
|
||||
[HttpPost]
|
||||
[DiscoAuthorize(Claims.Device.Actions.EnrolDevices), HttpPost]
|
||||
public virtual ActionResult AddOffline(Models.Device.AddOfflineModel m)
|
||||
{
|
||||
// Trim Serial Number & Error Check
|
||||
@@ -61,15 +65,14 @@ namespace Disco.Web.Controllers
|
||||
else
|
||||
{
|
||||
// Ensure Existing Device Doesn't Exist
|
||||
if (!string.IsNullOrEmpty(m.Device.SerialNumber) && dbContext.Devices.Count(d => d.SerialNumber == m.Device.SerialNumber) > 0)
|
||||
if (!string.IsNullOrEmpty(m.Device.SerialNumber) && Database.Devices.Count(d => d.SerialNumber == m.Device.SerialNumber) > 0)
|
||||
ModelState.AddModelError("Device.SerialNumber", "A Device what this Serial Number already exists");
|
||||
}
|
||||
|
||||
|
||||
if (ModelState.IsValid)
|
||||
{
|
||||
var d = m.Device.AddOffline(dbContext);
|
||||
dbContext.SaveChanges();
|
||||
var d = m.Device.AddOffline(Database);
|
||||
Database.SaveChanges();
|
||||
return RedirectToAction(MVC.Device.Show(d.SerialNumber));
|
||||
}
|
||||
return AddOffline();
|
||||
@@ -77,21 +80,24 @@ namespace Disco.Web.Controllers
|
||||
#endregion
|
||||
|
||||
#region Import/Export
|
||||
[HttpGet]
|
||||
[DiscoAuthorizeAny(Claims.Device.Actions.Import, Claims.Device.Actions.Export), HttpGet]
|
||||
public virtual ActionResult ImportExport()
|
||||
{
|
||||
Models.Device.ImportModel m = new Models.Device.ImportModel();
|
||||
|
||||
m.DeviceModels = dbContext.DeviceModels.ToList();
|
||||
m.DeviceProfiles = dbContext.DeviceProfiles.ToList();
|
||||
m.DeviceBatches = dbContext.DeviceBatches.ToList();
|
||||
if (Authorization.Has(Claims.Device.Actions.Import))
|
||||
{
|
||||
m.DeviceModels = Database.DeviceModels.ToList();
|
||||
m.DeviceProfiles = Database.DeviceProfiles.ToList();
|
||||
m.DeviceBatches = Database.DeviceBatches.ToList();
|
||||
}
|
||||
|
||||
// UI Extensions
|
||||
UIExtensions.ExecuteExtensions<DeviceImportModel>(this.ControllerContext, m);
|
||||
|
||||
return View(m);
|
||||
}
|
||||
[HttpGet]
|
||||
[DiscoAuthorize(Claims.Device.Actions.Import), HttpGet]
|
||||
public virtual ActionResult ImportReview(string ImportParseTaskId)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(ImportParseTaskId))
|
||||
@@ -112,25 +118,20 @@ namespace Disco.Web.Controllers
|
||||
#endregion
|
||||
|
||||
#region Show
|
||||
[DiscoAuthorize(Claims.Device.Show)]
|
||||
public virtual ActionResult Show(string id)
|
||||
{
|
||||
var m = new Models.Device.ShowModel();
|
||||
|
||||
dbContext.Configuration.LazyLoadingEnabled = true;
|
||||
Database.Configuration.LazyLoadingEnabled = true;
|
||||
|
||||
m.Device = dbContext.Devices.Include("DeviceDetails")
|
||||
.Where(d => d.SerialNumber == id)
|
||||
.FirstOrDefault();
|
||||
m.Device = Database.Devices
|
||||
.Include("DeviceModel").Include("DeviceDetails").Include("DeviceUserAssignments.AssignedUser").Include("DeviceAttachments")
|
||||
.FirstOrDefault(d => d.SerialNumber == id);
|
||||
|
||||
if (m.Device == null)
|
||||
throw new ArgumentException(string.Format("Unknown Device: [{0}]", id), "id");
|
||||
|
||||
// Removed 2012-07-03 G#
|
||||
// Deferred to Ajax call - improve load performance
|
||||
// Update Device LastNetworkLogonDate
|
||||
//if (m.Device.UpdateLastNetworkLogonDate())
|
||||
// dbContext.SaveChanges();
|
||||
|
||||
// No Necessary - Yet...
|
||||
//if (!string.IsNullOrWhiteSpace(m.Device.ComputerName))
|
||||
//{
|
||||
@@ -141,27 +142,32 @@ namespace Disco.Web.Controllers
|
||||
// }
|
||||
//}
|
||||
|
||||
m.DeviceProfiles = dbContext.DeviceProfiles.ToList();
|
||||
if (Authorization.Has(Claims.Device.Properties.DeviceProfile))
|
||||
m.DeviceProfiles = Database.DeviceProfiles.ToList();
|
||||
|
||||
m.DeviceBatches = dbContext.DeviceBatches.ToList();
|
||||
if (Authorization.Has(Claims.Device.Properties.DeviceBatch))
|
||||
m.DeviceBatches = Database.DeviceBatches.ToList();
|
||||
|
||||
m.Jobs = new Disco.Models.BI.Job.JobTableModel()
|
||||
if (Authorization.Has(Claims.Device.ShowJobs))
|
||||
{
|
||||
ShowStatus = true,
|
||||
ShowDevice = false,
|
||||
IsSmallTable = false,
|
||||
HideClosedJobs = true,
|
||||
EnablePaging = false
|
||||
};
|
||||
m.Jobs.Fill(dbContext, BI.JobBI.Searching.BuildJobTableModel(dbContext).Where(j => j.DeviceSerialNumber == m.Device.SerialNumber).OrderByDescending(j => j.Id));
|
||||
m.Jobs = new Disco.Models.BI.Job.JobTableModel()
|
||||
{
|
||||
ShowStatus = true,
|
||||
ShowDevice = false,
|
||||
IsSmallTable = false,
|
||||
HideClosedJobs = true,
|
||||
EnablePaging = false
|
||||
};
|
||||
m.Jobs.Fill(Database, BI.JobBI.Searching.BuildJobTableModel(Database).Where(j => j.DeviceSerialNumber == m.Device.SerialNumber).OrderByDescending(j => j.Id));
|
||||
}
|
||||
|
||||
m.Certificates = dbContext.DeviceCertificates.Where(c => c.DeviceSerialNumber == m.Device.SerialNumber).ToList();
|
||||
if (Authorization.Has(Claims.Device.ShowCertificates))
|
||||
m.Certificates = Database.DeviceCertificates.Where(c => c.DeviceSerialNumber == m.Device.SerialNumber).ToList();
|
||||
|
||||
//m.AttachmentTypes = dbContext.AttachmentTypes.Where(at => at.Scope == AttachmentType.AttachmentTypeScopes.Device).ToList();
|
||||
m.DocumentTemplates = m.Device.AvailableDocumentTemplates(dbContext, DiscoApplication.CurrentUser, DateTime.Now);
|
||||
|
||||
m.DeviceProfileDefaultOrganisationAddress = m.Device.DeviceProfile.DefaultOrganisationAddressDetails(dbContext);
|
||||
if (Authorization.Has(Claims.Device.Actions.GenerateDocuments))
|
||||
m.DocumentTemplates = m.Device.AvailableDocumentTemplates(Database, UserService.CurrentUser, DateTime.Now);
|
||||
|
||||
m.DeviceProfileDefaultOrganisationAddress = m.Device.DeviceProfile.DefaultOrganisationAddressDetails(Database);
|
||||
|
||||
PluginFeatureManifest deviceProfileCertificateProvider;
|
||||
if (Disco.Services.Plugins.Plugins.TryGetPluginFeature(m.Device.DeviceProfile.CertificateProviderId, out deviceProfileCertificateProvider))
|
||||
|
||||
@@ -159,10 +159,10 @@ namespace Disco.Web.Controllers
|
||||
// Save Connection String
|
||||
//Disco.Data.Repository.DiscoDatabaseConnectionFactory.SetDiscoDataContextConnectionString(model.ToConnectionString().ToString(), true);
|
||||
// Write Organisation Name into DB
|
||||
using (DiscoDataContext db = new DiscoDataContext())
|
||||
using (DiscoDataContext database = new DiscoDataContext())
|
||||
{
|
||||
db.DiscoConfiguration.OrganisationName = DiscoApplication.OrganisationName;
|
||||
db.SaveChanges();
|
||||
database.DiscoConfiguration.OrganisationName = DiscoApplication.OrganisationName;
|
||||
database.SaveChanges();
|
||||
}
|
||||
|
||||
return RedirectToAction(MVC.InitialConfig.FileStore());
|
||||
@@ -180,8 +180,8 @@ namespace Disco.Web.Controllers
|
||||
string FileStoreLocation = null;
|
||||
try
|
||||
{
|
||||
using (DiscoDataContext db = new DiscoDataContext())
|
||||
FileStoreLocation = db.ConfigurationItems.Where(ci => ci.Scope == "System" && ci.Key == "DataStoreLocation").Select(ci => ci.Value).FirstOrDefault();
|
||||
using (DiscoDataContext database = new DiscoDataContext())
|
||||
FileStoreLocation = database.ConfigurationItems.Where(ci => ci.Scope == "System" && ci.Key == "DataStoreLocation").Select(ci => ci.Value).FirstOrDefault();
|
||||
}
|
||||
catch (Exception) { } // Ignore All Errors
|
||||
|
||||
@@ -205,12 +205,12 @@ namespace Disco.Web.Controllers
|
||||
if (ModelState.IsValid)
|
||||
{
|
||||
// Ensure Path Exists
|
||||
using (DiscoDataContext db = new DiscoDataContext())
|
||||
using (DiscoDataContext database = new DiscoDataContext())
|
||||
{
|
||||
var configItem = db.ConfigurationItems.Where(ci => ci.Scope == "System" && ci.Key == "DataStoreLocation").FirstOrDefault();
|
||||
var configItem = database.ConfigurationItems.Where(ci => ci.Scope == "System" && ci.Key == "DataStoreLocation").FirstOrDefault();
|
||||
if (configItem == null)
|
||||
{ // Create Config
|
||||
db.ConfigurationItems.Add(new Disco.Models.Repository.ConfigurationItem()
|
||||
database.ConfigurationItems.Add(new Disco.Models.Repository.ConfigurationItem()
|
||||
{
|
||||
Scope = "System",
|
||||
Key = "DataStoreLocation",
|
||||
@@ -221,7 +221,7 @@ namespace Disco.Web.Controllers
|
||||
{ // Update Config
|
||||
configItem.Value = m.FileStoreLocation;
|
||||
}
|
||||
db.SaveChanges();
|
||||
database.SaveChanges();
|
||||
}
|
||||
|
||||
// Extract DataStore Template into FileStore
|
||||
|
||||
@@ -1,23 +1,21 @@
|
||||
using System;
|
||||
using Disco.BI.Extensions;
|
||||
using Disco.BI.JobBI;
|
||||
using Disco.Models.Repository;
|
||||
using Disco.Models.UI.Job;
|
||||
using Disco.Services.Authorization;
|
||||
using Disco.Services.Plugins.Features.UIExtension;
|
||||
using Disco.Services.Plugins.Features.WarrantyProvider;
|
||||
using Disco.Services.Users;
|
||||
using Disco.Services.Web;
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
using System.Web.Mvc;
|
||||
using Disco.Data.Repository;
|
||||
using Disco.BI;
|
||||
using Disco.BI.Extensions;
|
||||
using Disco.Models.Repository;
|
||||
using System.Web.Script.Serialization;
|
||||
using Disco.Services.Plugins.Features.WarrantyProvider;
|
||||
using Disco.Services.Plugins;
|
||||
using Disco.Models.UI.Job;
|
||||
using Disco.Services.Plugins.Features.UIExtension;
|
||||
using Disco.BI.JobBI;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Disco.Web.Controllers
|
||||
{
|
||||
public partial class JobController : dbAdminController
|
||||
public partial class JobController : AuthorizedDatabaseController
|
||||
{
|
||||
|
||||
#region Index
|
||||
@@ -47,7 +45,7 @@ namespace Disco.Web.Controllers
|
||||
&& (j.DeviceHeld == null || j.DeviceReturnedDate != null || j.DeviceReadyForReturn == null)),
|
||||
SortFunction = q => q.OrderBy(j => j.Id),
|
||||
ShowStatus = true
|
||||
}.Initialize(dbContext);
|
||||
}.Initialize(Database);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -65,14 +63,17 @@ namespace Disco.Web.Controllers
|
||||
FilterFunction = q => q.Where(j => j.ClosedDate == null && j.OpenedDate < longRunningThreshold),
|
||||
SortFunction = q => q.OrderBy(j => j.Id),
|
||||
ShowStatus = true
|
||||
}.Initialize(dbContext);
|
||||
}.Initialize(Database);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
m.OpenJobs = jobList_OpenJobs;
|
||||
m.LongRunningJobs = jobList_LongRunning;
|
||||
m.DailyOpenedClosedStatistics = Disco.BI.JobBI.Statistics.DailyOpenedClosed.Data(dbContext, true);
|
||||
if (Authorization.Has(Claims.Job.Lists.AwaitingTechnicianAction))
|
||||
m.OpenJobs = jobList_OpenJobs;
|
||||
if (Authorization.Has(Claims.Job.Lists.LongRunningJobs))
|
||||
m.LongRunningJobs = jobList_LongRunning;
|
||||
if (Authorization.Has(Claims.Job.ShowDailyChart))
|
||||
m.DailyOpenedClosedStatistics = Disco.BI.JobBI.Statistics.DailyOpenedClosed.Data(Database, true);
|
||||
|
||||
// UI Extensions
|
||||
UIExtensions.ExecuteExtensions<JobIndexModel>(this.ControllerContext, m);
|
||||
@@ -82,24 +83,27 @@ namespace Disco.Web.Controllers
|
||||
#endregion
|
||||
|
||||
#region Lists
|
||||
[DiscoAuthorize(Claims.Job.Lists.AllOpen)]
|
||||
public virtual ActionResult AllOpen()
|
||||
{
|
||||
dbContext.Configuration.LazyLoadingEnabled = true;
|
||||
Database.Configuration.LazyLoadingEnabled = true;
|
||||
var m = new Models.Job.ListModel() { Title = "All Open Jobs" };
|
||||
m.JobTable = new Disco.Models.BI.Job.JobTableModel() { ShowStatus = true };
|
||||
m.JobTable.Fill(dbContext, BI.JobBI.Searching.BuildJobTableModel(dbContext).Where(j => j.ClosedDate == null).OrderBy(j => j.Id));
|
||||
m.JobTable.Fill(Database, BI.JobBI.Searching.BuildJobTableModel(Database).Where(j => j.ClosedDate == null).OrderBy(j => j.Id));
|
||||
|
||||
// UI Extensions
|
||||
UIExtensions.ExecuteExtensions<JobListModel>(this.ControllerContext, m);
|
||||
|
||||
return View(Views.List, m);
|
||||
}
|
||||
|
||||
[DiscoAuthorize(Claims.Job.Lists.DevicesReadyForReturn)]
|
||||
public virtual ActionResult DevicesReadyForReturn()
|
||||
{
|
||||
dbContext.Configuration.LazyLoadingEnabled = true;
|
||||
Database.Configuration.LazyLoadingEnabled = true;
|
||||
var m = new Models.Job.ListModel() { Title = "Jobs with Devices Ready for Return" };
|
||||
m.JobTable = new Disco.Models.BI.Job.JobTableModel() { ShowStatus = true };
|
||||
m.JobTable.Fill(dbContext, BI.JobBI.Searching.BuildJobTableModel(dbContext).Where(j => !j.WaitingForUserAction.HasValue
|
||||
m.JobTable.Fill(Database, BI.JobBI.Searching.BuildJobTableModel(Database).Where(j => !j.WaitingForUserAction.HasValue
|
||||
&& j.DeviceHeld != null && j.DeviceReturnedDate == null && j.DeviceReadyForReturn != null &&
|
||||
((!j.JobMetaNonWarranty.AccountingChargeRequiredDate.HasValue && !j.JobMetaNonWarranty.AccountingChargeAddedDate.HasValue) || j.JobMetaNonWarranty.AccountingChargePaidDate.HasValue)
|
||||
&& j.ClosedDate == null).OrderBy(j => j.Id));
|
||||
@@ -109,12 +113,14 @@ namespace Disco.Web.Controllers
|
||||
|
||||
return View(Views.List, m);
|
||||
}
|
||||
|
||||
[DiscoAuthorize(Claims.Job.Lists.DevicesAwaitingRepair)]
|
||||
public virtual ActionResult DevicesAwaitingRepair()
|
||||
{
|
||||
dbContext.Configuration.LazyLoadingEnabled = true;
|
||||
Database.Configuration.LazyLoadingEnabled = true;
|
||||
var m = new Models.Job.ListModel() { Title = "Jobs with Devices Awaiting Repair" };
|
||||
m.JobTable = new Disco.Models.BI.Job.JobTableModel() { ShowStatus = true };
|
||||
m.JobTable.Fill(dbContext, BI.JobBI.Searching.BuildJobTableModel(dbContext).Where(j => j.ClosedDate == null &&
|
||||
m.JobTable.Fill(Database, BI.JobBI.Searching.BuildJobTableModel(Database).Where(j => j.ClosedDate == null &&
|
||||
(
|
||||
(j.JobMetaNonWarranty.RepairerLoggedDate != null && j.JobMetaNonWarranty.RepairerCompletedDate == null) ||
|
||||
(j.JobMetaWarranty.ExternalLoggedDate != null && j.JobMetaWarranty.ExternalCompletedDate == null)
|
||||
@@ -127,12 +133,13 @@ namespace Disco.Web.Controllers
|
||||
}
|
||||
|
||||
#region "Finance Lists"
|
||||
[DiscoAuthorize(Claims.Job.Lists.AwaitingFinance)]
|
||||
public virtual ActionResult AwaitingFinance()
|
||||
{
|
||||
dbContext.Configuration.LazyLoadingEnabled = true;
|
||||
Database.Configuration.LazyLoadingEnabled = true;
|
||||
var m = new Models.Job.ListModel() { Title = "Jobs Awaiting Finance" };
|
||||
m.JobTable = new Disco.Models.BI.Job.JobTableModel() { ShowStatus = true };
|
||||
m.JobTable.Fill(dbContext, BI.JobBI.Searching.BuildJobTableModel(dbContext).Where(j => j.ClosedDate == null &&
|
||||
m.JobTable.Fill(Database, BI.JobBI.Searching.BuildJobTableModel(Database).Where(j => j.ClosedDate == null &&
|
||||
(
|
||||
(j.JobTypeId == JobType.JobTypeIds.HNWar && (j.JobMetaNonWarranty.IsInsuranceClaim && !j.JobMetaInsurance.ClaimFormSentDate.HasValue)) ||
|
||||
(j.JobTypeId == JobType.JobTypeIds.HNWar && (j.JobMetaNonWarranty.AccountingChargeRequiredDate.HasValue && (!j.JobMetaNonWarranty.AccountingChargeAddedDate.HasValue && !j.JobMetaNonWarranty.AccountingChargePaidDate.HasValue))) ||
|
||||
@@ -146,12 +153,13 @@ namespace Disco.Web.Controllers
|
||||
return View(Views.List, m);
|
||||
}
|
||||
|
||||
[DiscoAuthorizeAll(Claims.Job.Lists.AwaitingFinance, Claims.Job.Lists.AwaitingFinanceCharge)]
|
||||
public virtual ActionResult AwaitingFinanceCharge()
|
||||
{
|
||||
dbContext.Configuration.LazyLoadingEnabled = true;
|
||||
Database.Configuration.LazyLoadingEnabled = true;
|
||||
var m = new Models.Job.ListModel() { Title = "Jobs Awaiting Finance - Accounting Charge" };
|
||||
m.JobTable = new Disco.Models.BI.Job.JobTableModel() { ShowStatus = true };
|
||||
m.JobTable.Fill(dbContext, BI.JobBI.Searching.BuildJobTableModel(dbContext).Where(j => j.ClosedDate == null &&
|
||||
m.JobTable.Fill(Database, BI.JobBI.Searching.BuildJobTableModel(Database).Where(j => j.ClosedDate == null &&
|
||||
(j.JobTypeId == JobType.JobTypeIds.HNWar && (j.JobMetaNonWarranty.AccountingChargeRequiredDate.HasValue && (!j.JobMetaNonWarranty.AccountingChargeAddedDate.HasValue && !j.JobMetaNonWarranty.AccountingChargePaidDate.HasValue)))
|
||||
).OrderBy(j => j.Id));
|
||||
|
||||
@@ -160,12 +168,14 @@ namespace Disco.Web.Controllers
|
||||
|
||||
return View(Views.List, m);
|
||||
}
|
||||
|
||||
[DiscoAuthorizeAll(Claims.Job.Lists.AwaitingFinance, Claims.Job.Lists.AwaitingFinancePayment)]
|
||||
public virtual ActionResult AwaitingFinancePayment()
|
||||
{
|
||||
dbContext.Configuration.LazyLoadingEnabled = true;
|
||||
Database.Configuration.LazyLoadingEnabled = true;
|
||||
var m = new Models.Job.ListModel() { Title = "Jobs Awaiting Finance - Accounting Payment" };
|
||||
m.JobTable = new Disco.Models.BI.Job.JobTableModel() { ShowStatus = true };
|
||||
m.JobTable.Fill(dbContext, BI.JobBI.Searching.BuildJobTableModel(dbContext).Where(j => j.ClosedDate == null &&
|
||||
m.JobTable.Fill(Database, BI.JobBI.Searching.BuildJobTableModel(Database).Where(j => j.ClosedDate == null &&
|
||||
(j.JobTypeId == JobType.JobTypeIds.HNWar && (!j.JobMetaNonWarranty.AccountingChargeAddedDate.HasValue || !j.JobMetaNonWarranty.AccountingChargePaidDate.HasValue))
|
||||
).OrderBy(j => j.Id));
|
||||
|
||||
@@ -174,12 +184,14 @@ namespace Disco.Web.Controllers
|
||||
|
||||
return View(Views.List, m);
|
||||
}
|
||||
|
||||
[DiscoAuthorizeAll(Claims.Job.Lists.AwaitingFinance, Claims.Job.Lists.AwaitingFinanceInsuranceProcessing)]
|
||||
public virtual ActionResult AwaitingFinanceInsuranceProcessing()
|
||||
{
|
||||
dbContext.Configuration.LazyLoadingEnabled = true;
|
||||
Database.Configuration.LazyLoadingEnabled = true;
|
||||
var m = new Models.Job.ListModel() { Title = "Jobs Awaiting Finance - Insurance Processing" };
|
||||
m.JobTable = new Disco.Models.BI.Job.JobTableModel() { ShowStatus = true };
|
||||
m.JobTable.Fill(dbContext, BI.JobBI.Searching.BuildJobTableModel(dbContext).Where(j => j.ClosedDate == null &&
|
||||
m.JobTable.Fill(Database, BI.JobBI.Searching.BuildJobTableModel(Database).Where(j => j.ClosedDate == null &&
|
||||
(j.JobTypeId == JobType.JobTypeIds.HNWar && (j.JobMetaNonWarranty.IsInsuranceClaim && !j.JobMetaInsurance.ClaimFormSentDate.HasValue))
|
||||
).OrderBy(j => j.Id));
|
||||
|
||||
@@ -188,12 +200,14 @@ namespace Disco.Web.Controllers
|
||||
|
||||
return View(Views.List, m);
|
||||
}
|
||||
|
||||
[DiscoAuthorizeAll(Claims.Job.Lists.AwaitingFinance, Claims.Job.Lists.AwaitingFinanceAgreementBreach)]
|
||||
public virtual ActionResult AwaitingFinanceAgreementBreach()
|
||||
{
|
||||
dbContext.Configuration.LazyLoadingEnabled = true;
|
||||
Database.Configuration.LazyLoadingEnabled = true;
|
||||
var m = new Models.Job.ListModel() { Title = "Jobs Awaiting Finance - Agreement Breach" };
|
||||
m.JobTable = new Disco.Models.BI.Job.JobTableModel() { ShowStatus = true };
|
||||
m.JobTable.Fill(dbContext, BI.JobBI.Searching.BuildJobTableModel(dbContext).Where(j => j.ClosedDate == null &&
|
||||
m.JobTable.Fill(Database, BI.JobBI.Searching.BuildJobTableModel(Database).Where(j => j.ClosedDate == null &&
|
||||
(j.JobTypeId == JobType.JobTypeIds.UMgmt && Job.UserManagementFlags.Infringement_BreachFinancialAgreement == (j.Flags & Job.UserManagementFlags.Infringement_BreachFinancialAgreement))
|
||||
).OrderBy(j => j.Id));
|
||||
|
||||
@@ -202,15 +216,15 @@ namespace Disco.Web.Controllers
|
||||
|
||||
return View(Views.List, m);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
[DiscoAuthorize(Claims.Job.Lists.AwaitingUserAction)]
|
||||
public virtual ActionResult AwaitingUserAction()
|
||||
{
|
||||
dbContext.Configuration.LazyLoadingEnabled = true;
|
||||
Database.Configuration.LazyLoadingEnabled = true;
|
||||
var m = new Models.Job.ListModel() { Title = "Jobs Awaiting User Action" };
|
||||
m.JobTable = new Disco.Models.BI.Job.JobTableModel() { ShowStatus = true };
|
||||
m.JobTable.Fill(dbContext, BI.JobBI.Searching.BuildJobTableModel(dbContext).Where(j => (j.WaitingForUserAction.HasValue || (j.JobMetaNonWarranty.AccountingChargeAddedDate != null && j.JobMetaNonWarranty.AccountingChargePaidDate == null))
|
||||
m.JobTable.Fill(Database, BI.JobBI.Searching.BuildJobTableModel(Database).Where(j => (j.WaitingForUserAction.HasValue || (j.JobMetaNonWarranty.AccountingChargeAddedDate != null && j.JobMetaNonWarranty.AccountingChargePaidDate == null))
|
||||
&& j.ClosedDate == null).OrderBy(j => j.Id));
|
||||
|
||||
// UI Extensions
|
||||
@@ -218,9 +232,11 @@ namespace Disco.Web.Controllers
|
||||
|
||||
return View(Views.List, m);
|
||||
}
|
||||
|
||||
[DiscoAuthorize(Claims.Job.Lists.RecentlyClosed)]
|
||||
public virtual ActionResult RecentlyClosed()
|
||||
{
|
||||
dbContext.Configuration.LazyLoadingEnabled = true;
|
||||
Database.Configuration.LazyLoadingEnabled = true;
|
||||
var m = new Models.Job.ListModel() { Title = "Recently Closed Jobs" };
|
||||
m.JobTable = new Disco.Models.BI.Job.JobTableModel() { ShowStatus = true };
|
||||
|
||||
@@ -230,19 +246,21 @@ namespace Disco.Web.Controllers
|
||||
closedThreshold = closedThreshold.AddDays(-2);
|
||||
if (dateTimeNow.DayOfWeek == DayOfWeek.Tuesday)
|
||||
closedThreshold = closedThreshold.AddDays(-1);
|
||||
m.JobTable.Fill(dbContext, BI.JobBI.Searching.BuildJobTableModel(dbContext).Where(j => j.ClosedDate > closedThreshold).OrderBy(j => j.Id));
|
||||
m.JobTable.Fill(Database, BI.JobBI.Searching.BuildJobTableModel(Database).Where(j => j.ClosedDate > closedThreshold).OrderBy(j => j.Id));
|
||||
|
||||
// UI Extensions
|
||||
UIExtensions.ExecuteExtensions<JobListModel>(this.ControllerContext, m);
|
||||
|
||||
return View(Views.List, m);
|
||||
}
|
||||
|
||||
[DiscoAuthorize(Claims.Job.Lists.Locations)]
|
||||
public virtual ActionResult Locations()
|
||||
{
|
||||
dbContext.Configuration.LazyLoadingEnabled = true;
|
||||
Database.Configuration.LazyLoadingEnabled = true;
|
||||
var m = new Models.Job.ListModel() { Title = "Held Device Locations" };
|
||||
m.JobTable = new Disco.Models.BI.Job.JobTableModel() { ShowStatus = true, ShowLocation = true, ShowTechnician = false, ShowType = false };
|
||||
m.JobTable.Fill(dbContext, BI.JobBI.Searching.BuildJobTableModel(dbContext).Where(j => j.ClosedDate == null && j.DeviceHeld.HasValue && !j.DeviceReturnedDate.HasValue).OrderBy(j => j.DeviceHeldLocation));
|
||||
m.JobTable.Fill(Database, BI.JobBI.Searching.BuildJobTableModel(Database).Where(j => j.ClosedDate == null && j.DeviceHeld.HasValue && !j.DeviceReturnedDate.HasValue).OrderBy(j => j.DeviceHeldLocation));
|
||||
|
||||
// UI Extensions
|
||||
UIExtensions.ExecuteExtensions<JobListModel>(this.ControllerContext, m);
|
||||
@@ -253,23 +271,57 @@ namespace Disco.Web.Controllers
|
||||
#endregion
|
||||
|
||||
#region Show
|
||||
[DiscoAuthorize(Claims.Job.Show)]
|
||||
public virtual ActionResult Show(int? id)
|
||||
{
|
||||
if (!id.HasValue)
|
||||
return RedirectToAction(MVC.Job.Index());
|
||||
|
||||
dbContext.Configuration.LazyLoadingEnabled = true;
|
||||
Database.Configuration.LazyLoadingEnabled = true;
|
||||
|
||||
var m = new Models.Job.ShowModel();
|
||||
|
||||
m.Job = (from j in dbContext.Jobs.Include("Device.DeviceModel").Include("Device.DeviceBatch").Include("DeviceHeldTechUser").Include("DeviceReadyForReturnTechUser").Include("DeviceReturnedTechUser")
|
||||
m.Job = (from j in Database.Jobs.Include("Device.DeviceModel").Include("Device.DeviceBatch").Include("DeviceHeldTechUser").Include("DeviceReadyForReturnTechUser").Include("DeviceReturnedTechUser")
|
||||
.Include("OpenedTechUser").Include("ClosedTechUser").Include("JobType").Include("JobSubTypes").Include("User").Include("JobLogs.TechUser")
|
||||
where (j.Id == id.Value)
|
||||
select j).FirstOrDefault();
|
||||
|
||||
m.UpdatableJobSubTypes = m.Job.JobType.JobSubTypes.OrderBy(jst => jst.Description).ToList();
|
||||
if (m.Job == null)
|
||||
throw new ArgumentException(string.Format("Unknown Job: [{0}]", id), "id");
|
||||
|
||||
m.AvailableDocumentTemplates = m.Job.AvailableDocumentTemplates(dbContext, DiscoApplication.CurrentUser, DateTime.Now);
|
||||
// Validate Authorization
|
||||
switch (m.Job.JobTypeId)
|
||||
{
|
||||
case JobType.JobTypeIds.HMisc:
|
||||
Authorization.Require(Claims.Job.Types.ShowHMisc);
|
||||
break;
|
||||
case JobType.JobTypeIds.HNWar:
|
||||
Authorization.Require(Claims.Job.Types.ShowHNWar);
|
||||
break;
|
||||
case JobType.JobTypeIds.HWar:
|
||||
Authorization.Require(Claims.Job.Types.ShowHWar);
|
||||
break;
|
||||
case JobType.JobTypeIds.SApp:
|
||||
Authorization.Require(Claims.Job.Types.ShowSApp);
|
||||
break;
|
||||
case JobType.JobTypeIds.SImg:
|
||||
Authorization.Require(Claims.Job.Types.ShowSImg);
|
||||
break;
|
||||
case JobType.JobTypeIds.SOS:
|
||||
Authorization.Require(Claims.Job.Types.ShowSOS);
|
||||
break;
|
||||
case JobType.JobTypeIds.UMgmt:
|
||||
Authorization.Require(Claims.Job.Types.ShowUMgmt);
|
||||
break;
|
||||
default:
|
||||
throw new InvalidOperationException("Unknown JobType");
|
||||
}
|
||||
|
||||
if (Authorization.Has(Claims.Job.Actions.UpdateSubTypes))
|
||||
m.UpdatableJobSubTypes = m.Job.JobType.JobSubTypes.OrderBy(jst => jst.Description).ToList();
|
||||
|
||||
if (Authorization.Has(Claims.Job.Actions.GenerateDocuments))
|
||||
m.AvailableDocumentTemplates = m.Job.AvailableDocumentTemplates(Database, UserService.CurrentUser, DateTime.Now);
|
||||
|
||||
// UI Extensions
|
||||
UIExtensions.ExecuteExtensions<JobShowModel>(this.ControllerContext, m);
|
||||
@@ -279,6 +331,7 @@ namespace Disco.Web.Controllers
|
||||
#endregion
|
||||
|
||||
#region Create
|
||||
[DiscoAuthorize(Claims.Job.Actions.Create)]
|
||||
public virtual ActionResult Create(string DeviceSerialNumber, string UserId)
|
||||
{
|
||||
var m = new Models.Job.CreateModel()
|
||||
@@ -286,17 +339,17 @@ namespace Disco.Web.Controllers
|
||||
DeviceSerialNumber = DeviceSerialNumber,
|
||||
UserId = UserId
|
||||
};
|
||||
m.UpdateModel(dbContext);
|
||||
m.UpdateModel(Database);
|
||||
|
||||
// UI Extensions
|
||||
UIExtensions.ExecuteExtensions<JobCreateModel>(this.ControllerContext, m);
|
||||
|
||||
return View(m);
|
||||
}
|
||||
[HttpPost]
|
||||
[HttpPost, DiscoAuthorize(Claims.Job.Actions.Create)]
|
||||
public virtual ActionResult Create(Models.Job.CreateModel m)
|
||||
{
|
||||
m.UpdateModel(dbContext);
|
||||
m.UpdateModel(Database);
|
||||
|
||||
if (!ModelState.IsValid)
|
||||
{
|
||||
@@ -308,8 +361,8 @@ namespace Disco.Web.Controllers
|
||||
else
|
||||
{
|
||||
// Create New Job
|
||||
var currentUser = dbContext.Users.Find(DiscoApplication.CurrentUser.Id);
|
||||
var j = BI.JobBI.Utilities.Create(dbContext, m.Device, m.User, m.GetJobType, m.GetJobSubTypes, currentUser);
|
||||
var currentUser = Database.Users.Find(UserService.CurrentUserId);
|
||||
var j = BI.JobBI.Utilities.Create(Database, m.Device, m.User, m.GetJobType, m.GetJobSubTypes, currentUser);
|
||||
|
||||
if (m.DeviceHeld.Value)
|
||||
{
|
||||
@@ -342,10 +395,10 @@ namespace Disco.Web.Controllers
|
||||
Timestamp = DateTime.Now,
|
||||
Comments = m.Comments
|
||||
};
|
||||
dbContext.JobLogs.Add(jl);
|
||||
Database.JobLogs.Add(jl);
|
||||
}
|
||||
|
||||
dbContext.SaveChanges();
|
||||
Database.SaveChanges();
|
||||
|
||||
// Return Dialog Redirect
|
||||
var redirectModel = new Models.Job.CreateRedirectModel();
|
||||
@@ -359,46 +412,13 @@ namespace Disco.Web.Controllers
|
||||
}
|
||||
#endregion
|
||||
|
||||
// Decommissioned 2012-11-28 G# - Moved to new infrastructure
|
||||
#region Create - Old
|
||||
//public virtual ActionResult Create(string DeviceSerialNumber, string UserId)
|
||||
//{
|
||||
// var m = new Models.Job.CreateModel()
|
||||
// {
|
||||
// DeviceSerialNumber = DeviceSerialNumber,
|
||||
// UserId = UserId
|
||||
// };
|
||||
// m.UpdateModel(dbContext);
|
||||
|
||||
// return View(m);
|
||||
//}
|
||||
//[HttpPost]
|
||||
//public virtual ActionResult Create(Models.Job.CreateModel m)
|
||||
//{
|
||||
// m.UpdateModel(dbContext);
|
||||
|
||||
// if (!ModelState.IsValid)
|
||||
// {
|
||||
// return View(m);
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// // Create New Job
|
||||
// var currentUser = dbContext.Users.Find(DiscoApplication.CurrentUser.Id);
|
||||
// var j = BI.JobBI.Utilities.Create(dbContext, m.Device, m.User, m.GetJobType, m.GetJobSubTypes, currentUser);
|
||||
// dbContext.SaveChanges();
|
||||
// return RedirectToAction(MVC.Job.Show(j.Id));
|
||||
// }
|
||||
//}
|
||||
#endregion
|
||||
// End Decommissioned 2012-11-28 G#
|
||||
|
||||
#region Log Warranty
|
||||
[DiscoAuthorize(Claims.Job.Actions.LogWarranty)]
|
||||
public virtual ActionResult LogWarranty(int id, string WarrantyProviderId, int? OrganisationAddressId)
|
||||
{
|
||||
var m = new Models.Job.LogWarrantyModel() { JobId = id, WarrantyProviderId = WarrantyProviderId, OrganisationAddressId = OrganisationAddressId };
|
||||
m.UpdateModel(dbContext, false);
|
||||
m.FaultDescription = m.Job.GenerateFaultDescription(dbContext);
|
||||
m.UpdateModel(Database, false);
|
||||
m.FaultDescription = m.Job.GenerateFaultDescription(Database);
|
||||
|
||||
if (m.WarrantyProvider != null)
|
||||
{
|
||||
@@ -407,17 +427,17 @@ namespace Disco.Web.Controllers
|
||||
if (wp.SubmitJobViewType != null)
|
||||
{
|
||||
m.WarrantyProviderSubmitJobViewType = wp.SubmitJobViewType;
|
||||
m.WarrantyProviderSubmitJobModel = wp.SubmitJobViewModel(dbContext, this, m.Job, m.OrganisationAddress, m.TechUser);
|
||||
m.WarrantyProviderSubmitJobModel = wp.SubmitJobViewModel(Database, this, m.Job, m.OrganisationAddress, m.TechUser);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return View(m);
|
||||
}
|
||||
[HttpPost]
|
||||
[HttpPost, DiscoAuthorize(Claims.Job.Actions.LogWarranty)]
|
||||
public virtual ActionResult LogWarranty(Models.Job.LogWarrantyModel m, FormCollection form)
|
||||
{
|
||||
m.UpdateModel(dbContext, true);
|
||||
m.UpdateModel(Database, true);
|
||||
|
||||
if (ModelState.IsValid)
|
||||
{
|
||||
@@ -429,7 +449,7 @@ namespace Disco.Web.Controllers
|
||||
Dictionary<string, string> warrantyProviderProperties;
|
||||
try
|
||||
{
|
||||
warrantyProviderProperties = p.SubmitJobParseProperties(dbContext, form, this, m.Job, m.OrganisationAddress, m.TechUser, m.FaultDescription);
|
||||
warrantyProviderProperties = p.SubmitJobParseProperties(Database, form, this, m.Job, m.OrganisationAddress, m.TechUser, m.FaultDescription);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -443,14 +463,14 @@ namespace Disco.Web.Controllers
|
||||
{
|
||||
m.WarrantyProviderPropertiesJson = JsonConvert.SerializeObject(warrantyProviderProperties);
|
||||
}
|
||||
m.DiscloseProperties = p.SubmitJobDiscloseInfo(dbContext, m.Job, m.OrganisationAddress, m.TechUser, m.FaultDescription, warrantyProviderProperties);
|
||||
m.DiscloseProperties = p.SubmitJobDiscloseInfo(Database, m.Job, m.OrganisationAddress, m.TechUser, m.FaultDescription, warrantyProviderProperties);
|
||||
return View(Views.LogWarrantyDisclose, m);
|
||||
}
|
||||
case "Submit":
|
||||
try
|
||||
{
|
||||
m.Job.OnLogWarranty(dbContext, m.FaultDescription, m.WarrantyProvider, m.OrganisationAddress, m.TechUser, m.WarrantyProviderProperties());
|
||||
dbContext.SaveChanges();
|
||||
m.Job.OnLogWarranty(Database, m.FaultDescription, m.WarrantyProvider, m.OrganisationAddress, m.TechUser, m.WarrantyProviderProperties());
|
||||
Database.SaveChanges();
|
||||
return RedirectToAction(MVC.Job.Show(m.JobId));
|
||||
}
|
||||
catch (Exception ex)
|
||||
@@ -470,11 +490,12 @@ namespace Disco.Web.Controllers
|
||||
}
|
||||
}
|
||||
|
||||
[DiscoAuthorize(Claims.Job.Properties.WarrantyProperties.ProviderDetails)]
|
||||
public virtual ActionResult WarrantyProviderJobDetails(int id)
|
||||
{
|
||||
Models.Job.WarrantyProviderJobDetailsModel model = new Models.Job.WarrantyProviderJobDetailsModel();
|
||||
|
||||
Job job = dbContext.Jobs.Include("Device.DeviceModel").Include("JobMetaWarranty").Include("JobSubTypes").Where(j => j.Id == id).FirstOrDefault();
|
||||
Job job = Database.Jobs.Include("Device.DeviceModel").Include("JobMetaWarranty").Include("JobSubTypes").Where(j => j.Id == id).FirstOrDefault();
|
||||
if (job != null)
|
||||
{
|
||||
if (job.JobMetaWarranty != null && !string.IsNullOrEmpty(job.JobMetaWarranty.ExternalName))
|
||||
@@ -489,7 +510,7 @@ namespace Disco.Web.Controllers
|
||||
{
|
||||
try
|
||||
{
|
||||
object providerModel = providerInstance.JobDetailsViewModel(dbContext, this, job);
|
||||
object providerModel = providerInstance.JobDetailsViewModel(Database, this, job);
|
||||
|
||||
model.JobDetailsSupported = true;
|
||||
model.ViewType = providerInstance.JobDetailsViewType;
|
||||
|
||||
@@ -5,12 +5,13 @@ using System.Linq;
|
||||
using System.Web;
|
||||
using System.Web.Mvc;
|
||||
using Disco.Services.Plugins;
|
||||
using Disco.Services.Authorization;
|
||||
|
||||
namespace Disco.Web.Controllers
|
||||
{
|
||||
public partial class PluginWebHandlerController : Controller
|
||||
{
|
||||
[AuthorizeDiscoUsersAttribute(Disco.Models.Repository.User.Types.Admin)]
|
||||
[DiscoAuthorize(Claims.DiscoAdminAccount)]
|
||||
[OutputCache(Duration = 0, Location = System.Web.UI.OutputCacheLocation.None)]
|
||||
public virtual ActionResult Index(string PluginId, string PluginAction)
|
||||
{
|
||||
|
||||
@@ -1,19 +1,18 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
using System.Web.Mvc;
|
||||
using Disco.BI;
|
||||
using Disco.Data.Repository;
|
||||
using Disco.Models.Repository;
|
||||
using Disco.Models.UI.Search;
|
||||
using Disco.Services.Authorization;
|
||||
using Disco.Services.Plugins.Features.UIExtension;
|
||||
using Disco.Models.UI.Search;
|
||||
using Disco.Services.Users;
|
||||
using Disco.Services.Web;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Web.Mvc;
|
||||
|
||||
namespace Disco.Web.Controllers
|
||||
{
|
||||
public partial class SearchController : dbAdminController
|
||||
public partial class SearchController : AuthorizedDatabaseController
|
||||
{
|
||||
#region Query
|
||||
[DiscoAuthorizeAny(Claims.Job.Search, Claims.Device.Search, Claims.User.Search)]
|
||||
public virtual ActionResult Query(string term, string limit = null, bool searchDetails = false)
|
||||
{
|
||||
term = term.Trim();
|
||||
@@ -62,23 +61,29 @@ namespace Disco.Web.Controllers
|
||||
m.ErrorMessage = "A search term of at least two characters is required";
|
||||
return View(m);
|
||||
}
|
||||
m.Devices = BI.DeviceBI.Searching.Search(dbContext, term, null, searchDetails);
|
||||
m.Jobs = BI.JobBI.Searching.Search(dbContext, term, null, true, searchDetails);
|
||||
m.Users = BI.UserBI.Searching.Search(dbContext, term);
|
||||
if (Authorization.Has(Claims.Job.Search))
|
||||
m.Jobs = BI.JobBI.Searching.Search(Database, term, null, true, searchDetails);
|
||||
|
||||
if (Authorization.Has(Claims.Device.Search))
|
||||
m.Devices = BI.DeviceBI.Searching.Search(Database, term, null, searchDetails);
|
||||
|
||||
if (Authorization.Has(Claims.User.Search))
|
||||
m.Users = BI.UserBI.Searching.Search(Database, term);
|
||||
}
|
||||
else
|
||||
{
|
||||
switch (limit.ToLower())
|
||||
{
|
||||
case "devicemodel":
|
||||
Authorization.Require(Claims.Device.Search);
|
||||
int deviceModelId;
|
||||
if (int.TryParse(term, out deviceModelId))
|
||||
{
|
||||
var vm = dbContext.DeviceModels.Find(deviceModelId);
|
||||
var vm = Database.DeviceModels.Find(deviceModelId);
|
||||
if (vm != null)
|
||||
{
|
||||
m.FriendlyTerm = string.Format("Device Model: {0}", vm.ToString());
|
||||
m.Devices = BI.DeviceBI.Searching.SearchDeviceModel(dbContext, vm.Id);
|
||||
m.Devices = BI.DeviceBI.Searching.SearchDeviceModel(Database, vm.Id);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -87,14 +92,15 @@ namespace Disco.Web.Controllers
|
||||
m.ErrorMessage = "Invalid Device Model Id";
|
||||
break;
|
||||
case "deviceprofile":
|
||||
Authorization.Require(Claims.Device.Search);
|
||||
int deviceProfileId;
|
||||
if (int.TryParse(term, out deviceProfileId))
|
||||
{
|
||||
var dp = dbContext.DeviceProfiles.Find(deviceProfileId);
|
||||
var dp = Database.DeviceProfiles.Find(deviceProfileId);
|
||||
if (dp != null)
|
||||
{
|
||||
m.FriendlyTerm = string.Format("Device Profile: {0}", dp.ToString());
|
||||
m.Devices = BI.DeviceBI.Searching.SearchDeviceProfile(dbContext, dp.Id);
|
||||
m.Devices = BI.DeviceBI.Searching.SearchDeviceProfile(Database, dp.Id);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -103,14 +109,15 @@ namespace Disco.Web.Controllers
|
||||
m.ErrorMessage = "Invalid Device Profile Id";
|
||||
break;
|
||||
case "devicebatch":
|
||||
Authorization.Require(Claims.Device.Search);
|
||||
int deviceBatchId;
|
||||
if (int.TryParse(term, out deviceBatchId))
|
||||
{
|
||||
var db = dbContext.DeviceBatches.Find(deviceBatchId);
|
||||
var db = Database.DeviceBatches.Find(deviceBatchId);
|
||||
if (db != null)
|
||||
{
|
||||
m.FriendlyTerm = string.Format("Device Batch: {0}", db.ToString());
|
||||
m.Devices = BI.DeviceBI.Searching.SearchDeviceBatch(dbContext, db.Id);
|
||||
m.Devices = BI.DeviceBI.Searching.SearchDeviceBatch(Database, db.Id);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -119,19 +126,21 @@ namespace Disco.Web.Controllers
|
||||
m.ErrorMessage = "Invalid Device Batch Id";
|
||||
break;
|
||||
case "devices":
|
||||
Authorization.Require(Claims.Device.Search);
|
||||
if (term.Length < 2)
|
||||
{
|
||||
m.Success = false;
|
||||
m.ErrorMessage = "A search term of at least two characters is required";
|
||||
return View(m);
|
||||
}
|
||||
m.Devices = BI.DeviceBI.Searching.Search(dbContext, term, null, searchDetails);
|
||||
m.Devices = BI.DeviceBI.Searching.Search(Database, term, null, searchDetails);
|
||||
if (m.Devices.Count == 1)
|
||||
{
|
||||
return RedirectToAction(MVC.Device.Show(m.Devices[0].SerialNumber));
|
||||
}
|
||||
break;
|
||||
case "jobs":
|
||||
Authorization.Require(Claims.Job.Search);
|
||||
if (term.Length < 2 && termInt < 0)
|
||||
{
|
||||
m.Success = false;
|
||||
@@ -140,28 +149,30 @@ namespace Disco.Web.Controllers
|
||||
}
|
||||
if (termInt >= 0)
|
||||
{ // Term is a Number - Check for JobId
|
||||
if (dbContext.Jobs.Count(j => j.Id == termInt) == 1)
|
||||
if (Database.Jobs.Count(j => j.Id == termInt) == 1)
|
||||
{
|
||||
return RedirectToAction(MVC.Job.Show(termInt));
|
||||
}
|
||||
}
|
||||
m.Jobs = BI.JobBI.Searching.Search(dbContext, term, null, true, searchDetails);
|
||||
m.Jobs = BI.JobBI.Searching.Search(Database, term, null, true, searchDetails);
|
||||
break;
|
||||
case "users":
|
||||
Authorization.Require(Claims.User.Search);
|
||||
if (term.Length < 2)
|
||||
{
|
||||
m.Success = false;
|
||||
m.ErrorMessage = "A search term of at least two characters is required";
|
||||
return View(m);
|
||||
}
|
||||
m.Users = BI.UserBI.Searching.Search(dbContext, term);
|
||||
m.Users = BI.UserBI.Searching.Search(Database, term);
|
||||
if (m.Users.Count == 1)
|
||||
{
|
||||
return RedirectToAction(MVC.User.Show(m.Users[0].Id));
|
||||
}
|
||||
break;
|
||||
case "deviceserialnumber":
|
||||
var device = dbContext.Devices.FirstOrDefault(d => d.SerialNumber == term);
|
||||
Authorization.Require(Claims.Device.Search);
|
||||
var device = Database.Devices.FirstOrDefault(d => d.SerialNumber == term);
|
||||
if (device != null)
|
||||
return RedirectToAction(MVC.Device.Show(term));
|
||||
else
|
||||
@@ -171,9 +182,10 @@ namespace Disco.Web.Controllers
|
||||
return View(m);
|
||||
}
|
||||
case "jobid":
|
||||
Authorization.Require(Claims.Job.Search);
|
||||
if (termInt >= 0)
|
||||
{
|
||||
var job = dbContext.Jobs.FirstOrDefault(d => d.Id == termInt);
|
||||
var job = Database.Jobs.FirstOrDefault(d => d.Id == termInt);
|
||||
if (job != null)
|
||||
return RedirectToAction(MVC.Job.Show(termInt));
|
||||
else
|
||||
@@ -190,14 +202,15 @@ namespace Disco.Web.Controllers
|
||||
return View(m);
|
||||
}
|
||||
case "userid":
|
||||
var user = dbContext.Users.FirstOrDefault(u => u.Id == term);
|
||||
Authorization.Require(Claims.User.Search);
|
||||
var user = Database.Users.FirstOrDefault(u => u.Id == term);
|
||||
if (user != null)
|
||||
return RedirectToAction(MVC.User.Show(term));
|
||||
else
|
||||
{
|
||||
try
|
||||
{
|
||||
user = BI.UserBI.UserCache.GetUser(term, dbContext);
|
||||
user = UserService.GetUser(term, Database);
|
||||
if (user != null)
|
||||
return RedirectToAction(MVC.User.Show(term));
|
||||
else
|
||||
|
||||
@@ -1,16 +1,17 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
using System.Web.Mvc;
|
||||
using Disco.Models.Repository;
|
||||
using Disco.BI.Extensions;
|
||||
using Disco.Services.Plugins.Features.UIExtension;
|
||||
using Disco.BI.Extensions;
|
||||
using Disco.Models.UI.User;
|
||||
using Disco.Services.Authorization;
|
||||
using Disco.Services.Authorization.Roles;
|
||||
using Disco.Services.Plugins.Features.UIExtension;
|
||||
using Disco.Services.Users;
|
||||
using Disco.Services.Web;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Web.Mvc;
|
||||
|
||||
namespace Disco.Web.Controllers
|
||||
{
|
||||
public partial class UserController : dbAdminController
|
||||
public partial class UserController : AuthorizedDatabaseController
|
||||
{
|
||||
#region Index
|
||||
public virtual ActionResult Index()
|
||||
@@ -25,40 +26,62 @@ namespace Disco.Web.Controllers
|
||||
#endregion
|
||||
|
||||
#region Show
|
||||
[DiscoAuthorize(Claims.User.Show)]
|
||||
public virtual ActionResult Show(string id)
|
||||
{
|
||||
var m = new Models.User.ShowModel();
|
||||
|
||||
dbContext.Configuration.LazyLoadingEnabled = true;
|
||||
Database.Configuration.LazyLoadingEnabled = true;
|
||||
|
||||
// Update User Cache
|
||||
// Do this first so the Database is updated if necessary
|
||||
try
|
||||
{
|
||||
Disco.BI.UserBI.UserCache.GetUser(id, dbContext, true);
|
||||
UserService.GetUser(id, Database, true);
|
||||
}
|
||||
catch (ArgumentException)
|
||||
{
|
||||
// Ignore if User not in Active Directory anymore
|
||||
}
|
||||
|
||||
m.User = dbContext.Users.Where(um => um.Id == id).FirstOrDefault();
|
||||
m.User = Database.Users
|
||||
.Include("DeviceUserAssignments.Device.DeviceModel").Include("UserAttachments")
|
||||
.FirstOrDefault(um => um.Id == id);
|
||||
|
||||
if (m.User == null)
|
||||
throw new ArgumentException("Unknown User Id", "id");
|
||||
|
||||
m.Jobs = new Disco.Models.BI.Job.JobTableModel()
|
||||
if (Authorization.Has(Claims.User.ShowJobs))
|
||||
{
|
||||
ShowStatus = true,
|
||||
ShowDevice = true,
|
||||
ShowUser = false,
|
||||
IsSmallTable = false,
|
||||
HideClosedJobs = true,
|
||||
EnablePaging = false
|
||||
};
|
||||
m.Jobs.Fill(dbContext, BI.JobBI.Searching.BuildJobTableModel(dbContext).Where(j => j.UserId == id).OrderByDescending(j => j.Id));
|
||||
m.Jobs = new Disco.Models.BI.Job.JobTableModel()
|
||||
{
|
||||
ShowStatus = true,
|
||||
ShowDevice = true,
|
||||
ShowUser = false,
|
||||
IsSmallTable = false,
|
||||
HideClosedJobs = true,
|
||||
EnablePaging = false
|
||||
};
|
||||
m.Jobs.Fill(Database, BI.JobBI.Searching.BuildJobTableModel(Database).Where(j => j.UserId == id).OrderByDescending(j => j.Id));
|
||||
}
|
||||
|
||||
m.DocumentTemplates = m.User.AvailableDocumentTemplates(dbContext, DiscoApplication.CurrentUser, DateTime.Now);
|
||||
try
|
||||
{
|
||||
if (Authorization.Has(Claims.User.ShowAuthorization))
|
||||
{
|
||||
var userAuth = UserService.GetAuthorization(id);
|
||||
var claims = userAuth.RoleTokens.Cast<RoleToken>().Select(rt => rt.Claims).ToArray();
|
||||
if (claims.Length > 0)
|
||||
m.ClaimNavigator = Claims.RoleClaimNavigator.BuildClaimTree(claims);
|
||||
}
|
||||
}
|
||||
catch (ArgumentException)
|
||||
{
|
||||
// Ignore if User not in Active Directory anymore
|
||||
}
|
||||
|
||||
if (Authorization.Has(Claims.User.Actions.GenerateDocuments))
|
||||
m.DocumentTemplates = m.User.AvailableDocumentTemplates(Database, UserService.CurrentUser, DateTime.Now);
|
||||
|
||||
// UI Extensions
|
||||
UIExtensions.ExecuteExtensions<UserShowModel>(this.ControllerContext, m);
|
||||
|
||||
Reference in New Issue
Block a user