support user details category in document bulk generation
This commit is contained in:
@@ -1113,6 +1113,60 @@ namespace Disco.Web.Areas.API.Controllers
|
||||
return Json(results);
|
||||
}
|
||||
|
||||
[DiscoAuthorizeAll(Claims.Config.DocumentTemplate.BulkGenerate, Claims.User.Actions.GenerateDocuments, Claims.User.ShowDetails)]
|
||||
[HttpPost, ValidateAntiForgeryToken]
|
||||
public virtual ActionResult BulkGenerateGetUserDetailValues(string key)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(key))
|
||||
return new HttpStatusCodeResult(System.Net.HttpStatusCode.BadRequest);
|
||||
|
||||
var results = Database.UserDetails.Where(d => d.Scope == "Details" && d.Key == key).Select(d => d.Value).Distinct().ToList();
|
||||
|
||||
return Json(results);
|
||||
}
|
||||
|
||||
[DiscoAuthorizeAll(Claims.Config.DocumentTemplate.BulkGenerate, Claims.User.Actions.GenerateDocuments, Claims.User.ShowDetails)]
|
||||
[HttpPost, ValidateAntiForgeryToken, ValidateInput(false)]
|
||||
public virtual ActionResult BulkGenerateAddUserDetail(string key, string value)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(key))
|
||||
return new HttpStatusCodeResult(System.Net.HttpStatusCode.BadRequest);
|
||||
|
||||
var results = new List<BulkGenerateUserModel>();
|
||||
|
||||
var query = Database.UserDetails.Include(d => d.User).Where(d => d.Scope == "Details" && d.Key == key);
|
||||
if (!string.IsNullOrWhiteSpace(value))
|
||||
{
|
||||
query = query.Where(d => d.Value == value);
|
||||
}
|
||||
var details = query.ToList();
|
||||
|
||||
if (details.Count == 0)
|
||||
{
|
||||
results.Add(new BulkGenerateUserModel()
|
||||
{
|
||||
Id = key,
|
||||
DisplayName = $"{key}{(string.IsNullOrWhiteSpace(value) ? null : $":{value}")}",
|
||||
Scope = $"User Detail '{key}' didn't match any users{(string.IsNullOrWhiteSpace(value) ? null : $" with the value '{value}'")}",
|
||||
IsError = true,
|
||||
});
|
||||
} else
|
||||
{
|
||||
foreach (var user in details.Select(d => d.User).Distinct())
|
||||
{
|
||||
results.Add(new BulkGenerateUserModel()
|
||||
{
|
||||
Id = user.UserId,
|
||||
DisplayName = user.DisplayName,
|
||||
Scope = $"User Detail '{key}'{(string.IsNullOrWhiteSpace(value) ? null : $" with the value '{value}'")} Matches User",
|
||||
IsError = false,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return Json(results);
|
||||
}
|
||||
|
||||
public virtual ActionResult Generate(string id, string TargetId)
|
||||
{
|
||||
Disco.Services.DocumentTemplateExtensions.GetTemplateAndTarget(Database, Authorization, id, TargetId, out var template, out var target, out _);
|
||||
|
||||
@@ -12,6 +12,7 @@ using Disco.Web.Areas.Config.Models.DocumentTemplate;
|
||||
using Disco.Web.Areas.Config.Views.DocumentTemplate;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.Eventing.Reader;
|
||||
using System.Linq;
|
||||
using System.Web.Mvc;
|
||||
|
||||
@@ -262,6 +263,18 @@ namespace Disco.Web.Areas.Config.Controllers
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
}
|
||||
if (Authorization.Has(Claims.User.ShowDetails))
|
||||
{
|
||||
m.UserDetails = Database.UserDetails.Where(d => d.Scope == "Details").GroupBy(d => d.Key).Select(g => new BulkGenerateModel.ItemWithCount<string>()
|
||||
{
|
||||
Item = g.Key,
|
||||
Count = g.Count(),
|
||||
}).ToList();
|
||||
}
|
||||
else
|
||||
{
|
||||
m.UserDetails = new List<BulkGenerateModel.ItemWithCount<string>>();
|
||||
}
|
||||
|
||||
// UI Extensions
|
||||
UIExtensions.ExecuteExtensions<ConfigDocumentTemplateBulkGenerate>(ControllerContext, m);
|
||||
|
||||
@@ -11,6 +11,7 @@ namespace Disco.Web.Areas.Config.Models.DocumentTemplate
|
||||
public List<ItemWithCount<Disco.Models.Repository.DeviceProfile>> DeviceProfiles { get; set; }
|
||||
public List<ItemWithCount<Disco.Models.Repository.DeviceBatch>> DeviceBatches { get; set; }
|
||||
public List<ItemWithCount<Disco.Models.Repository.DocumentTemplate>> DocumentTemplates { get; set; }
|
||||
public List<ItemWithCount<string>> UserDetails { get; set; }
|
||||
|
||||
public class ItemWithCount<T>
|
||||
{
|
||||
|
||||
@@ -37,6 +37,10 @@
|
||||
{
|
||||
<button id="AddDocumentAttachment" class="button small">Add With Document Attachment</button>
|
||||
}
|
||||
@if (Model.UserDetails.Any(b => b.Count > 0))
|
||||
{
|
||||
<button id="AddUserDetail" class="button small">Add With User Detail</button>
|
||||
}
|
||||
</div>
|
||||
<table class="genericData">
|
||||
<thead>
|
||||
@@ -207,3 +211,39 @@
|
||||
}
|
||||
</div>
|
||||
}
|
||||
|
||||
@if (Model.UserDetails.Any(b => b.Count > 0))
|
||||
{
|
||||
<div id="DocumentTemplate_BulkGenerate_Dialog_AddUserDetail" class="dialog dialog-bulk-generate" title="@(Model.DocumentTemplate.Description): Add User by Detail">
|
||||
<div class="brief">
|
||||
<div>
|
||||
Add all users with a matching user detail to the bulk generation.
|
||||
</div>
|
||||
</div>
|
||||
@using (Html.BeginForm(MVC.API.DocumentTemplate.BulkGenerateAddUserDetail(), FormMethod.Post))
|
||||
{
|
||||
<input name="key" type="hidden" required />
|
||||
<input name="value" type="hidden" />
|
||||
|
||||
<div id="DocumentTemplate_BulkGenerate_Dialog_AddUserDetail_Key" class="dialog-item-picker" style="width: 49%; float: left;">
|
||||
@foreach (var key in Model.UserDetails)
|
||||
{
|
||||
<div class="item @(key.Count == 0 ? "disabled" : null)" data-id="@key.Item">
|
||||
<i class="fa fa-info fa-fw fa-lg"></i>@key.Item.TrimEnd('*', '&') <small>(@key.Count.ToString("N0") user@(key.Count == 1 ? null : "s"))</small>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
|
||||
@Html.AntiForgeryToken()
|
||||
}
|
||||
@using (Html.BeginForm(MVC.API.DocumentTemplate.BulkGenerateGetUserDetailValues(), FormMethod.Post))
|
||||
{
|
||||
<input name="key" type="hidden" required />
|
||||
|
||||
<div id="DocumentTemplate_BulkGenerate_Dialog_AddUserDetail_Value" class="dialog-item-picker" style="width: 49%; float: left; margin-left: 1%;">
|
||||
</div>
|
||||
|
||||
@Html.AntiForgeryToken()
|
||||
}
|
||||
</div>
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user