Permissions & Authorization for Users #24
Initial Release; Includes Database and MVC refactoring
This commit is contained in:
@@ -38,16 +38,16 @@ namespace Disco.Web.Models.Job
|
||||
public Disco.Models.Repository.User User { get; set; }
|
||||
public List<Disco.Models.Repository.JobType> JobTypes { get; set; }
|
||||
public List<Disco.Models.Repository.JobSubType> JobSubTypes { get; set; }
|
||||
public void UpdateModel(DiscoDataContext dbContext)
|
||||
public void UpdateModel(DiscoDataContext Database)
|
||||
{
|
||||
if (this.JobTypes == null)
|
||||
JobTypes = dbContext.JobTypes.ToList();
|
||||
JobTypes = Database.JobTypes.ToList();
|
||||
if (this.JobSubTypes == null)
|
||||
JobSubTypes = dbContext.JobSubTypes.ToList();
|
||||
JobSubTypes = Database.JobSubTypes.ToList();
|
||||
|
||||
if (!string.IsNullOrEmpty(DeviceSerialNumber))
|
||||
{
|
||||
this.Device = dbContext.Devices.Include("DeviceModel").Where(d => d.SerialNumber == DeviceSerialNumber).FirstOrDefault();
|
||||
this.Device = Database.Devices.Include("DeviceModel").Where(d => d.SerialNumber == DeviceSerialNumber).FirstOrDefault();
|
||||
if (this.Device == null)
|
||||
{
|
||||
throw new ArgumentException("Invalid Device Serial Number Specified", "DeviceSerialNumber");
|
||||
@@ -101,7 +101,7 @@ namespace Disco.Web.Models.Job
|
||||
}
|
||||
if (!string.IsNullOrEmpty(UserId))
|
||||
{
|
||||
this.User = dbContext.Users.Find(UserId);
|
||||
this.User = Database.Users.Find(UserId);
|
||||
if (this.User == null)
|
||||
{
|
||||
throw new ArgumentException("Invalid User Id Specified", "UserId");
|
||||
|
||||
@@ -10,9 +10,6 @@ namespace Disco.Web.Models.Job
|
||||
{
|
||||
public Disco.Models.BI.Job.JobTableModel OpenJobs { get; set; }
|
||||
public Disco.Models.BI.Job.JobTableModel LongRunningJobs { get; set; }
|
||||
//public Disco.Models.BI.Job.JobTableModel WaitingForUserActionJobs { get; set; }
|
||||
//public Disco.Models.BI.Job.JobTableModel ReadyForReturnJobs { get; set; }
|
||||
//public Disco.Models.BI.Job.JobTableModel RecentlyClosedJobs { get; set; }
|
||||
|
||||
public List<Disco.Models.BI.Job.Statistics.DailyOpenedClosedItem> DailyOpenedClosedStatistics { get; set; }
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ using System.Web.Script.Serialization;
|
||||
using Disco.Services.Plugins;
|
||||
using Disco.Services.Plugins.Features.WarrantyProvider;
|
||||
using Newtonsoft.Json;
|
||||
using Disco.Services.Users;
|
||||
|
||||
namespace Disco.Web.Models.Job
|
||||
{
|
||||
@@ -57,23 +58,23 @@ namespace Disco.Web.Models.Job
|
||||
|
||||
public Exception Error { get; set; }
|
||||
|
||||
public void UpdateModel(DiscoDataContext dbContext, bool IsPostBack)
|
||||
public void UpdateModel(DiscoDataContext Database, bool IsPostBack)
|
||||
{
|
||||
dbContext.Configuration.LazyLoadingEnabled = true;
|
||||
Database.Configuration.LazyLoadingEnabled = true;
|
||||
if (Job == null)
|
||||
{
|
||||
// Update Job User's Details [#12]
|
||||
string jobUserId = dbContext.Jobs.Where(j => j.Id == JobId).Select(j => j.UserId).FirstOrDefault();
|
||||
string jobUserId = Database.Jobs.Where(j => j.Id == JobId).Select(j => j.UserId).FirstOrDefault();
|
||||
if (jobUserId != null)
|
||||
{
|
||||
// Ignore update errors (Most commonly when the User Id no longer exists in AD)
|
||||
try
|
||||
{
|
||||
Disco.BI.UserBI.UserCache.GetUser(jobUserId, dbContext, true);
|
||||
UserService.GetUser(jobUserId, Database, true);
|
||||
} catch (Exception) {}
|
||||
}
|
||||
|
||||
Job = (from j in dbContext.Jobs.Include("Device.DeviceModel").Include("JobMetaWarranty").Include("JobSubTypes")
|
||||
Job = (from j in Database.Jobs.Include("Device.DeviceModel").Include("JobMetaWarranty").Include("JobSubTypes")
|
||||
where (j.Id == JobId)
|
||||
select j).FirstOrDefault();
|
||||
if (Job == null)
|
||||
@@ -83,7 +84,7 @@ namespace Disco.Web.Models.Job
|
||||
}
|
||||
|
||||
// Update TechUser's Details [#12]
|
||||
this.TechUser = Disco.BI.UserBI.UserCache.GetUser(DiscoApplication.CurrentUser.Id, dbContext, true);
|
||||
this.TechUser = UserService.GetUser(UserService.CurrentUserId, Database, true);
|
||||
|
||||
WarrantyProviders = Plugins.GetPluginFeatures(typeof(WarrantyProviderFeature));
|
||||
|
||||
@@ -95,7 +96,7 @@ namespace Disco.Web.Models.Job
|
||||
if (!string.IsNullOrEmpty(WarrantyProviderId))
|
||||
WarrantyProvider = Plugins.GetPluginFeature(WarrantyProviderId, typeof(WarrantyProviderFeature));
|
||||
|
||||
this.OrganisationAddresses = dbContext.DiscoConfiguration.OrganisationAddresses.Addresses;
|
||||
this.OrganisationAddresses = Database.DiscoConfiguration.OrganisationAddresses.Addresses;
|
||||
|
||||
if (!IsPostBack && !this.OrganisationAddressId.HasValue)
|
||||
{
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
using Disco.Models.Authorization;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
|
||||
namespace Disco.Web.Models.Shared
|
||||
{
|
||||
public class FancyTreeNode
|
||||
{
|
||||
public string title { get; set; }
|
||||
public string key { get; set; }
|
||||
public bool expanded { get; set; }
|
||||
public bool folder { get; set; }
|
||||
public bool selected { get; set; }
|
||||
public bool unselectable { get; set; }
|
||||
public FancyTreeNode[] children { get; set; }
|
||||
public string tooltip { get; set; }
|
||||
|
||||
public static FancyTreeNode FromClaimNavigatorItem(IClaimNavigatorItem Item, bool Unselectable)
|
||||
{
|
||||
FancyTreeNode[] children = Item.IsGroup ? Item.Children.Where(i => !i.Hidden).Select(i => FromClaimNavigatorItem(i, Unselectable)).ToArray() : null;
|
||||
|
||||
return new FancyTreeNode()
|
||||
{
|
||||
key = Item.Key,
|
||||
title = Item.Name,
|
||||
folder = children != null && children.Length > 0,
|
||||
tooltip = Item.Description,
|
||||
children = children == null || children.Length == 0 ? null : children,
|
||||
selected = Item.Value.HasValue && Item.Value.Value,
|
||||
unselectable = Unselectable
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -8,6 +8,8 @@ using Disco.BI.Extensions;
|
||||
using Disco.Models.Interop.ActiveDirectory;
|
||||
using Disco.Models.UI.User;
|
||||
using Disco.Web.Extensions;
|
||||
using Disco.Models.Authorization;
|
||||
using Disco.Web.Models.Shared;
|
||||
|
||||
namespace Disco.Web.Models.User
|
||||
{
|
||||
@@ -16,6 +18,20 @@ namespace Disco.Web.Models.User
|
||||
public Disco.Models.Repository.User User { get; set; }
|
||||
public Disco.Models.BI.Job.JobTableModel Jobs { get; set; }
|
||||
public List<Disco.Models.Repository.DocumentTemplate> DocumentTemplates { get; set; }
|
||||
public IClaimNavigatorItem ClaimNavigator { get; set; }
|
||||
|
||||
public FancyTreeNode[] ClaimNavigatorFancyTreeNodes
|
||||
{
|
||||
get
|
||||
{
|
||||
var rootNode = FancyTreeNode.FromClaimNavigatorItem(this.ClaimNavigator, true);
|
||||
rootNode.expanded = true;
|
||||
|
||||
return new FancyTreeNode[] {
|
||||
rootNode
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public List<SelectListItem> DocumentTemplatesSelectListItems
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user