Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions frontend/src/lib/api/portal.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,19 @@ export const portal = {
// Get custom fields used by this portal's request types (portal-authenticated)
getCustomFields: (slug) => fetchAPI(`/portal/${slug}/custom-fields`),

// Search assets exposed to the portal. Pass `fieldId` for an asset custom
// field: the server loads that field's admin-configured asset set and
// ql_query (the caller never supplies CQL). `assetSetId` is the report-scoped
// fallback. `query` narrows by title/description.
searchAssets: (slug, { fieldId = null, query = '', assetSetId = null, limit = 20 } = {}) => {
const params = new URLSearchParams();
if (fieldId) params.set('field_id', String(fieldId));
if (query) params.set('q', query);
if (assetSetId) params.set('asset_set_id', String(assetSetId));
if (limit) params.set('limit', String(limit));
return fetchAPI(`/portal/${slug}/assets/search?${params.toString()}`);
},

// Portal-side approvals — list pending approvals for the active customer (or
// internal user with a customer link), open a single request, and decide.
getMyApprovals: (slug, status = 'pending') =>
Expand Down
10 changes: 10 additions & 0 deletions frontend/src/lib/dialogs/AssetReportFormModal.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,14 @@
return field.display_name || field.field_label || field.field_name || field.field_identifier;
}

// Asset custom fields resolve their options through the portal's asset
// search, which evaluates the field's ql_query against the set the
// administrator exposed to portals.
function loadAssetOptions(assetSetId, _cqlQuery, search, fieldId) {
if (!portalSlug) return Promise.resolve({ assets: [], total: 0 });
return portal.searchAssets(portalSlug, { fieldId, assetSetId, query: search });
}

function parseSelectOptions(optionsJson) {
try {
const parsed = typeof optionsJson === 'string' ? JSON.parse(optionsJson) : optionsJson;
Expand Down Expand Up @@ -249,6 +257,7 @@
onChange={(val) => (values[field.field_identifier] = val)}
milestones={[]}
{isDarkMode}
{loadAssetOptions}
/>
{:else}
<CustomFieldRenderer
Expand All @@ -258,6 +267,7 @@
onChange={(val) => (values[field.field_identifier] = val)}
milestones={[]}
{isDarkMode}
{loadAssetOptions}
/>
{/if}
</div>
Expand Down
9 changes: 9 additions & 0 deletions frontend/src/lib/dialogs/RequestFormModal.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,14 @@
applyPrefill(prefill);
}

// Asset custom fields resolve their options through the portal's asset
// search, which evaluates the field's ql_query against the set the
// administrator exposed to portals.
function loadAssetOptions(assetSetId, _cqlQuery, search, fieldId) {
if (!portalSlug) return Promise.resolve({ assets: [], total: 0 });
return portal.searchAssets(portalSlug, { fieldId, assetSetId, query: search });
}

function validateCurrentStep() {
const message = validateFormStep({
fields,
Expand Down Expand Up @@ -501,6 +509,7 @@
bind:customFieldValues
{isDarkMode}
idPrefix="request"
{loadAssetOptions}
/>

<!-- Staged attachments (last step only). Uploads happen after the
Expand Down
4 changes: 4 additions & 0 deletions frontend/src/lib/features/forms/FormFields.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
customFieldValues = $bindable({}),
isDarkMode = false,
idPrefix = 'form',
// Resolves asset picker options for asset custom fields. The portal passes
// a loader backed by its own asset search; public forms leave it null.
loadAssetOptions = null,
} = $props();

let currentStepFields = $derived(
Expand Down Expand Up @@ -82,6 +85,7 @@
required={field.is_required}
milestones={[]}
{isDarkMode}
{loadAssetOptions}
/>
{#if field.description}
<p class="mt-1 text-xs" style="color: var(--ds-text-subtle);">{field.description}</p>
Expand Down
1 change: 1 addition & 0 deletions frontend/src/lib/features/items/CustomFieldRenderer.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -1091,6 +1091,7 @@
assetConfig.asset_set_id,
assetConfig.cql_query || assetConfig.ql_query || '',
search,
field.id,
)
: null}
onSelect={(asset) => {
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/lib/locales/en/misc.js
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,7 @@ export default {
selectAnAssetSetDesc: 'Choose an asset set from the dropdown above to view and manage assets.',
default: 'Default',
availableOnPortals: 'Available on portals',
availableOnPortalsDesc: 'Let portal visitors read assets in this set through a portal report that references it.',
availableOnPortalsDesc: 'Let portal visitors read assets in this set through portal reports and asset fields.',
assetTag: 'Asset Tag',
preview: 'Preview',
serialNumber: 'Serial Number',
Expand Down
9 changes: 7 additions & 2 deletions internal/handlers/asset_reports.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,11 +212,16 @@ func (h *AssetReportHandler) requirePortalOwner(w http.ResponseWriter, r *http.R
return true
}

// availableFieldsForAssetReport offers the create-screen fields an asset-report
// form can bind. Asset reports only run on portal channels, where asset custom
// fields are resolvable through the portal's own asset endpoints. Multi-asset
// fields are excluded: their list values are not expressible in report CQL
// substitution.
func (h *AssetReportHandler) availableFieldsForAssetReport(ar *models.AssetReport) ([]AvailableField, error) {
if ar.ItemTypeID == nil {
return availableCreateFields(h.screenRepo, ar.WorkspaceID, 0)
return availableCreateFields(h.screenRepo, ar.WorkspaceID, 0, true, true)
}
return availableCreateFields(h.screenRepo, ar.WorkspaceID, *ar.ItemTypeID)
return availableCreateFields(h.screenRepo, ar.WorkspaceID, *ar.ItemTypeID, true, true)
}

// validateAssetReportFormBinding applies the same workspace and item-type
Expand Down
18 changes: 17 additions & 1 deletion internal/handlers/portal.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,11 @@ func (h *PortalHandler) getPortalCustomerID(ctx context.Context, r *http.Request
}
}

// Fall back to internal user session (backward compatible)
// Fall back to internal user session (backward compatible). A handler
// without a session manager has no internal identity to resolve.
if h.sessionManager == nil {
return nil, fmt.Errorf("authentication required")
}
sessionToken, err := h.sessionManager.GetSessionFromRequest(r)
if err != nil {
return nil, fmt.Errorf("authentication required")
Expand Down Expand Up @@ -794,6 +798,18 @@ func (h *PortalHandler) SubmitToPortal(w http.ResponseWriter, r *http.Request) {
return
}

// Asset custom fields reference assets in an administrator-exposed set,
// which the generic custom-field validator cannot authorize. Reject ids
// outside the field's configured set, a set without a portal grant, or an
// asset the field's own query excludes before creating the item. The filter
// identity matches the picker (including a linked customer on an internal
// session); item attribution still uses getAuthFromContext.
filterCustomerID, filterOrgID := h.portalAssetFilterIdentity(ctx, r, channel.ID)
if err := h.validatePortalAssetCustomFields(ctx, filterCustomerID, filterOrgID, validationResult.CustomFieldValues); err != nil {
respondValidationError(w, r, err.Error())
return
}

// Title fallback: when the request type hides the title field from the
// form, render its title_template. Items have a NOT NULL title, so we
// reject when the template is missing or renders to empty.
Expand Down
Loading
Loading