Permissions & Authorization for Users #24
Initial Release; Includes Database and MVC refactoring
This commit is contained in:
@@ -1,26 +1,26 @@
|
||||
using System;
|
||||
using Disco.BI.Extensions;
|
||||
using Disco.Models.Repository;
|
||||
using Disco.Models.UI.Config.DeviceProfile;
|
||||
using Disco.Services.Authorization;
|
||||
using Disco.Services.Plugins;
|
||||
using Disco.Services.Plugins.Features.CertificateProvider;
|
||||
using Disco.Services.Plugins.Features.UIExtension;
|
||||
using Disco.Services.Web;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
using System.Web.Mvc;
|
||||
using Disco.Data.Configuration;
|
||||
using Disco.BI;
|
||||
using Disco.BI.Extensions;
|
||||
using Disco.Services.Plugins.Features.CertificateProvider;
|
||||
using Disco.Services.Plugins;
|
||||
using Disco.Services.Plugins.Features.UIExtension;
|
||||
using Disco.Models.UI.Config.DeviceProfile;
|
||||
using Disco.Models.Repository;
|
||||
|
||||
namespace Disco.Web.Areas.Config.Controllers
|
||||
{
|
||||
public partial class DeviceProfileController : dbAdminController
|
||||
public partial class DeviceProfileController : AuthorizedDatabaseController
|
||||
{
|
||||
[DiscoAuthorize(Claims.Config.DeviceProfile.Show)]
|
||||
public virtual ActionResult Index(int? id)
|
||||
{
|
||||
if (id.HasValue)
|
||||
{
|
||||
var m = dbContext.DeviceProfiles.Where(dp => dp.Id == id.Value).Select(dp => new Models.DeviceProfile.ShowModel()
|
||||
var m = Database.DeviceProfiles.Where(dp => dp.Id == id.Value).Select(dp => new Models.DeviceProfile.ShowModel()
|
||||
{
|
||||
DeviceProfile = dp,
|
||||
DeviceCount = dp.Devices.Count(),
|
||||
@@ -30,7 +30,11 @@ namespace Disco.Web.Areas.Config.Controllers
|
||||
if (m == null || m.DeviceProfile == null)
|
||||
throw new ArgumentException("Invalid Device Profile Id", "id");
|
||||
|
||||
m.OrganisationAddresses = dbContext.DiscoConfiguration.OrganisationAddresses.Addresses;
|
||||
m.OrganisationAddresses = Database.DiscoConfiguration.OrganisationAddresses.Addresses;
|
||||
|
||||
if (m.DeviceProfile.DefaultOrganisationAddress.HasValue)
|
||||
m.DefaultOrganisationAddress = Database.DiscoConfiguration.OrganisationAddresses.GetAddress(m.DeviceProfile.DefaultOrganisationAddress.Value);
|
||||
|
||||
m.CertificateProviders = Plugins.GetPluginFeatures(typeof(CertificateProviderFeature));
|
||||
|
||||
var DistributionValues = Enum.GetValues(typeof(Disco.Models.Repository.DeviceProfile.DistributionTypes));
|
||||
@@ -44,13 +48,7 @@ namespace Disco.Web.Areas.Config.Controllers
|
||||
Selected = ((int)m.DeviceProfile.DistributionType == value)
|
||||
});
|
||||
}
|
||||
m.CanDelete = m.DeviceProfile.CanDelete(dbContext);
|
||||
|
||||
// Removed 2012-06-14 G# - Properties moved to DeviceProfile model & DB Migrated in DBv3.
|
||||
//var config = m.DeviceProfile.Configuration(dbContext);
|
||||
//m.AllocateWirelessCertificate = m.DeviceProfile.AllocateWirelessCertificate;
|
||||
//m.OrganisationalUnit = m.DeviceProfile.OrganisationalUnit;
|
||||
//m.ComputerNameTemplate = m.DeviceProfile.ComputerNameTemplate;
|
||||
m.CanDelete = m.DeviceProfile.CanDelete(Database);
|
||||
|
||||
// UI Extensions
|
||||
UIExtensions.ExecuteExtensions<ConfigDeviceProfileShowModel>(this.ControllerContext, m);
|
||||
@@ -59,7 +57,7 @@ namespace Disco.Web.Areas.Config.Controllers
|
||||
}
|
||||
else
|
||||
{
|
||||
var m = Models.DeviceProfile.IndexModel.Build(dbContext);
|
||||
var m = Models.DeviceProfile.IndexModel.Build(Database);
|
||||
|
||||
// UI Extensions
|
||||
UIExtensions.ExecuteExtensions<ConfigDeviceProfileIndexModel>(this.ControllerContext, m);
|
||||
@@ -68,6 +66,7 @@ namespace Disco.Web.Areas.Config.Controllers
|
||||
}
|
||||
}
|
||||
|
||||
[DiscoAuthorizeAll(Claims.Config.DeviceProfile.Create, Claims.Config.DeviceProfile.Configure)]
|
||||
public virtual ActionResult Create()
|
||||
{
|
||||
var m = new Models.DeviceProfile.CreateModel()
|
||||
@@ -86,19 +85,19 @@ namespace Disco.Web.Areas.Config.Controllers
|
||||
return View(m);
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
[DiscoAuthorizeAll(Claims.Config.DeviceProfile.Create, Claims.Config.DeviceProfile.Configure), HttpPost]
|
||||
public virtual ActionResult Create(Models.DeviceProfile.CreateModel model)
|
||||
{
|
||||
if (ModelState.IsValid)
|
||||
{
|
||||
// Check for Existing
|
||||
var existing = dbContext.DeviceProfiles.Where(m => m.Name == model.DeviceProfile.Name).FirstOrDefault();
|
||||
var existing = Database.DeviceProfiles.Where(m => m.Name == model.DeviceProfile.Name).FirstOrDefault();
|
||||
if (existing == null)
|
||||
{
|
||||
model.DeviceProfile.ProvisionADAccount = true;
|
||||
|
||||
dbContext.DeviceProfiles.Add(model.DeviceProfile);
|
||||
dbContext.SaveChanges();
|
||||
Database.DeviceProfiles.Add(model.DeviceProfile);
|
||||
Database.SaveChanges();
|
||||
return RedirectToAction(MVC.Config.DeviceProfile.Index(model.DeviceProfile.Id));
|
||||
}
|
||||
else
|
||||
@@ -113,13 +112,14 @@ namespace Disco.Web.Areas.Config.Controllers
|
||||
return View(model);
|
||||
}
|
||||
|
||||
[DiscoAuthorize(Claims.Config.DeviceProfile.ConfigureDefaults)]
|
||||
public virtual ActionResult Defaults()
|
||||
{
|
||||
var m = new Models.DeviceProfile.DefaultsModel()
|
||||
{
|
||||
DeviceProfiles = dbContext.DeviceProfiles.ToList(),
|
||||
Default = dbContext.DiscoConfiguration.DeviceProfiles.DefaultDeviceProfileId,
|
||||
DefaultAddDeviceOffline = dbContext.DiscoConfiguration.DeviceProfiles.DefaultAddDeviceOfflineDeviceProfileId
|
||||
DeviceProfiles = Database.DeviceProfiles.ToList(),
|
||||
Default = Database.DiscoConfiguration.DeviceProfiles.DefaultDeviceProfileId,
|
||||
DefaultAddDeviceOffline = Database.DiscoConfiguration.DeviceProfiles.DefaultAddDeviceOfflineDeviceProfileId
|
||||
};
|
||||
m.DeviceProfilesAndNone = m.DeviceProfiles.ToList();
|
||||
m.DeviceProfilesAndNone.Insert(0, new Disco.Models.Repository.DeviceProfile() { Id = 0, Name = "<No Default>" });
|
||||
|
||||
Reference in New Issue
Block a user