Skip to content

Show asset creator + admin owner filter#12

Open
haphantran wants to merge 2 commits into
mainfrom
feature/asset-created-by
Open

Show asset creator + admin owner filter#12
haphantran wants to merge 2 commits into
mainfrom
feature/asset-created-by

Conversation

@haphantran

Copy link
Copy Markdown
Collaborator

What & why

Follow-up to the admin-view-all-assets work (#11). Answers "who created this asset?" and lets admins cut on-screen clutter by focusing on specific users.

1. "Created by {email}" on asset listings

A small reusable CreatedBy label shows the creator on each asset. The owner already arrives on API listings (ownerEmail for resources the user doesn't own; the current user otherwise), so this threads isOwner/ownerEmail through the frontend asset types and renders them. Applied to:

  • Models, Metamodels, Views/Diagrams (the primary browse lists)
  • Viewpoints (owner derived from their parent metamodel)

2. Global admin "Filter by owner"

An admin-only multi-select in the sidebar (OwnerFilterContext + OwnerFilterControl) restricts every browse list to the selected owners. Empty = show all, and it renders nothing for non-admins (no effect for them). Applied to the Models, Metamodels, and Views lists via useOwnerFilterMatcher.

Coverage notes

  • Code generation / transformations / testing: these are workflow tools scoped to an already-selected model/metamodel (dropdown-driven), not standalone asset browsers, so the owner filter doesn't apply there. The underlying types still carry the owner fields if we want to surface "created by" later.
  • Depends on Let platform admins view and edit all assets #11 for the admin case: an admin only sees all users' assets once Let platform admins view and edit all assets #11 is merged/deployed. Until then this works for owned + shared assets; it lights up fully for cross-user browsing afterward. The feature itself is independent and safe to merge first.

Tests

  • Frontend tsc --noEmit: clean.
  • Full frontend suite: 106 passed (+ new CreatedBy.test.tsx: 4 tests covering owner resolution and rendering).

- Add a reusable CreatedBy label and surface 'Created by {email}' on the
  Models, Metamodels, Views, and Viewpoints listings. Owner data already
  rides on the API listings (ownerEmail for non-owned, current user
  otherwise); thread isOwner/ownerEmail through the frontend asset types
  and preserve them in the transformation-rule mapping.
- Add a global, admin-only 'Filter by owner' control in the sidebar
  (OwnerFilterContext + OwnerFilterControl) so admins can narrow the
  browse lists to specific users and reduce on-screen clutter. Renders
  nothing for non-admins, so it has no effect for them.
Copilot AI review requested due to automatic review settings June 15, 2026 21:08

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds creator attribution to asset listings and introduces an admin-only global “Filter by owner” to reduce clutter when browsing assets (follow-up to the admin view-all-assets work).

Changes:

  • Thread isOwner / ownerEmail metadata through frontend asset types and API sync, and render a reusable CreatedBy label in key lists.
  • Add OwnerFilterContext + OwnerFilterControl and apply the matcher to Models, Metamodels, and Diagrams browse lists.
  • Add unit tests for CreatedBy / resolveOwnerEmail.

Reviewed changes

Copilot reviewed 14 out of 14 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
frontend/src/services/transformation/transformation-api-sync.service.ts Threads isOwner/ownerEmail through transformation rule hydration from API.
frontend/src/services/testing/testing-types.ts Extends TestCase type with ownership metadata fields.
frontend/src/services/common/ownership.ts Introduces shared ownership metadata + resolveOwnerEmail helper.
frontend/src/models/types.ts Adds ownership metadata fields across core asset interfaces.
frontend/src/contexts/OwnerFilterContext.tsx Adds global owner-filter context and matcher hook.
frontend/src/components/viewpoints/ViewpointManager.tsx Renders CreatedBy for viewpoints (derived from parent metamodel).
frontend/src/components/model/ModelManager.tsx Applies owner filtering to model list + renders CreatedBy per model.
frontend/src/components/metamodel/MetamodelManager.tsx Applies owner filtering to metamodel list + renders CreatedBy per metamodel.
frontend/src/components/layout/Sidebar.tsx Adds admin-only sidebar control for selecting owner filter.
frontend/src/components/common/OwnerFilterControl.tsx New admin UI control that fetches users and sets selected owners.
frontend/src/components/common/index.ts Exports CreatedBy and ownership helpers via the common barrel.
frontend/src/components/common/CreatedBy.tsx New “Created by {email}” label component.
frontend/src/App.tsx Wraps app with OwnerFilterProvider, applies filtering to diagrams list, renders CreatedBy in diagram cards.
frontend/src/tests/components/CreatedBy.test.tsx Adds tests for CreatedBy and resolveOwnerEmail.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread frontend/src/services/common/ownership.ts
Comment on lines +32 to +43
export const useOwnerFilterMatcher = (): ((resource: ResourceOwnership) => boolean) => {
const { selectedOwnerEmails } = useOwnerFilter();
const { user } = useAuth();
return useCallback(
(resource: ResourceOwnership) => {
if (selectedOwnerEmails.length === 0) return true;
const email = resolveOwnerEmail(resource, user?.email);
return email !== undefined && selectedOwnerEmails.includes(email);
},
[selectedOwnerEmails, user?.email]
);
};
Comment on lines +17 to +24
useEffect(() => {
if (!isAdmin) return;
let cancelled = false;
adminService
.getUsers({ pageSize: 100 })
.then(res => {
if (!cancelled) setEmails(res.users.map(u => u.email));
})
- resolveOwnerEmail: treat explicit isOwner=false without ownerEmail as
  unknown instead of attributing the resource to the current user.
- useOwnerFilterMatcher: gate on the ADMIN role so a stale owner selection
  can never filter a non-admin who signs in on the same session.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants