bug fix #185: fix document package generation

This commit is contained in:
Gary Sharp
2025-12-03 15:49:10 +11:00
parent 529bba5c72
commit 94a31282eb
11 changed files with 218 additions and 31 deletions
@@ -149,27 +149,28 @@ namespace Disco.Services
template = database.DocumentTemplates.Find(templateId);
if (template == null)
throw new ArgumentException("Invalid document template id", nameof(templateId));
if (!Enum.TryParse(template.Scope, out AttachmentTypes scope))
throw new InvalidOperationException("Unknown DocumentType Scope");
// validate authorization
switch (template.Scope)
switch (scope)
{
case DocumentTemplate.DocumentTemplateScopes.Device:
case AttachmentTypes.Device:
authorization.Require(Claims.Device.Actions.GenerateDocuments);
break;
case DocumentTemplate.DocumentTemplateScopes.Job:
case AttachmentTypes.Job:
authorization.Require(Claims.Job.Actions.GenerateDocuments);
break;
case DocumentTemplate.DocumentTemplateScopes.User:
case AttachmentTypes.User:
authorization.Require(Claims.User.Actions.GenerateDocuments);
break;
default:
throw new InvalidOperationException("Unknown DocumentType Scope");
throw new InvalidOperationException("Unsupported DocumentType Scope");
}
// resolve target
target = template.ResolveScopeTarget(database, targetId, out targetUser);
if (target == null)
throw new ArgumentException("Target not found", nameof(targetId));
target = template.ResolveScopeTarget(database, targetId, out targetUser)
?? throw new ArgumentException("Target not found", nameof(targetId));
}
public static IEnumerable<OnImportUserFlagRule> GetOnImportUserFlagRuleDetails(this DocumentTemplate template, DiscoDataContext database)