Skip to content

Commit

Permalink
Merge branch 'release_24.0' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
mvdbeek committed Mar 20, 2024
2 parents 113430f + 81753fb commit cd16d19
Show file tree
Hide file tree
Showing 35 changed files with 632 additions and 193 deletions.
51 changes: 51 additions & 0 deletions client/src/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,19 @@ import { components } from "@/api/schema";
*/
export type HistorySummary = components["schemas"]["HistorySummary"];

export interface HistorySummaryExtended extends HistorySummary {
size: number;
contents_active: components["schemas"]["HistoryActiveContentCounts"];
user_id: string;
}

/**
* Contains additional details about a History.
*/
export type HistoryDetailed = components["schemas"]["HistoryDetailed"];

export type AnyHistory = HistorySummary | HistorySummaryExtended | HistoryDetailed;

/**
* Contains minimal information about a HistoryContentItem.
*/
Expand Down Expand Up @@ -125,3 +133,46 @@ export function hasDetails(entry: DatasetEntry): entry is DatasetDetails {
* Contains dataset metadata information.
*/
export type MetadataFiles = components["schemas"]["MetadataFile"][];

export function isHistorySummary(history: AnyHistory): history is HistorySummary {
return !("user_id" in history);
}

export function isHistorySummaryExtended(history: AnyHistory): history is HistorySummaryExtended {
return "contents_active" in history && "user_id" in history;
}

type QuotaUsageResponse = components["schemas"]["UserQuotaUsage"];

export interface User extends QuotaUsageResponse {
id: string;
email: string;
tags_used: string[];
isAnonymous: false;
is_admin?: boolean;
username?: string;
}

export interface AnonymousUser {
isAnonymous: true;
username?: string;
is_admin?: false;
}

export type GenericUser = User | AnonymousUser;

export function isRegisteredUser(user: User | AnonymousUser | null): user is User {
return !user?.isAnonymous;
}

export function userOwnsHistory(user: User | AnonymousUser | null, history: AnyHistory) {
return (
// Assuming histories without user_id are owned by the current user
(isRegisteredUser(user) && !hasOwner(history)) ||
(isRegisteredUser(user) && hasOwner(history) && user.id === history.user_id)
);
}

function hasOwner(history: AnyHistory): history is HistorySummaryExtended {
return "user_id" in history;
}
Loading

0 comments on commit cd16d19

Please sign in to comment.